docs: apply suggestions from review
This commit is contained in:
parent
493b19446b
commit
ab53e6e8c6
|
|
@ -133,110 +133,9 @@ pwsh bin/Debug/net8.0/playwright.ps1 show-trace bin/Debug/net8.0/playwright-trac
|
|||
|
||||
Setup your tests to record a trace only when the test fails:
|
||||
|
||||
<Tabs
|
||||
groupId="test-runners"
|
||||
defaultValue="nunit"
|
||||
values={[
|
||||
{label: 'NUnit', value: 'nunit'},
|
||||
{label: 'MSTest', value: 'mstest'}
|
||||
]
|
||||
}>
|
||||
<TabItem value="nunit">
|
||||
|
||||
```csharp
|
||||
namespace PlaywrightTests;
|
||||
|
||||
[Parallelizable(ParallelScope.Self)]
|
||||
[TestFixture]
|
||||
public class ExampleTest : PageTest
|
||||
{
|
||||
[SetUp]
|
||||
public async Task Setup()
|
||||
{
|
||||
await Context.Tracing.StartAsync(new()
|
||||
{
|
||||
Title = $"{TestContext.CurrentContext.Test.ClassName}.{TestContext.CurrentContext.Test.Name}",
|
||||
Screenshots = true,
|
||||
Snapshots = true,
|
||||
Sources = true
|
||||
});
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public async Task TearDown()
|
||||
{
|
||||
var failed = TestContext.CurrentContext.Result.Outcome == NUnit.Framework.Interfaces.ResultState.Error
|
||||
|| TestContext.CurrentContext.Result.Outcome == NUnit.Framework.Interfaces.ResultState.Failure;
|
||||
|
||||
await Context.Tracing.StopAsync(new()
|
||||
{
|
||||
Path = Path.Combine(
|
||||
TestContext.CurrentContext.WorkDirectory,
|
||||
"playwright-traces",
|
||||
$"{TestContext.CurrentContext.Test.ClassName}.{TestContext.CurrentContext.Test.Name}.zip"
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetStartedLink()
|
||||
{
|
||||
// ..
|
||||
}
|
||||
}
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value="mstest">
|
||||
|
||||
```csharp
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.Playwright;
|
||||
using Microsoft.Playwright.MSTest;
|
||||
|
||||
namespace PlaywrightTests;
|
||||
|
||||
[TestClass]
|
||||
public class ExampleTest : PageTest
|
||||
{
|
||||
[TestInitialize]
|
||||
public async Task TestInitialize()
|
||||
{
|
||||
await Context.Tracing.StartAsync(new()
|
||||
{
|
||||
Title = $"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}",
|
||||
Screenshots = true,
|
||||
Snapshots = true,
|
||||
Sources = true
|
||||
});
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public async Task TestCleanup()
|
||||
{
|
||||
var failed = new[] { UnitTestOutcome.Failed, UnitTestOutcome.Error, UnitTestOutcome.Timeout, UnitTestOutcome.Aborted }.Contains(TestContext.CurrentTestOutcome);
|
||||
|
||||
await Context.Tracing.StopAsync(new()
|
||||
{
|
||||
Path = Path.Combine(
|
||||
Environment.CurrentDirectory,
|
||||
"playwright-traces",
|
||||
$"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}.zip"
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetStartedLink()
|
||||
{
|
||||
// ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
To learn more check out our detailed guide on [Trace Viewer](/trace-viewer.md).
|
||||
Check out our detailed guide on [Trace Viewer](/trace-viewer.md) to learn more about the trace viewer and how to setup your tests to record a trace only when the test fails.
|
||||
|
||||
## What's next
|
||||
|
||||
|
|
|
|||
|
|
@ -388,7 +388,7 @@ public class ExampleTest : PageTest
|
|||
|
||||
await Context.Tracing.StopAsync(new()
|
||||
{
|
||||
Path = Path.Combine(
|
||||
Path = failed ? Path.Combine(
|
||||
TestContext.CurrentContext.WorkDirectory,
|
||||
"playwright-traces",
|
||||
$"{TestContext.CurrentContext.Test.ClassName}.{TestContext.CurrentContext.Test.Name}.zip"
|
||||
|
|
@ -435,7 +435,7 @@ public class ExampleTest : PageTest
|
|||
|
||||
await Context.Tracing.StopAsync(new()
|
||||
{
|
||||
Path = Path.Combine(
|
||||
Path = failed ? Path.Combine(
|
||||
Environment.CurrentDirectory,
|
||||
"playwright-traces",
|
||||
$"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}.zip"
|
||||
|
|
|
|||
Loading…
Reference in a new issue