Playwright 自动化测试 录制操作并自动生成代码

playwright是由微软开发的Web UI自动化测试工具, 支持Node.js、Python、C# 和 Java语言,本文将介绍playwright的特性以及它的简单使用。

# 安装

Playwright有Node.js、Python、C# 和 Java语言版本,本文介绍Python版本的Playwright使用方法。

Playwright的Python版本仓库地址:[https://github.com/microsoft/playwright-python](https://github.com/microsoft/playwright-python)

官方文档地址:[https://playwright.dev/python/docs/intro](https://playwright.dev/python/docs/intro)

Playwright安装简单,pip安装时会自动下载浏览器驱动:

```

pip install playwright

playwright install # 安装支持的浏览器:cr, chromium, ff, firefox, wk 和 webkit

playwright install chromium # 安装指定的chromium浏览器

```

脚本录制

在命令行窗口使用如下语法格式进行脚本录制:

npx playwright codegen [options] [url]

options参数:

-o, --output <file name> :保存生成脚本

--target <language> :生成的脚本语言,可以设置javascript, test, python, python-async和csharp,默认为python。

-b, --browser <browserType> :要使用的浏览器,可以选择cr, chromium, ff, firefox, wk和webkit,默认chromium。

--channel <channel>:chromium版本,比如chrome, chrome-beta, msedge-dev等,

--color-scheme <scheme>:模拟器的颜色主题,可选择light 或者 dark样式。

--device <deviceName> :模拟的设备,比如iPhone 11。

--save-storage <filename> :保存上下文状态,用于保存cookies 和localStorage,可用它来实现重用。例如playwright codegen --save-storage=auth.json

--load-storage <filename> :加载--save-storage 保存的数据,重用认证数据。

--proxy-server <proxy> :指定代理服务器

--timezone <time zone> : 指定时区

--geolocation <coordinates> :指定地理位置坐标

--lang <language> :指定语言/地区,比如中国大陆:zh-CN

--timeout <timeout> :超时时间,定位毫秒,默认10000ms

--user-agent <ua string> :用户代理

--viewport-size <size> :浏览器窗口大小

-h, --help :查看帮助信息

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容