Selenium webdriver fixture for py.test
项目描述
此 fixture 提供了配置好的 webdriver 以进行 Selenium 浏览器测试,并在测试失败时为您自动截图。
安装
使用您喜欢的包安装程序进行安装
pip install pytest-webdriver
# or
easy_install pytest-webdriver
在您的测试或 conftest.py 中显式启用 fixture(使用 setuptools 入口点时不需要)
pytest_plugins = ['pytest_webdriver']
快速入门
此 fixture 连接到远程 selenium webdriver 并返回浏览器句柄。它按函数级别进行范围划分,因此您在每个测试中获得一个浏览器窗口。
要使用此 fixture,请按照以下步骤操作。
指定一个浏览器主机,并在该主机上启动 webdriver 可执行文件。
从这里下载最新的zip文件:https://sites.google.com/a/chromium.org/chromedriver/downloads
解压缩到目标主机,并运行解压缩后的chromedriver二进制可执行文件。
将环境变量SELENIUM_HOST设置为浏览器主机的IP地址或主机名。默认为本地主机名。
将环境变量SELENIUM_PORT设置为webdriver服务器的端口号。默认端口号为4444。
将环境变量SELENIUM_BROWSER设置为浏览器类型。默认为chrome。
将测试夹具用作测试参数
def test_mywebpage(webdriver):
webdriver.get('http://www.google.com')
SELENIUM_URI设置
您也可以使用SELENIUM_URL环境变量通过URI格式指定selenium服务器地址
.. code:: bash
$ export SELENIUM_URI=https://#:4444/wd/hub
当处理selenium服务器而不是chrome驱动程序时需要这样做(见https://groups.google.com/forum/?fromgroups#!topic/selenium-users/xodZDJxt81o)。如果SELENIUM_URI未定义,则使用SELENIUM_HOST & SELENIUM_PORT。
自动截图
当您的浏览器测试失败时,此插件将为您截取屏幕截图并将其保存在当前工作目录中。名称将与失败的测试函数的逻辑路径匹配,例如
test_login_page__LoginPageTest__test_unicode.png
pytest-webdriver和PageObjects
如果当前测试中正在运行pyramid_server夹具,它将检测到并设置webdriver实例上的root_uri属性
def test_my_pyramid_app(webdriver, pyramid_server):
assert webdriver.root_uri == pyramid_server.uri
为什么需要这样做呢?它可以由PageObjects库用来自动设置Web应用的基本URL。这可以节省大量的字符串连接。例如
from page_objects import PageObject, PageElement
class LoginPage(PageObject):
username = PageElement(id_='username')
password = PageElement(name='password')
login = PageElement(css='input[type="submit"]')
def test_login_page(webdriver, pyramid_server):
page = LoginPage(webdriver)
page.login.click()
page.get('/foo/bar')
assert webdriver.getCurrentUrl() == pyramid_server.uri + '/foo/bar'
变更日志
1.7.0
所有:支持pytest >= 4.0.0
所有:支持Python 3.7
pytest-server-fixtures:如果您的机器上未定义主机,则默认为localhost
pytest-server-fixture:由于上游API更改,将rethinkdb < 2.4.0锁定以解决兼容性问题
pytest-verbose-parametrize:添加对改进的标记基础设施的支持
pytest-verbose-parametrize:修复集成测试以支持pytest >= 4.1.0
pytest-virtualenv:添加virtualenv作为安装要求。修复#122
pytest-webdriver:使用getfixturevalue修复RemovedInPytest4Warning
circleci:跳过对没有推送访问权限的开发者的coverall提交以修复检查
wheels:生成既可安装于python 2.x也可安装于3.x的通用wheels
dist:移除构建和分发*.egg文件的支持
VagrantFile:安装python 3.7并默认初始化python 3.7
修复使用“logger.warning()”函数的DeprecationWarning警告
1.6.2 (2019-02-21)
pytest-server-fixtures:如果调用kill()则抑制堆栈跟踪
pytest-server-fixtures:修复TestServerV2中的随机端口逻辑
1.6.1 (2019-02-12)
pytest-server-fixtures:修复在服务器未启动时尝试访问主机名时的异常
1.6.0 (2019-02-12)
pytest-server-fixtures:添加之前已删除的TestServerV2.kill()函数
pytest-profiling:在集成测试中将more-itertools==5.0.0锁定,因为这是一个仅PY3的版本
1.5.1 (2019-01-24)
pytest-verbose-parametrize:修复使用@pytest.mark.parametrize时的Unicode参数
1.5.0 (2019-01-23)
pytest-server-fixtures:使postgres夹具及其测试可选,如所有其他夹具一样
pytest-server-fixtures:撤销对pymongo弃用警告的修复,因为这会破坏与pymongo 3.6.0的兼容性
pytest-server-fixtures:在httpd中停止对RHEL5的支持
1.4.1 (2019-01-18)
pytest-server-fixtures:现在仅通过ENV指定的环境变量中的服务器固定二进制路径影响服务器类‘thread’
1.4.0 (2019-01-15)
修复Simple HTTP Server夹具中的Python 3兼容性问题
修复pytest-profiling中的损坏测试
将pytest<4.0.0锁定,直到所有弃用警告都得到修复。
pytest-webdriver:用废弃的phantomjs替换为无头Google Chrome。
将Vagrantfile添加到项目中以使测试环境可移植。
将.editorconfig文件添加到项目中。
pytest-server-fixtures:添加具有Docker和Kubernetes支持的TestServerV2。
pytest-server-fixtures: 修复了 MinioServer 在使用后没有清理的问题。
pytest-server-fixtures: 修复了调用 pymongo 时的弃用警告。
pytest-server-fixtures: 在 MongoTestServer 构建时关闭 pymongo 客户端。
pytest-server-fixtures: 将 Mongo、Redis 和 RethinkDB 升级到 TestServerV2。
coveralls: 修复了损坏的 coveralls。
1.3.1 (2018-06-28)
使用 pymongo list_database_names() 替代已弃用的 database_names(),并添加了 pymongo>=3.6.0 依赖。
1.3.0 (2017-11-17)
修复了 teardown 为 None 时的工作空间删除问题。
修复了 pytest-listener 中根日志记录器的压缩。
添加了 S3 Minio 固定装置(多谢 Gavin Bisesi)。
添加了 Postgres 固定装置(多谢 Gavin Bisesi)。
使用 requests 进行服务器固定装置的 http gets,因为它可以正确处理重定向和代理。
1.2.12 (2017-8-1)
修复了缓存临时主机名的回归,一些客户端依赖于此。现在这是可选的。
1.2.11 (2017-7-21)
修复了 OSX 绑定到非法本地 IP 范围的问题(多谢 Gavin Bisesi)。
为 pytest-profiling 设置和 Py3k 修复(多谢 xoviat)。
当预留本地 IP 主机时,我们不再尝试绑定端口 5000,因为有人可能将其绑定到 0.0.0.0。
修复了 #46 当本地虚拟环境未激活时源 gprof2dot 的回归。
1.2.10 (2017-2-23)
在 pytest-webdriver 中处理自定义 Pytest 测试项。
1.2.9 (2017-2-23)
在 mongo 服务器固定装置的 tempdir 路径中添加用户名,以防止在共享多用户文件系统上的冲突。
1.2.8 (2017-2-21)
在 shutil.run.run_as_main 中返回函数结果。
1.2.7 (2017-2-20)
对 older versions of path.py 的更多处理。
允许在 pytest-virtualenv 中传递 virtualenv 参数。
1.2.6 (2017-2-16 )
更新了 devpi-server 服务器设置以兼容 devpi-server >= 2.0。
对随机端口选择进行了改进。
HTTPD 服务器现在默认绑定到 0.0.0.0 以帮助进行 Selenium 风格的测试。
更新了 mongodb 服务器参数以兼容 mongodb >= 3.2。
对 mongodb 固定装置配置进行了纠正并改进了启动逻辑。
添加了模块作用域的 mongodb 固定装置。
对 older versions of path.py 进行了处理。
修复了 #40 中 chdir 破坏 pytest-profiling 的问题。
1.2.5 (2016-12-09)
对服务器运行器主机和端口生成进行了改进,现在支持随机本地 IP。
对 RethinkDB 固定装置配置进行了修复。
1.2.4 (2016-11-14)
对 pymongo 额外依赖进行了修复。
修复了 pytest-virtualenv 的 Windows 兼容性(多谢 Jean-Christophe Fillion-Robin 的 PR)。
修复了 pytest-shutil.cmdline.get_real_python_executable 的符号链接处理。
1.2.3 (2016-11-7)
提高了 Mongo 固定装置启动检查的弹性。
1.2.2 (2016-10-27)
大多数模块跨 Python 3 的兼容性。
修复了 deprecated Path.py 导入(多谢 Bryan Moscon)。
修复了 pytest-profiling 中的 deprecated multicall(多谢 Paul van der Linden 的 PR)。
添加了 devpi-server 固定装置以创建每个测试函数的索引。
添加了缺失的许可文件。
拆分了 httpd 服务器固定装置配置,以便子类可以更容易地覆盖加载的模块。
在 TestServer 基类中添加了 'preserve_sys_path' 参数,该参数将当前 python sys.path 导出给子进程。
更新了 httpd、redis 和 jenkins 运行时参数和路径以符合当前的 Ubuntu 规范。
在拆卸工作空间时忽略错误,以避免 'shutil.rmtree' 实现中的竞争条件。
1.2.1 (2016-3-1)
修复了 pytest-verbose-parametrize 以兼容最新的 py.test 版本。
1.2.0 (2016-2-19)
新插件:git 仓库固定装置。
1.1.1 (2016-2-16)
pytest-profiling 改进:在 .prof 文件中转义非法字符(多谢 Aarni Koskela 的 PR)。
1.1.0 (2016-2-15)
新插件:devpi 服务器固定装置。
pytest-profiling 改进:过长的 .prof 文件保存为测试名称的短哈希(多谢 Vladimir Lagunov 的 PR)。
出于安全原因,将 workspace.run() 的默认行为更改为不使用子shell。
修复了 virtualenv.run() 方法,使其与父方法 workspace.run() 处理参数的方式相同。
从 virtualenv 参数中删除了 deprecated 的 ‘–distribute’。
1.0.1 (2015-12-23)
修复了打包错误。
1.0.0 (2015-12-21)
初始公开发布。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源分布
构建分布
pytest-webdriver-1.7.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | f93552f44979bc1d6d34eea9fc587d9d9ea7f9c36344916b68057a960c34210e |
|
MD5 | 33110c8c5d25bc703a449a96a6ecbfc6 |
|
BLAKE2b-256 | 92d3e2160ba8104295f12210d9f4e4b2b7960ce38fec06d79915714a6d21d15a |
pytest-webdriver-1.7.0-py3.6.egg 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | ede974d656bc0c60a947470a791e3fdcd25b93295a3432b65040805f4c9d04a2 |
|
MD5 | ba301490bfbfbf1399ac1c9c83e8d3b1 |
|
BLAKE2b-256 | a404eb9b8f870f208717989807c6f15077a15bd2a69445067307854cc3dff4d1 |
pytest-webdriver-1.7.0-py2.py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 5bedc08f6c4c21ce206118d942eb896bcdaaf30675f79629c7d935493aac32e7 |
|
MD5 | 0dd00f233e678e087e37f0b2e98e0b38 |
|
BLAKE2b-256 | 33280a398cbe6bbedb6cf7b6bbd4d693fbbb9ac21084ef62034c2063d92a09c1 |
pytest-webdriver-1.7.0-py2.7.egg 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 33bc0fda0b8baacae69c4b1b603692eca91b7ede8dcc7338b2df44042f213156 |
|
MD5 | 0a35b76fde31529031a18a8cdb87de8c |
|
BLAKE2b-256 | d7b5932a47fb26bc2da5202355a37d0cc123cc33010eeb09fa3399f6c757cadc |