|

Playwright
Playwright 是一个用于 Web 测试和自动化的框架。它允许使用单一 API 测试Chromium、Firefox和WebKit。Playwright旨在实现持久、强大、可靠且快速的跨浏览器 Web 自动化。
官网:超链接登录可见。
源码:超链接登录可见。
Playwright for .NET 文档:超链接登录可见。
- 跨浏览器:Playwright支持所有现代渲染引擎,包括 Chromium、WebKit 和 Firefox。
- 跨平台:可在 Windows、Linux 和 macOS 上进行测试,本地或持续集成 (CI),无头或有头。
- 跨语言:在TypeScript、JavaScript、Python、.NET、Java中使用 Playwright API 。
- 测试移动网页:Android版 Google Chrome 和移动版 Safari 的原生移动模拟。相同的渲染引擎可在您的桌面和云端运行。
运行环境
Playwright 以 .NET Standard 2.0 库的形式发布。我们推荐使用 .NET 8。
Windows 10+、Windows Server 2016+ 或 Windows Subsystem for Linux (WSL)。
macOS 14 Ventura 或更高版本。
Debian 12、Ubuntu 22.04、Ubuntu 24.04,基于 x86-64 和 arm64 架构。
新建 .NET 8 控制台
首先,引入 nuget 包如下:
然后下载浏览器内核,Node.js 方式下载安装命令如下:
如下:
╔═══════════════════════════════════════════════════════════════════════════════╗
║ 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) from 超链接登录可见。
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) from 超链接登录可见。
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) from 超链接登录可见。
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) from 超链接登录可见。
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 from 超链接登录可见。
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 from 超链接登录可见。
0.1 MiB [====================] 100% 0.0s
Winldd playwright build v1007 downloaded to C:\Users\itsvse\AppData\Local\ms-playwright\winldd-1007
或者使用 C# 在运行的时候自动检测进行安装,代码如下:
否则运行的时候,会报错如下:
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 ║
╚════════════════════════════════════════════════════════════╝
模拟输入用户名和密码,c# 代码如下:
效果图如下:
(完) |
上一篇:B 站开源项目 IndexTTS 部署教程下一篇:【Playwright】(二)常用功能和操作
|