当前位置:网站首页>【Playwright测试教程】5分钟上手
【Playwright测试教程】5分钟上手
2022-08-04 02:17:00 【泽泽说测试】
我喜欢Playwright! 这是微软开源的一款非常强大的自动化工具,再过几年,他很有可能取代Selenium在浏览器自动化的通知地位。使用过一段时间,我没有找到很好的中文资料可以参考,导致很多问题无法得到及时解决,因此我决定自己记录一下使用的笔记,算是给社区回馈。
开始
这次我想整理一下如何快速搭建Playwright的执行环境,其中有一些坑,我也会记录,以后重新搭环境的时候照着操作就可以了。
Playwright 目前支持的编程语言有 JavaScript、Python、Java、.NET,本教程使用 Python 语言演示。要在 Python 语言当中使用 Playwright,需要执行两个步骤。第一步,安装python的执行环境。第二步,安装 Playwright。
安装
安装python只需要从官方网站下载安装包,点击安装就可以完成。首先我们打开python的官方网站,然后点击 download 下载安装包。不同的操作系统会推荐不同的安装包。下载完成后点击安装文件完成安装。
安装 Playwright
Playwright 的 Python语言安装包几乎包含了所有需要用到的组件,安装 playwright 工具唯一需要做的事情就是打开命令行工具,输入安装指令:
pip install playwright
playwright install
pip install playwright 安装语言包工具,除此之外,playwright 需要依赖浏览器环境才能运行,playwright install 的意思是下载和安装依赖的浏览器。浏览器不需要提前安装,通过这行命令,程序会自动下载一个 chrioum 浏览器和一个 firefox 浏览器,之后的浏览器操作都会在这些浏览器上运行。耐心等待浏览器下载完成后,就完成了安装,以后每次运行不会再重复下载。
如果觉得等待时间太长,也可以选择单独安装 chromium 浏览器或者 firefox 浏览器,目前支持的浏览器有chromium, chrome, chrome-beta, msedge, msedge-beta, msedge-dev, firefox, webkit。
playwright install chromium
# or
playwright install firefox
所有关于 playwright 的命令行参数,你都可以通过 help 指令查看:
$ playwright --help
Usage: npx playwright [options] [command]
Options:
-V, --version output the version number
-h, --help display help for command
Commands:
open [options] [url] open page in browser specified via -b, --browser
codegen [options] [url] open page and generate code for user actions
install [options] [browser...] ensure browsers necessary for this version of Playwright are installed
install-deps [browser...] install dependencies necessary to run browsers (will ask for sudo permissions)
cr [options] [url] open page in Chromium
ff [options] [url] open page in Firefox
wk [options] [url] open page in WebKit
screenshot [options] <url> <filename> capture a page screenshot
pdf [options] <url> <filename> save page as pdf
show-trace [options] [trace] Show trace viewer
help [command] display help for command
运行
当安装好 Playwright 以及浏览器之后,我们可以通过下面的代码来简单运行。这个程序会打开一个浏览器,并且访问一个网址,然后你就可以在浏览器上执行操作了。你做的每步操作,都会被 playwright 录制下来,生成运行代码,显示在一个 Inspector 的界面中,这些代码可以拷贝下来,保存到代码库当中。
playwright codegen http://www.baidu.com

未完待续~~
边栏推荐
- Continuing to invest in product research and development, Dingdong Maicai wins in supply chain investment
- Web APIs BOM - operating browser: swiper plug-in
- 持续投入商品研发,叮咚买菜赢在了供应链投入上
- Promise solves blocking synchronization and turns asynchronous into synchronous
- 网页三维虚拟展厅为接入元宇宙平台做基础
- 云开发旅游打卡广场微信小程序源码(含视频教程)
- HBuilderX的下载安装和创建/运行项目
- 持续投入商品研发,叮咚买菜赢在了供应链投入上
- 静态/动态代理模式
- Use of lombok annotation @RequiredArgsConstructor
猜你喜欢

Qt中对象树的机制介绍以及底层实现,各种结果分析:(以及自己写容易犯错的点)

实例036:算素数

实例040:逆序列表

Example 041: Methods and variables of a class
编写 BOLL 心得体会

html select标签赋值数据库查询结果

Dong mingzhu live cold face away, when employees frequency low-level mistakes, no one can understand their products

5. Scrapy middleware & distributed crawler

持续投入商品研发,叮咚买菜赢在了供应链投入上

什么是SVN(Subversion)?
随机推荐
5. Scrapy middleware & distributed crawler
[QNX Hypervisor 2.2用户手册]10.3 vdev gic
Kubernetes:(十一)KubeSphere的介绍和安装(华丽的篇章)
各位大佬好,麻烦问一下flink cdc oracle写入doris的时候,发现cpu异常,一下下跑
HBuilderX的下载安装和创建/运行项目
web端动效 lottie-web 使用
计算首屏时间
持续投入商品研发,叮咚买菜赢在了供应链投入上
IDEA02:配置SQL Server2019数据库
html select标签赋值数据库查询结果
MallBook联合人民交通出版社,推动驾培领域新发展,开启驾培智慧交易新生态
Flask Framework Beginner-05-Command Management Manager and Database Use
[QNX Hypervisor 2.2 User Manual] 10.3 vdev gic
this巩固训练,从两道执行题加深理解闭包与箭头函数中的this
pytorch应用于MNIST手写字体识别
Snake game bug analysis and function expansion
工程制图复习题(带答案)
Day13 Postman的使用
Continuing to pour money into commodities research and development, the ding-dong buy vegetables in win into the supply chain
flinkcdc 消费 mysql binlog 没有 sqltype=delete 的数据是什么原