pytest-playwright配置base_url
在做自动化测试的时候,我们经常是基于某个测试环境地址去测试某个项目,这样的话我们可以把测试环境的地址拿出来做为一个全局的配置。其它地方用相对地址就行。在本专栏的第45篇教程介绍了如何在实例化content对象时,设置base_url:
context=brower.new_context(base_url=‘https://www.xxxx.com’)
在pytest-playwright可以用到pytest-base-url 插件来实现。
如果你安装了pytest-playwright,则pytest-base-url 插件已经一并安装,不需要单独安装。如果你没有安装pytest-playwright,而是在pytest框架,则需要安装。
安装pytest-base-url 插件:
pip install pytest-base-url
pytest-base-url 插件安装好后,仅需在pytest.ini中配置
[pytest]
base_url=http://www.xxx.com
或者使用命令行参数
pytest --base-url http://www.xxx.com