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(docs): add docs about integrating Trace into NUnit/MSTest (#28639)
Max Schmittff3b70b6259c
diff --git a/docs/src/trace-viewer-intro-csharp-java-python.md b/docs/src/trace-viewer-intro-csharp-java-python.mdindex 5f10abe68e..68fcef6acc 100644--- a/docs/src/trace-viewer-intro-csharp-java-python.md+++ b/docs/src/trace-viewer-intro-csharp-java-python.md@@ -62,7 +62,7 @@ context.tracing.stop(path = "trace.zip")</details>## Recording a trace-* langs: csharp, java+* langs: javaTraces can be recorded using the [`property: BrowserContext.tracing`] API as follows:@@ -84,30 +84,118 @@ context.tracing().stop(new Tracing.StopOptions().setPath(Paths.get("trace.zip")));```++This will record the trace and place it into the file named `trace.zip`.++## Recording a trace+* langs: csharp++Traces can be recorded using the [`property: BrowserContext.tracing`] API as follows:++<Tabs+ groupId="test-runners"+ defaultValue="nunit"+ values={[+ {label: 'NUnit', value: 'nunit'},+ {label: 'MSTest', value: 'mstest'}+ ]+}>+<TabItem value="nunit">+```csharp-using var playwright = await Playwright.CreateAsync();-var browser = await playwright.Chromium.LaunchAsync();-await using var context = await browser.NewContextAsync();+namespace PlaywrightTests;-// Start tracing before creating / navigating a page.-await context.Tracing.StartAsync(new()+[Parallelizable(ParallelScope.Self)]+[TestFixture]+public class Tests : PageTest{- Screenshots = true,- Snapshots = true,- Sources = true-});+ [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()+ {+ // This will produce e.g.:+ // bin/Debug/net8.0/playwright-traces/PlaywrightTests.Tests.Test1.zip+ 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 TestYourOnlineShop()+ {+ // ..+ }+}+```-var page = await context.NewPageAsync();-await page.GotoAsync("https://playwright.dev");+</TabItem>+<TabItem value="mstest">-// Stop tracing and export it into a zip archive.-await context.Tracing.StopAsync(new()+```csharp+using System.Text.RegularExpressions;+using Microsoft.Playwright;+using Microsoft.Playwright.MSTest;++namespace PlaywrightTestsMSTest;++[TestClass]+public class UnitTest1 : PageTest{- Path = "trace.zip"-});+ [TestInitialize]+ public async Task TestInitialize()+ {+ await Context.Tracing.StartAsync(new()+ {+ Title = TestContext.TestName,+ Screenshots = true,+ Snapshots = true,+ Sources = true+ });+ }++ [TestCleanup]+ public async Task TestCleanup()+ {+ // This will produce e.g.:+ // bin/Debug/net8.0/playwright-traces/PlaywrightTests.UnitTest1.zip+ await Context.Tracing.StopAsync(new()+ {+ Path = Path.Combine(+ Environment.CurrentDirectory,+ "playwright-traces",+ $"{TestContext.FullyQualifiedTestClassName}.zip"+ )+ });+ }++ [TestMethod]+ public async Task TestYourOnlineShop()+ {+ // ...+ }+}```-This will record the trace and place it into the file named `trace.zip`.+</TabItem>+</Tabs>++This will record the trace and place it into the `bin/Debug/net8.0/playwright-traces/` directory.## Opening the tracediff --git a/docs/src/trace-viewer.md b/docs/src/trace-viewer.mdindex 017679abf1..1f50025c32 100644--- a/docs/src/trace-viewer.md+++ b/docs/src/trace-viewer.md@@ -211,7 +211,7 @@ context.tracing.stop(path = "trace.zip")</details>## Recording a trace-* langs: java, csharp+* langs: javaTraces can be recorded using the [`property: BrowserContext.tracing`] API as follows:@@ -233,30 +233,117 @@ context.tracing().stop(new Tracing.StopOptions().setPath(Paths.get("trace.zip")));```+This will record the trace and place it into the file named `trace.zip`.++## Recording a trace+* langs: csharp++Traces can be recorded using the [`property: BrowserContext.tracing`] API as follows:++<Tabs+ groupId="test-runners"+ defaultValue="nunit"+ values={[+ {label: 'NUnit', value: 'nunit'},+ {label: 'MSTest', value: 'mstest'}+ ]+}>+<TabItem value="nunit">+```csharp-using var playwright = await Playwright.CreateAsync();-var browser = await playwright.Chromium.LaunchAsync();-await using var context = await browser.NewContextAsync();+namespace PlaywrightTests;-// Start tracing before creating / navigating a page.-await context.Tracing.StartAsync(new()+[Parallelizable(ParallelScope.Self)]+[TestFixture]+public class Tests : PageTest{- Screenshots = true,- Snapshots = true,- Sources = true-});+ [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()+ {+ // This will produce e.g.:+ // bin/Debug/net8.0/playwright-traces/PlaywrightTests.Tests.Test1.zip+ 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 TestYourOnlineShop()+ {+ // ..+ }+}+```-var page = await context.NewPageAsync();-await page.GotoAsync("https://playwright.dev");+</TabItem>+<TabItem value="mstest">-// Stop tracing and export it into a zip archive.-await context.Tracing.StopAsync(new()+```csharp+using System.Text.RegularExpressions;+using Microsoft.Playwright;+using Microsoft.Playwright.MSTest;++namespace PlaywrightTestsMSTest;++[TestClass]+public class UnitTest1 : PageTest{- Path = "trace.zip"-});+ [TestInitialize]+ public async Task TestInitialize()+ {+ await Context.Tracing.StartAsync(new()+ {+ Title = TestContext.TestName,+ Screenshots = true,+ Snapshots = true,+ Sources = true+ });+ }++ [TestCleanup]+ public async Task TestCleanup()+ {+ // This will produce e.g.:+ // bin/Debug/net8.0/playwright-traces/PlaywrightTests.UnitTest1.zip+ await Context.Tracing.StopAsync(new()+ {+ Path = Path.Combine(+ Environment.CurrentDirectory,+ "playwright-traces",+ $"{TestContext.FullyQualifiedTestClassName}.zip"+ )+ });+ }++ [TestMethod]+ public async Task TestYourOnlineShop()+ {+ // ...+ }+}```-This will record the trace and place it into the file named `trace.zip`.+</TabItem>+</Tabs>++This will record the trace and place it into the `bin/Debug/net8.0/playwright-traces/` directory.## Opening the trace