Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
docs(assertions): explain retry behavior across languages (#42401)
Devin Rousso036533f7f3c1
diff --git a/docs/src/test-assertions-csharp-java-python.md b/docs/src/test-assertions-csharp-java-python.mdindex d81762849e..0a6f543a69 100644--- a/docs/src/test-assertions-csharp-java-python.md+++ b/docs/src/test-assertions-csharp-java-python.md@@ -3,7 +3,29 @@ id: test-assertionstitle: "Assertions"----## List of assertions+## Introduction++Playwright includes web-specific assertions that automatically retry until the expected condition is met. Consider the following example:++```python+expect(page.get_by_test_id("status")).to_have_text("Submitted")+```++```java+assertThat(page.getByTestId("status")).hasText("Submitted");+```++```csharp+await Expect(Page.GetByTestId("status")).ToHaveTextAsync("Submitted");+```++Playwright will re-test the element with the test ID of `status` until it has the `"Submitted"` text. It will re-fetch the element and check it repeatedly until the condition is met or the timeout is reached.++By default, the timeout for assertions is 5 seconds.++## Auto-retrying assertions++The following assertions will retry until the assertion passes or the assertion timeout is reached.| Assertion | Description || :- | :- |@@ -96,7 +118,7 @@ Call log:```## Setting a custom timeout-* langs: python, csharp+* langs: python, java, csharpYou can specify a custom timeout for assertions either globally or per assertion. The default timeout is 5 seconds.@@ -109,6 +131,15 @@ from playwright.sync_api import expectexpect.set_options(timeout=10_000)```+### Global timeout+* langs: java++```java+import com.microsoft.playwright.assertions.PlaywrightAssertions;++PlaywrightAssertions.setDefaultAssertionTimeout(10_000);+```+### Global timeout* langs: csharp@@ -214,6 +245,15 @@ def test_foobar(page: Page) -> None:expect(page.get_by_text("Name")).to_be_visible(timeout=10_000)```+```java+import com.microsoft.playwright.assertions.LocatorAssertions;++import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;++assertThat(page.getByText("Name")).isVisible(+ new LocatorAssertions.IsVisibleOptions().setTimeout(10_000));+```+```csharp title="UnitTest1.cs"await Expect(Page.GetByText("Name")).ToBeVisibleAsync(new() { Timeout = 10_000 });```