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(dotnet): First part/pass for guides (#6583)
Anže Vodovnik0aa9e0637016
diff --git a/docs/src/assertions.md b/docs/src/assertions.mdindex 5d04de2492..db47338db7 100644--- a/docs/src/assertions.md+++ b/docs/src/assertions.md@@ -30,6 +30,11 @@ content = page.text_content("nav:first-child")assert content == "home"```+```csharp+var content = await page.TextContentAsync("nav:first-child");+Assert.Equals("home", content);+```+### API reference- [`method: Page.textContent`]- [`method: ElementHandle.textContent`]@@ -56,6 +61,11 @@ text = page.inner_text(".selected")assert text == "value"```+```csharp+var content = await page.InnerTextAsync(".selected");+Assert.Equals("value", content);+```+### API reference- [`method: Page.innerText`]- [`method: ElementHandle.innerText`]@@ -82,6 +92,11 @@ checked = page.get_attribute("input", "alt")assert alt == "Text"```+```csharp+var value = await page.GetAttributeAsync("input", "alt");+Assert.Equals("Text", value);+```+## Checkbox state```js@@ -104,6 +119,11 @@ checked = page.is_checked("input")assert checked```+```csharp+var checked = await page.IsCheckedAsync("input");+Assert.True(checked);+```+### API reference- [`method: Page.isChecked`]- [`method: ElementHandle.isChecked`]@@ -130,6 +150,11 @@ content = page.eval_on_selector("nav:first-child", "e => e.textContent")assert content == "home"```+```csharp+var content = await page.EvalOnSelectorAsync("nav:first-child", "e => e.textContent");+Assert.Equals("home", content);+```+### API reference- [`method: Page.evalOnSelector`]- [`method: JSHandle.evaluate`]@@ -156,6 +181,11 @@ html = page.inner_html("div.result")assert html == "<p>Result</p>"```+```csharp+var html = await page.InnerHTMLAsync("div.result");+Assert.Equals(html, "<p>Result</p>");+```+### API reference- [`method: Page.innerHTML`]- [`method: ElementHandle.innerHTML`]@@ -182,6 +212,11 @@ visible = page.is_visible("input")assert visible```+```csharp+var visibility = await page.IsVisibleAsync("input");+Assert.True(visibility);+```+### API reference- [`method: Page.isVisible`]- [`method: ElementHandle.isVisible`]@@ -208,6 +243,11 @@ enabled = page.is_enabled("input")assert enabled```+```csharp+var enabled = await page.IsEnabledAsync("input");+Assert.True(enabled);+```+### API reference- [`method: Page.isEnabled`]- [`method: ElementHandle.isEnabled`]@@ -294,6 +334,25 @@ length = page.eval_on_selector_all('li.selected', '(items) => items.length')assert length == 3```+```csharp+// Assert local storage value+var userId = await page.EvaluateAsync<string>("() => window.localStorage.getItem('userId')");+Assert.NotNull(userId);++// Assert value for input element+await page.WaitForSelectorAsync("#search");+var value = await page.EvalOnSelectorAsync("#search", "el => el.value");+Assert.Equals("query", value);++// Assert computed style+var fontSize = await page.EvalOnSelectorAsync<string>("div", "el => window.getComputedStyle(el).fontSize");+Assert.Equals("16px", fontSize);++// Assert list length+var length = await page.EvalOnSelectorAllAsync<int>("li.selected", "items => items.length");+Assert.Equals(3, length);+```+### API reference- [`method: Page.evaluate`]- [`method: Page.evalOnSelector`]diff --git a/docs/src/auth.md b/docs/src/auth.mdindex 87651699e4..db031ac954 100644--- a/docs/src/auth.md+++ b/docs/src/auth.md@@ -224,6 +224,23 @@ context.add_init_script(storage => {}, session_storage)```+```csharp+// Get session storage and store as env variable+var sessionStorage = await page.EvaluateAsync<string>("() => JSON.stringify(sessionStorage");+Environment.SetEnvironmentVariable("SESSION_STORAGE", sessionStorage);++// Set session storage in a new context+var loadedSessionStorage = Environment.GetEnvironmentVariable("SESSION_STORAGE");+await context.AddInitScriptAsync(@"(storage => {+ if (window.location.hostname === 'example.com') {+ const entries = JSON.parse(storage);+ Object.keys(entries).forEach(key => {+ window.sessionStorage.setItem(key, entries[key]);+ });+ }+ })(" + loadedSessionStorage + ")");+```+### API reference- [`method: BrowserContext.storageState`]- [`method: Browser.newContext`]@@ -290,6 +307,20 @@ with sync_playwright() as p:# Execute login steps manually in the browser window```+```csharp+using Microsoft.Playwright;++class Guides+{+ public async void Main()+ {+ using var playwright = await Playwright.CreateAsync();+ var chromium = playwright.Chromium;+ var context = chromium.LaunchPersistentContextAsync(@"C:\path\to\directory\", headless: false);+ }+}+```+### Lifecycle1. Create a user data directory on disk@@ -298,4 +329,4 @@ with sync_playwright() as p:### API reference- [BrowserContext]-- [`method: BrowserType.launchPersistentContext`]\ No newline at end of file+- [`method: BrowserType.launchPersistentContext`]diff --git a/docs/src/ci.md b/docs/src/ci.mdindex d7541e747f..bf574a9b47 100644--- a/docs/src/ci.md+++ b/docs/src/ci.md@@ -100,6 +100,10 @@ Suggested configuration})```+ ```csharp+ await playwright.Chromium.LaunchAsync(args: new[] { "--disable-dev-shm-usage" });+ ```+This will write shared memory files into `/tmp` instead of `/dev/shm`. See[crbug.com/736452](https://bugs.chromium.org/p/chromium/issues/detail?id=736452) for more details.1. Using `--ipc=host` is also recommended when using Chromium—without it Chromium can run out of memory@@ -259,6 +263,20 @@ browser = await playwright.chromium.launch(chromiumSandbox=False)browser = playwright.chromium.launch(chromiumSandbox=False)```+```csharp+using Microsoft.Playwright;+using System.Threading.Tasks;++class Guides+{+ public async void Main()+ {+ using var playwright = await Playwright.CreateAsync();+ await playwright.Chromium.LaunchAsync(chromiumSandbox: false);+ }+}+```+### GitLab CITo run Playwright tests on GitLab, use our public Docker image ([see Dockerfile](./docker.md)).@@ -371,6 +389,20 @@ with sync_playwright() as p:browser = p.chromium.launch(headless=False)```+```csharp+using Microsoft.Playwright;+using System.Threading.Tasks;++class Guides+{+ public async void Main()+ {+ using var playwright = await Playwright.CreateAsync();+ await playwright.Chromium.LaunchAsync(headless: false);+ }+}+```+On Linux agents, headed execution requires [Xvfb](https://en.wikipedia.org/wiki/Xvfb) to be installed. Our [Docker image](./docker.md) and GitHub Action have Xvfb pre-installed. To run browsers in headed mode with Xvfb, add `xvfb-run` before the Node.js command.```sh js