用于selenium webdriver测试执行的python模块

shishito的Python项目详细描述


shishito

shishito是使用selenium webdriver&python进行web和移动应用程序功能测试的模块。 它使用包含的库运行测试,并生成良好的测试结果输出。

文档-http://shishito.readthedocs.org/en/latest/index.html(托管在阅读文档上)

功能

  • 通过pytest运行python selenium webdriver测试
  • 轻松配置本地和远程(BrowserStack、Appium等)测试执行
  • 包含有用的测试库
  • 生成HTML测试结果报告(带有失败测试的屏幕截图)
  • 设计用作一个模块(如果需要,可由多个项目使用)

先决条件

从requirements.txt安装python moodules

pip install-r requirements.txt

需要设置webdriver驱动程序(chromedriver、internetexplorerdriver等)

快速启动

  1. 克隆shishito仓库。 git clone git@github.com:salsita/shishito.git
  2. shishito目录添加到pythonpath环境变量中
  3. 克隆示例测试项目存储库https://github.com/salsita/shishito-sample projectgit clone git@github.com:salsita/shishito sample project.git
  4. 如果要使用BrowserStack运行测试,请在shishito sample project/config/server-config.properties中用凭据替换"bs-username"、"bs-password"值 或者使用flag--browserstack username:token将其作为命令行参数传递给runner python文件
  5. 如果要使用saucelabs运行测试,请将凭据添加到shishito sample project/config/server_config.properties中的saucelabs变量 或者使用flag--saucelabs username:token将其作为命令行参数传递给runner python文件
  6. 在shishito sample project/config/web/(browserstack local).properties或shishito sample project/config/mobile/appium.properties中的移动应用程序中设置首选浏览器设置
  7. 在示例项目文件夹中运行google_test_runner.py!

如果您使用本地驱动程序,您现在应该看到浏览器正在启动并且测试正在运行。 控制台输出中显示了有关进度的信息。 测试完成后,可以在以下位置找到HTML报告:

shishito-sample-project/results folder # HTML report
shishito-sample-project/results_archive folder # zipped HTML report

连续积分

使用Shishito和持续集成解决方案,如Jenkins,很容易! 您只需克隆shishito repo并将其添加到pythonpath中即可。

下面的脚本示例(jenkins"execute shell"构建步骤):

#!/bin/bash####################### clone Shishito  #######################cd$WORKSPACE
git clone git@github.com:salsita/shishito.git

####################### VARIABLES          #######################exportPYTHONPATH=${PYTHONPATH}:/$WORKSPACE/shishito

####################### SCRIPT             #######################

python google_test_runner.py

命令行选项

--platformweb# define platform on which run tests (currently supported: web, mobile, generic)--environmnetlocal# define environment in which run tests (currently supported: local, browserstack, appium, remote)--test_directorytests# define directory where to lookup for tests (project_root + test_directory)# supported platform/environment combinations:#   generic/local#   generic/remote#   web/local#   web/browserstack#   web/remote#   mobile/appium (can run on local/remote appium server or on saucelabs)#   node_webkit/node_webkit--smoke# runs only tests with fixture "@pytest.mark.smoke"--browserstacktestuser1:p84asd21d15asd454# authenticate on BrowserStack using user "testuser1" and token "p84asd21d15asd454"--saucelabstestuser1:p84asd21d15asd454# authenticate on Saucelabs using user "testuser1" and token "p84asd21d15asd454"--test_railuser@email.com:1AVFS51AS# authenticate on TestRail using user email "user@email.com" and password "1AVFS51AS"

如果没有指定参数,shishito默认情况下会在(server local).properties文件中搜索设置组合,并根据它们运行测试。

配置文件

服务器配置属性

  • 带有测试变量的默认配置文件
  • 对变量的更改应该在VCS中维护;这样配置就可以被重用,以便自动执行测试
# modules
test_platform=web
test_environment=local

# test dir
test_directory=tests

# General
base_url=http://www.google.com
environment_configuration=Chrome
  • 测试平台-在哪个平台上运行测试(Web、移动)
  • test_environment-在哪个环境中运行测试(local、browserstack、appium)
  • test_目录-在哪个目录中查找测试
  • 基本URL-在每次测试开始时默认加载的URL
  • environment_configuration-哪个配置使用<;environment>;.properties文件(在没有运行程序的情况下运行测试时使用)
  • 远程驱动程序URL-远程驱动程序集线器。Selenium服务器需要在此URL上运行。

本地配置属性>

  • 如果变量local_execution=true,脚本将首先搜索本地配置以查找测试变量
  • 如果找不到变量,它将返回到默认的服务器配置属性值
  • 对该文件的更改不应在VCS中维护(它们仅用于本地测试执行)

<;平台>;/<;环境>;。属性

  • 包含应执行测试的组合
  • 例如,本地网络浏览器的浏览器和分辨率

conftest.py

  • 定义命令行参数、为shishito runner提供fixture和其他信息的助手文件

配置

可以使用命令行参数和配置文件配置shishito。一些配置值也作为参数添加到pytest(取决于测试环境)。 根据这些优先级查找配置值:

  1. pytest.config
  2. 命令行参数
  3. 本地配置文件(如果启用:本地执行=真)
  4. 服务器配置文件

