docs(dotnet): add docs for SetDefaultExpectTimeout (#29259)
This commit is contained in:
parent
aff6cf3c83
commit
0f8d619012
|
|
@ -91,7 +91,7 @@ Edit the `UnitTest1.cs` file with the code below to create an example end-to-end
|
||||||
}>
|
}>
|
||||||
<TabItem value="nunit">
|
<TabItem value="nunit">
|
||||||
|
|
||||||
```csharp
|
```csharp title="UnitTest1.cs"
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Playwright;
|
using Microsoft.Playwright;
|
||||||
|
|
@ -130,7 +130,7 @@ public class Tests : PageTest
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem value="mstest">
|
<TabItem value="mstest">
|
||||||
|
|
||||||
```csharp
|
```csharp title="UnitTest1.cs"
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Playwright;
|
using Microsoft.Playwright;
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,9 @@ You can do the following to leverage Playwright's web-first assertions when you
|
||||||
using Microsoft.Playwright;
|
using Microsoft.Playwright;
|
||||||
using static Microsoft.Playwright.Assertions;
|
using static Microsoft.Playwright.Assertions;
|
||||||
|
|
||||||
|
// Change the default 5 seconds timeout if you'd like.
|
||||||
|
SetDefaultExpectTimeout(10_000);
|
||||||
|
|
||||||
using var playwright = await Playwright.CreateAsync();
|
using var playwright = await Playwright.CreateAsync();
|
||||||
await using var browser = await playwright.Chromium.LaunchAsync();
|
await using var browser = await playwright.Chromium.LaunchAsync();
|
||||||
var page = await browser.NewPageAsync();
|
var page = await browser.NewPageAsync();
|
||||||
|
|
|
||||||
|
|
@ -56,11 +56,12 @@ tests/test_foobar.py:22: AssertionError
|
||||||
```
|
```
|
||||||
|
|
||||||
## Setting a custom timeout
|
## 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.
|
You can specify a custom timeout for assertions either globally or per assertion. The default timeout is 5 seconds.
|
||||||
|
|
||||||
### Global timeout
|
### Global timeout
|
||||||
|
* langs: python
|
||||||
|
|
||||||
```python title="conftest.py"
|
```python title="conftest.py"
|
||||||
from playwright.sync_api import expect
|
from playwright.sync_api import expect
|
||||||
|
|
@ -68,6 +69,64 @@ from playwright.sync_api import expect
|
||||||
expect.set_options(timeout=10_000)
|
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
|
### Per assertion timeout
|
||||||
|
|
||||||
```python title="test_foobar.py"
|
```python title="test_foobar.py"
|
||||||
|
|
@ -76,3 +135,7 @@ from playwright.sync_api import expect
|
||||||
def test_foobar(page: Page) -> None:
|
def test_foobar(page: Page) -> None:
|
||||||
expect(page.get_by_text("Name")).to_be_visible(timeout=10_000)
|
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 });
|
||||||
|
```
|
||||||
|
|
|
||||||
|
|
@ -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">
|
<TabItem value="nunit">
|
||||||
|
|
||||||
```csharp
|
```csharp title="UnitTest1.cs"
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Playwright;
|
using Microsoft.Playwright;
|
||||||
|
|
@ -60,7 +60,7 @@ public class Tests : PageTest
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem value="mstest">
|
<TabItem value="mstest">
|
||||||
|
|
||||||
```csharp
|
```csharp title="UnitTest1.cs"
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Playwright;
|
using Microsoft.Playwright;
|
||||||
|
|
@ -132,7 +132,7 @@ The Playwright NUnit and MSTest test framework base classes will isolate each te
|
||||||
}>
|
}>
|
||||||
<TabItem value="nunit">
|
<TabItem value="nunit">
|
||||||
|
|
||||||
```csharp
|
```csharp title="UnitTest1.cs"
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Playwright.NUnit;
|
using Microsoft.Playwright.NUnit;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
@ -154,7 +154,7 @@ public class Tests : PageTest
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem value="mstest">
|
<TabItem value="mstest">
|
||||||
|
|
||||||
```csharp
|
```csharp title="UnitTest1.cs"
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Playwright.MSTest;
|
using Microsoft.Playwright.MSTest;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
|
@ -189,7 +189,7 @@ You can use `SetUp`/`TearDown` in NUnit or `TestInitialize`/`TestCleanup` in MST
|
||||||
}>
|
}>
|
||||||
<TabItem value="nunit">
|
<TabItem value="nunit">
|
||||||
|
|
||||||
```csharp
|
```csharp title="UnitTest1.cs"
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Playwright.NUnit;
|
using Microsoft.Playwright.NUnit;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
@ -218,7 +218,7 @@ public class Tests : PageTest
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem value="mstest">
|
<TabItem value="mstest">
|
||||||
|
|
||||||
```csharp
|
```csharp title="UnitTest1.cs"
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Playwright.MSTest;
|
using Microsoft.Playwright.MSTest;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue