diff --git a/docs/src/intro-csharp.md b/docs/src/intro-csharp.md index 9281f886c9..43126bb63e 100644 --- a/docs/src/intro-csharp.md +++ b/docs/src/intro-csharp.md @@ -91,7 +91,7 @@ Edit the `UnitTest1.cs` file with the code below to create an example end-to-end }> -```csharp +```csharp title="UnitTest1.cs" using System.Text.RegularExpressions; using System.Threading.Tasks; using Microsoft.Playwright; @@ -130,7 +130,7 @@ public class Tests : PageTest -```csharp +```csharp title="UnitTest1.cs" using System.Text.RegularExpressions; using System.Threading.Tasks; using Microsoft.Playwright; diff --git a/docs/src/library-csharp.md b/docs/src/library-csharp.md index ff68f86fd9..5dab997f7e 100644 --- a/docs/src/library-csharp.md +++ b/docs/src/library-csharp.md @@ -66,6 +66,9 @@ You can do the following to leverage Playwright's web-first assertions when you using Microsoft.Playwright; using static Microsoft.Playwright.Assertions; +// Change the default 5 seconds timeout if you'd like. +SetDefaultExpectTimeout(10_000); + using var playwright = await Playwright.CreateAsync(); await using var browser = await playwright.Chromium.LaunchAsync(); var page = await browser.NewPageAsync(); diff --git a/docs/src/test-assertions-csharp-java-python.md b/docs/src/test-assertions-csharp-java-python.md index 0fa60874b0..1926aaad26 100644 --- a/docs/src/test-assertions-csharp-java-python.md +++ b/docs/src/test-assertions-csharp-java-python.md @@ -56,11 +56,12 @@ tests/test_foobar.py:22: AssertionError ``` ## Setting a custom timeout -* langs: python +* langs: python, csharp You can specify a custom timeout for assertions either globally or per assertion. The default timeout is 5 seconds. ### Global timeout +* langs: python ```python title="conftest.py" from playwright.sync_api import expect @@ -68,6 +69,64 @@ from playwright.sync_api import expect expect.set_options(timeout=10_000) ``` +### Global timeout +* langs: csharp + + + + +```csharp title="UnitTest1.cs" +using Microsoft.Playwright; +using Microsoft.Playwright.NUnit; +using NUnit.Framework; + +namespace PlaywrightTests; + +[Parallelizable(ParallelScope.Self)] +[TestFixture] +public class Tests : PageTest +{ + [OneTimeSetUp] + public void GlobalSetup() + { + SetDefaultExpectTimeout(10_000); + } + // ... +} +``` + + + + +```csharp title="UnitTest1.cs" +using Microsoft.Playwright; +using Microsoft.Playwright.MSTest; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace PlaywrightTests; + +[TestClass] +public class UnitTest1 : PageTest +{ + [ClassInitialize] + public static void GlobalSetup(TestContext context) + { + SetDefaultExpectTimeout(10_000); + } + // ... +} +``` + + + + ### Per assertion timeout ```python title="test_foobar.py" @@ -76,3 +135,7 @@ from playwright.sync_api import expect def test_foobar(page: Page) -> None: expect(page.get_by_text("Name")).to_be_visible(timeout=10_000) ``` + +```csharp title="UnitTest1.cs" +await Expect(Page.GetByText("Name")).ToBeVisibleAsync(new() { Timeout = 10_000 }); +``` diff --git a/docs/src/writing-tests-csharp.md b/docs/src/writing-tests-csharp.md index 1aea228c68..938b24429f 100644 --- a/docs/src/writing-tests-csharp.md +++ b/docs/src/writing-tests-csharp.md @@ -19,7 +19,7 @@ Take a look at the example test below to see how to write a test using using [lo }> -```csharp +```csharp title="UnitTest1.cs" using System.Text.RegularExpressions; using System.Threading.Tasks; using Microsoft.Playwright; @@ -60,7 +60,7 @@ public class Tests : PageTest -```csharp +```csharp title="UnitTest1.cs" using System.Text.RegularExpressions; using System.Threading.Tasks; using Microsoft.Playwright; @@ -132,7 +132,7 @@ The Playwright NUnit and MSTest test framework base classes will isolate each te }> -```csharp +```csharp title="UnitTest1.cs" using System.Threading.Tasks; using Microsoft.Playwright.NUnit; using NUnit.Framework; @@ -154,7 +154,7 @@ public class Tests : PageTest -```csharp +```csharp title="UnitTest1.cs" using System.Threading.Tasks; using Microsoft.Playwright.MSTest; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -189,7 +189,7 @@ You can use `SetUp`/`TearDown` in NUnit or `TestInitialize`/`TestCleanup` in MST }> -```csharp +```csharp title="UnitTest1.cs" using System.Threading.Tasks; using Microsoft.Playwright.NUnit; using NUnit.Framework; @@ -218,7 +218,7 @@ public class Tests : PageTest -```csharp +```csharp title="UnitTest1.cs" using System.Threading.Tasks; using Microsoft.Playwright.MSTest; using Microsoft.VisualStudio.TestTools.UnitTesting;