docs(dotnet): add docs for SetDefaultExpectTimeout (#29259)

This commit is contained in:
Max Schmitt 2024-01-31 17:49:01 +01:00 committed by GitHub
parent aff6cf3c83
commit 0f8d619012
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 75 additions and 9 deletions

View File

@ -91,7 +91,7 @@ Edit the `UnitTest1.cs` file with the code below to create an example end-to-end
}>
<TabItem value="nunit">
```csharp
```csharp title="UnitTest1.cs"
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.Playwright;
@ -130,7 +130,7 @@ public class Tests : PageTest
</TabItem>
<TabItem value="mstest">
```csharp
```csharp title="UnitTest1.cs"
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.Playwright;

View File

@ -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();

View File

@ -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
<Tabs
groupId="test-runners"
defaultValue="nunit"
values={[
{label: 'NUnit', value: 'nunit'},
{label: 'MSTest', value: 'mstest'}
]
}>
<TabItem value="nunit">
```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);
}
// ...
}
```
</TabItem>
<TabItem value="mstest">
```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);
}
// ...
}
```
</TabItem>
</Tabs>
### 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 });
```

View File

@ -19,7 +19,7 @@ Take a look at the example test below to see how to write a test using using [lo
}>
<TabItem value="nunit">
```csharp
```csharp title="UnitTest1.cs"
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.Playwright;
@ -60,7 +60,7 @@ public class Tests : PageTest
</TabItem>
<TabItem value="mstest">
```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
}>
<TabItem value="nunit">
```csharp
```csharp title="UnitTest1.cs"
using System.Threading.Tasks;
using Microsoft.Playwright.NUnit;
using NUnit.Framework;
@ -154,7 +154,7 @@ public class Tests : PageTest
</TabItem>
<TabItem value="mstest">
```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
}>
<TabItem value="nunit">
```csharp
```csharp title="UnitTest1.cs"
using System.Threading.Tasks;
using Microsoft.Playwright.NUnit;
using NUnit.Framework;
@ -218,7 +218,7 @@ public class Tests : PageTest
</TabItem>
<TabItem value="mstest">
```csharp
```csharp title="UnitTest1.cs"
using System.Threading.Tasks;
using Microsoft.Playwright.MSTest;
using Microsoft.VisualStudio.TestTools.UnitTesting;