Drama Finder provides assertion methods that leverage Playwright’s auto-retry mechanism to handle asynchronous state changes in Vaadin applications. These assertions automatically wait for conditions to be met, eliminating flaky tests caused by timing issues.
Playwright assertions automatically retry until the condition is met or a timeout occurs (default 5 seconds). This is essential for testing Vaadin’s asynchronous UI updates.
// Bad: No retry, may fail due to timingboolean isOpen = dialog.getLocator().getAttribute("opened") != null;assertTrue(isOpen);// Good: Auto-retries until timeoutassertThat(dialog.getLocator()).hasAttribute("opened", "");// Even better: Use element's assertion methoddialog.assertOpen();
Avoid using getAttribute() or isVisible() directly in assertions. These methods return the current state without retrying, leading to flaky tests.
// Assert element is visibleButtonElement button = ButtonElement.getByText(page, "Save");button.assertVisible();// Assert element is hiddenDialogElement dialog = DialogElement.get(page);dialog.assertHidden();
// HTML attribute (set via setAttribute or HTML)String maxLength = getInputLocator().getAttribute("maxlength");assertThat(getInputLocator()).hasAttribute("maxlength", "100");// DOM property (set via JavaScript)getLocator().evaluate("(el, v) => el.maxLength = v", 100);assertThat(getLocator()).hasJSProperty("maxLength", 100);
ButtonElement iconButton = ButtonElement.getByText(page, "Download");// Assert prefix/suffix exist and have expected texticonButton.assertPrefixHasText("⬇");iconButton.assertSuffixHasText("PDF");// Using direct Playwright assertionsassertThat(iconButton.getPrefixLocator()).isVisible();assertThat(iconButton.getSuffixLocator()).hasText("PDF");
Use Playwright assertions (assertThat()) or element assertion methods instead of raw boolean checks:
// Bad: No retryassertTrue(button.getLocator().getAttribute("disabled") != null);// Good: Auto-retriesbutton.assertDisabled();
Test async state changes
After actions that trigger async updates, use assertions that wait:
button.click();dialog.assertOpen(); // Waits for dialog to opencomboBox.selectItem("Option 1");comboBox.assertValue("Option 1"); // Waits for value update
Use semantic assertion methods
Prefer element-specific assertion methods over generic Playwright assertions:
// Good: Semantic and clearcheckbox.assertChecked();// Less clear: Generic assertionassertThat(checkbox.getInputLocator()).isChecked();
Handle null in custom assertions
When writing custom assertion helpers, always handle null to test attribute absence:
public void assertCustomAttribute(String value) { if (value != null) { assertThat(getLocator()).hasAttribute("custom", value); } else { assertThat(getLocator()).not().hasAttribute("custom", Pattern.compile(".*")); }}
Pitfall: Asserting state immediately after an action without waiting.Solution: Use Playwright assertions which auto-retry. Avoid raw getAttribute() checks.
// Bad: No retry, may flakebutton.click();assertTrue(dialog.getLocator().getAttribute("opened") != null);// Good: Auto-retries until timeoutbutton.click();assertThat(dialog.getLocator()).hasAttribute("opened", "");