Skip to main content

Assertions

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.

Auto-Retry Assertions

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.

Why Auto-Retry Matters

Avoid using getAttribute() or isVisible() directly in assertions. These methods return the current state without retrying, leading to flaky tests.

Built-in Assertion Methods

Drama Finder element classes provide assertion methods that wrap Playwright assertions with semantic names.

Visibility Assertions

State Assertions

Value Assertions

Component-Specific Assertions

Assertion Symmetry Pattern

For each state getter, Drama Finder provides matching assertion methods:
This pattern ensures consistency and discoverability across all element types.
Use element assertion methods instead of direct Playwright assertions. They provide better readability and handle locator delegation correctly.

Null Handling in Assertions

Assertion methods handle null values to test the absence of attributes:

Usage Example

Attribute vs Property Assertions

HTML attributes and DOM properties are different. Use the correct assertion method for your use case.

HTML Attributes

Use hasAttribute() for HTML attributes:

DOM Properties

Use hasJSProperty() for JavaScript properties:

When to Use Which

Testing Validation States

Component-Level Assertions

Theme and Style

ARIA and Accessibility

Prefix and Suffix Content

Grid Assertions

Grid elements have specialized assertions for tabular data:

Combining Multiple Assertions

Timeout Configuration

Adjust timeout for specific assertions when needed:

Best Practices

Use Playwright assertions (assertThat()) or element assertion methods instead of raw boolean checks:
After actions that trigger async updates, use assertions that wait:
Prefer element-specific assertion methods over generic Playwright assertions:
When writing custom assertion helpers, always handle null to test attribute absence:

Common Pitfalls

Pitfall: Asserting state immediately after an action without waiting.Solution: Use Playwright assertions which auto-retry. Avoid raw getAttribute() checks.