Playwright
Playwright is a framework for web testing and automation. It allows testing Chromium, Firefox, and WebKit using a single API. Playwright is designed to enable durable, powerful, reliable, and fast cross-browser web automation.
Official Website:The hyperlink login is visible. Source:The hyperlink login is visible. Playwright for .NET documentation:The hyperlink login is visible.
- Cross-Browser: Playwright supports all modern rendering engines, including Chromium, WebKit, and Firefox.
- Cross-platform: Available for testing on Windows, Linux, and macOS, local or continuous integration (CI), headless or headed.
- Cross-language: in TypeScript, JavaScript, Python, . NET, Java uses the Playwright API.
- Test mobile web pages: Native mobile emulation of Google Chrome for Android and Safari for mobile. The same rendering engine runs on your desktop and in the cloud.
operating environment
Playwright is released as a .NET Standard 2.0 library. We.NET 8 is recommended。 Windows 10+, Windows Server 2016+, or Windows Subsystem for Linux (WSL). macOS 14 Ventura or later. Debian 12, Ubuntu 22.04, Ubuntu 24.04, based on x86-64 and arm64 architectures.
Create a new .NET 8 console
First, the nuget package is introduced as follows:
Then download the browser kernel and download the installation command Node.js the following method:
As follows:
╔═══════════════════════════════════════════════════════════════════════════════╗ ║ WARNING: It looks like you are running 'npx playwright install' without first ║ ║ installing your project's dependencies. ║ ║ ║ ║ To avoid unexpected behavior, please install your dependencies first, and ║ ║ then run Playwright's install command: ║ ║ ║ ║ npm install ║ ║ npx playwright install ║ ║ ║ ║ If your project does not yet depend on Playwright, first install the ║ ║ applicable npm package(most commonly @playwright/test), and ║ ║ then run Playwright's install command to download the browsers: ║ ║ ║ ║ npm install @playwright/test ║ ║ npx playwright install ║ ║ ║ ╚═══════════════════════════════════════════════════════════════════════════════╝ Downloading Chromium 136.0.7103.25 (playwright build v1169) fromThe hyperlink login is visible. 144.4 MiB[====================] 100% 0.0s Chromium 136.0.7103.25 (playwright build v1169) downloaded to C:\Users\itsvse\AppData\Local\ms-playwright\chromium-1169 Downloading Chromium Headless Shell 136.0.7103.25 (playwright build v1169) fromThe hyperlink login is visible. 89.1 MiB[====================] 100% 0.0s Chromium Headless Shell 136.0.7103.25 (playwright build v1169) downloaded to C:\Users\itsvse\AppData\Local\ms-playwright\chromium_headless_shell-1169 Downloading Firefox 137.0 (playwright build v1482) fromThe hyperlink login is visible. 92.1 MiB [====================] 100% 0.0s Firefox 137.0 (playwright build v1482) downloaded to C:\Users\itsvse\AppData\Local\ms-playwright\firefox-1482 Downloading Webkit 18.4 (playwright build v2158) fromThe hyperlink login is visible. 57.1 MiB [====================] 100% 0.0s Webkit 18.4 (playwright build v2158) downloaded to C:\Users\itsvse\AppData\Local\ms-playwright\webkit-2158 Downloading FFMPEG playwright build v1011 fromThe hyperlink login is visible. 1.3 MiB [====================] 100% 0.0s FFMPEG playwright build v1011 downloaded to C:\Users\itsvse\AppData\Local\ms-playwright\ffmpeg-1011 Downloading Winldd playwright build v1007 fromThe hyperlink login is visible. 0.1 MiB [====================] 100% 0.0s Winldd playwright build v1007 downloaded to C:\Users\itsvse\AppData\Local\ms-playwright\winldd-1007 Or useC# automatically detects and installs at runtime, the code is as follows:
Otherwise, the error will be reported as follows:
Executable doesn't exist at C:\Users\itsvse\AppData\Local\ms-playwright\chromium-1169\chrome-win\chrome.exe ╔════════════════════════════════════════════════════════════╗ ║ Looks like Playwright was just installed or updated. ║ ║ Please run the following command to download new browsers: ║ ║ ║ ║ pwsh bin/Debug/netX/playwright.ps1 install ║ ║ ║ ║ <3 Playwright Team ║ ╚════════════════════════════════════════════════════════════╝ Simulate entering a username and password with the following C# code:
The renderings are as follows:
(End) |