节点WebKit配置

shishito能够对node webkit应用程序运行测试。当前的实现不允许tester指定基于url的url,只允许从应用程序中直接指定的url运行应用程序。 创建webdriver驱动程序对象是由特定的chromedriverchromedriver完成的,它必须与node webkit application放在同一目录中。 chromedriver将搜索节点webkit二进制文件并启动应用程序。二进制文件必须有特定的名称,否则chromedriver找不到它们。
节点WebKit二进制文件必须具有名称:

  • 对于Linux:nw
  • 对于Windows:nw.exe
  • 对于OS X:node webkit.app

故障时的临时屏幕截图功能

由于节点webkit chromedriver中的问题;已添加 使用pyscreenshot模块的故障时的临时屏幕截图功能。此功能拍摄整个桌面的截图,而不仅仅是节点webkit 应用程序窗口。此问题应在Chromedriver 2.15中修复。node webkit chromedriver v2.15有alpha版本。 一旦问题解决,此功能将被删除。

注意:ubuntu:还需要安装python imaging sudo apt get install python imaging

节点WebKit平台故障排除

如果您看到与下面类似的异常

   raise WebDriverException(
       \"\'\" + os.path.basename(self.path) + \"\' executable needs to be \
           available in the path. Please look at \
           http://docs.seleniumhq.org/download/#thirdPartyDrivers \
           and read up at \
\>                   http://code.google.com/p/selenium/wiki/ChromeDriver")
E    WebDriverException: Message: 'chromedriver' executable needs to be available in the path. Please look at http://docs.seleniumhq.org/download/#thirdPartyDrivers and read up at http://code.google.com/p/selenium/wiki/ChromeDriver

/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/service.py:70: WebDriverException

您需要检查chromedriver文件的访问权限,主要是在linux或os x上,windows应该没问题。

测试管理支持

shishito支持将测试结果上传到testrail测试管理应用程序。 必须填写服务器/本地配置中的以下属性:

  • 测试轨道-测试轨道的凭据。也可以保留为空并通过cmd参数传递(见上文)
  • test_rail_url-test rail实例的url。(例如:https://mycompany.testrail.net" rel="nofollow">https://mycompany.testrail.net)
  • test_rail_project_id-testrail project的id(示例:1)
  • 试验轨道截面图ID-试验轨道试验截面图ID(示例:2)
  • 测试轨道测试计划ID-测试轨道测试计划的ID(示例:5)
  • test_rail_suite_id-testrail测试套件的id(示例:1)

有关更多信息,请参见testrail api文档http://docs.gurock.com/testrail-api2/start" rel="nofollow">http://docs.gurock.com/testrail-api2/start

历史记录

3.1.10(2019-08-12)

  • 将html报告更新为contain在pytest收集阶段收集的偶数错误

3.1.9(2019-07-18)

  • shiscript未将新添加的包更新到requirements.txt的小修复

3.1.8(2019-07-03)

  • 修复HTML测试报告,在安装阶段不显示错误
  • 禁止转义测试报告中的特殊字符错误消息

3.1.7(2019-07-01)

  • 支持Chromedriver 75+的下载路径
  • 让下载路径成为可选路径

3.1.6(2019-06-18)

  • 支持下载路径和浏览器扩展

3.1.5(2019-05-22)

  • 小修

3.1.4(2019-05-21)

  • 修复flaky&html报告问题

3.1.3(2019-03-07)

  • 扩展Appium BrowserStack功能

3.1.2(2019-01-14)

  • 在配置文件中支持环境变量

3.1.1(2019-01-09)

  • 解决移动设备上多个驱动程序的问题
  • 更改如何获取BrowserStack的测试名称

3.1.0(2018-11-27)

  • 改进生成的报告

3.0.7(2018-10-25)

  • 修补程序-错误的配置分析

3.0.6(2018-10-25)

  • 向webdriver添加日志记录选项

3.0.5(2018-09-10)

  • 在SHI可执行脚本中激活VENV

3.0.4(2018-08-15)

  • 更新可执行的"shi"脚本以在实际目录中工作
  • 添加自述文件和历史记录文件

3.0.3(2018-08-14)

  • 启用"shi"可执行脚本与shi shi to一起使用pip install shishito

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
我可以用C++代码使用java代码吗?   java使用JSR303在派生类中提供更具体的约束   java在这个查找唯一路径数算法中我做错了什么?   java如何为2个不同的服务提供商使用2个不同的SSL证书?   java在Gridview上绘制文本   java使用连接for循环构建字符串名   java StringBuilder拆分无法处理某些文件   java事件关注EditText   Java Web Start“找不到URL的缓存资源”   java程序从命令行运行的速度比在Eclipse中慢   java为什么HttpServletRequest会截断#字符上的url输入?   java自定义折叠工具栏平滑标题大小调整   使用Mockito对安卓 java中调用另一个静态函数的函数进行单元测试   http在java客户机中使用cachecontrol头   java如何使用。是否使用Delimiter从输入文件中排除标点符号和数字?   使用上下文作为参数/参数的java   java更有效地从Jar中提取文件   java为多个JButton提供相同的actionListener