All Projects → stingbo → pystest

stingbo / pystest

Licence: MIT license
WEB UI自动化测试框架,selenium结合python,测试人员不需要会代码,只需要写配置即可实现,并且方便懂代码的测试人员扩展

Programming Languages

HTML
75241 projects
python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to pystest

Mobilenium
Mobilenium allows you to use Selenium and have access to status codes and HTTP headers, without the need for manual labor.
Stars: ✭ 22 (-8.33%)
Mutual labels:  webdriver, selenium, browsermob-proxy
Pytest Selenium
Plugin for running Selenium with pytest
Stars: ✭ 246 (+925%)
Mutual labels:  webdriver, selenium
Selenoid Ui
Graphical user interface for Selenoid project
Stars: ✭ 237 (+887.5%)
Mutual labels:  webdriver, selenium
phoenix.webui.framework
基于WebDriver的WebUI自动化测试框架
Stars: ✭ 118 (+391.67%)
Mutual labels:  webdriver, selenium
Steward
PHP libraries that makes Selenium WebDriver + PHPUnit functional testing easy and robust
Stars: ✭ 215 (+795.83%)
Mutual labels:  webdriver, selenium
Selenium Python Helium
Selenium-python but lighter: Helium is the best Python library for web automation.
Stars: ✭ 2,732 (+11283.33%)
Mutual labels:  webdriver, selenium
google-meet-bot
Bot for scheduling and entering google meet sessions automatically
Stars: ✭ 33 (+37.5%)
Mutual labels:  webdriver, selenium
Python Scripts
Collection of Various Python Script's.💻
Stars: ✭ 195 (+712.5%)
Mutual labels:  webdriver, selenium
spydriver
🕵️ Lightweight utility to intercept WebDriver and WebElement method calls.
Stars: ✭ 24 (+0%)
Mutual labels:  webdriver, selenium
SeleniumTDD
A Selenium TDD framework that incorporates key features of Selenium and TestNG which can be used to create web-based automation scripts.
Stars: ✭ 23 (-4.17%)
Mutual labels:  webdriver, selenium
nightwatch101
使用 Nightwatch 實現 End-to-End Testing ★
Stars: ✭ 42 (+75%)
Mutual labels:  webdriver, selenium
arquillian-graphene
Robust Functional Tests leveraging WebDriver with flavour of neat AJAX-ready API
Stars: ✭ 91 (+279.17%)
Mutual labels:  webdriver, selenium
Splinter
splinter - python test framework for web applications
Stars: ✭ 2,476 (+10216.67%)
Mutual labels:  webdriver, selenium
Cdp4j
cdp4j - Chrome DevTools Protocol for Java
Stars: ✭ 232 (+866.67%)
Mutual labels:  webdriver, selenium
Panther
A browser testing and web crawling library for PHP and Symfony
Stars: ✭ 2,480 (+10233.33%)
Mutual labels:  webdriver, selenium
Selion
Enabling Test Automation in Java
Stars: ✭ 252 (+950%)
Mutual labels:  webdriver, selenium
Seleniumbase
A Python framework that inspires developers to become better test automation engineers. 🧠💡
Stars: ✭ 2,520 (+10400%)
Mutual labels:  webdriver, selenium
Thirtyfour
Selenium WebDriver client for Rust, for automated testing of websites
Stars: ✭ 191 (+695.83%)
Mutual labels:  webdriver, selenium
basic-selenium-project
an example selenium test project
Stars: ✭ 55 (+129.17%)
Mutual labels:  webdriver, selenium
selenium-openapi
The missing Selenium OpenAPI spec
Stars: ✭ 25 (+4.17%)
Mutual labels:  webdriver, selenium

使用Python Selenium 进行自动化测试

  • 支持在PC、H5上运行,代理获取接口数据,无头模式,生成报告(含截图),发送邮件等

快速开始

  • 复制并修改全局配置,cp config.example.yaml config.yaml,此文件为全局配置,config目录下文件可覆盖此配置

  • 使用:python test.py filename,filename 为项目 config 目录下的文件名,如python3 test.py default,没有输入文件名, 则默认使用default.yaml

  • 测试用例采用YAML通用格式编写,详见YAML示例

  • 执行已有用例:python3 test.py default,test1,打开百度并搜索 "stingbo pystest",然后跳转到github目录,最后打开指定项目

其它命令

  • 查看 config 目录下所有用例:python3 test.py ls

  • 同时执行多个测试用例:python3 test.py test1,test2,test3

  • 使用配置文件执行测试用例:python3 test.py -f /your/path/test.txt,文件内容为:

    test1,test2,test3
    
  • 执行 config 目录下所有的测试用例:python3 test.py all_test

依赖

使用说明

  • 框架运行逻辑:

    1. 获取配置,合并配置项,启动浏览器
    1. wait_disappear 是否配置等待消失
    1. iframe 是否配置切换iframe
    1. wait 是否配置等待加载
    1. listener 是否配置监听,配置则开启监听
    1. 根据 type,content,index 查找元素
    1. javascript 是否配置,是则执行 javascript
    1. 根据 action 执行动作
  • 配置文件分为以下内容,格式说明如下:

    1. DEBUG: 布尔,True/False,是否开启调试模式,True-不生成生成报告,方便调试
      IMAGE: 布尔,True/False,是否截图,DEBUG为False且IMAGE设置为True时截图

    2. MAIL: 邮箱配置,配置正确会发送测试用例执行报告

    3. BROWSER,对浏览器层的设置

      type: 字符串,使用浏览器类型,目前支持 Chrome/Firefox

      bmp_path: 字符串,browsermob_proxy 地址,代理使用,获取 api 请求使用

      proxy: 布尔,True/False,是否开启代理

      H5: 布尔,True/False,是否使用 h5 进行测试打开浏览器

      device_name: 字符串,h5 模式下模拟的设备名称,目前只有在Chrome下生效,Firefox实现的策略是修改user_agent并设置浏览器界面大小

      headless: 布尔,True/False,是否开启无头模式,无界面测试,方便集成到服务器自动化部署

    4. WEBSITE,启动页面的设置

      url: 字符串,启动页地址,目前只有这一个配置可用

    5. MENU,测试用例详情

      key: 字符串,菜单路径

      name: 字符串,菜单名称/功能名称,方便使用者查看配置使用

      type: 字符串,寻找元素的方式,与webdriver提供的一致

      content: 字符串,上述type对应寻找元素所使用的内容,且一次能够找到,有的路径通过一次找不到(指通用规则,不是绝对路径),则使用contents,配置为none则不会运行当前配置第 7 步查找元素后续流程,但会继续执行其它配置

      contents: 数组,通过多次寻找元素所使用的内容

      index: 整数,所找元素有可能是多个,使用index固定某一个,-1代表默认,-2代表所有,大于等于0,代表list下标

      opertaion: 数组,action之前所要做的操作,数组类型,格式与上述一致

      action: 字符串,要做的动作
      1. none: 配置为none,不执行任务操作,如果配置了javascript选项,则会对元素执行javascript,因为action是最后才会执行
      2. open: 打开菜单,类似点击,但是可以增加一个open配置项,里面配置判断标识,目前实现了class判断,如果有此class,则不会点击,目的是防止某个菜单如果打开了,再点击则会关闭
      3. click: 点击元素
      4. moveToClick: 移动到目标元素并点击元素
      5. sendKeys: 向能输入的地方填写某个值,详细说明见下方value
      5. modifyKeys: 同sendKeys,区别在于会先清空,详细说明见下方value
      6. upload: 上传,value为上传的文件地址

      value: 字符串,如果action是sendKeys(输入)/modifyKeys(修改),则需要value,value可以使用自定义方法,如pkgpath:utils.util.Util:randstr:6(from utils.util import Util && Util.randstr(6)),其它自定义方法见utils/util

      javascript: 字符串,javascript代码,如:"arguments[0].scrollIntoView();",目前支持简单javascript代码运行,复杂的需要自己修改,如果当前配置项获取是多个元素,则都会执行此javascript

      listener: 数组,所需要监听的api url与返回的code,使用listener必须安装BrowserMob Proxy,并配置正确应用路径

      iframe: 字符串,iframe的id或者name,配置后会运行切换到对应iframe层操作,如果配置为空,则会保持在当前iframe层或者说时不做切换操作,如果没有配置,则会回到最外层

      wait: 对象,等待加载的元素,含有type与content(含义同上),比如等待某元素出现

      wait_disappear: 对象,等待消失的元素,含有type与content(含义同上),比如等待遮罩层的消失

      wait_time: 数字,指定某个动作固定等待的时间,单位秒

    6. TEST,数组,指定具体执行的测试用例,如果testa2下还有submenu,则会自动获取并执行,多个文件的TEST配置 会合并执行,执行顺序是输入测试用例时的名称顺序

      TEST:
          - login
          - testa.testa1.testa2
          - testb.testb1.testb2
          - testc.testc1

YAML示例

DEBUG: True/False #是否开启调试模式,True-不生成生成报告,方便调试
IMAGE: True/False #是否截图,DEBUG为False且IMAGE设置为True时截图

MAIL:
    SEND: True/False
    # 邮箱服务端配置
    SMTP:
        username: [email protected]
        password: xxxxxxxxxx
        host: smtp.163.com
        port: 25
    # 收件人列表
    receiver:
        - [email protected]
        - [email protected]

BROWSER:
    #浏览器类型
    type: Chrome/Firefox
    #bmp程序路径
    bmp_path: your/browsermob-proxy/path
    #是否开启代理,开启后,配置listener的操作,会记录请求日志到logs目录下
    proxy: True/False
    #H5
    H5: True/False
    #模拟的设备名称,目前只有在Chrome下生效,Firefox实现的策略是修改user_agent并设置浏览器界面大小
    device_name: iPhone 7
    #是否开启无头模式
    headless: True/False

WEBSITE:
    #启动页地址
    url: http://www.your_website_url.com

MENU:
    login:
        key: login
        name: 登录
        type: xpath
        content: //button[@class='btn btn-primary' and text()='登录']
        index: -1
        action: click
        listener:
            -
                url: login/url
                code: 0
        operation:
            -
                name: 用户名
                type: tag name
                content: input
                value: xxxxx
                index: 2
                action: sendKeys
            -
                name: 密码
                type: tag name
                content: input
                value: xxxxx
                index: 3
                action: sendKeys

总结

  • 使用 contents 多次获取元素时,在上一次范围内获取元素,使用 .//(点+双斜线)

  • 使用 class 匹配时,如果 class 里有空格,配置 xpath 时也需要含有,或者使用 contains

  • 项目里 pre-commit.sample 文件为 git hook,cp pre-commit.sample .git/hooks/pre-commit, 依赖yapfpyflakes,用于 python 代码语法与格式检测

  • 使用示例基本都能在 config 目录下里的文件找到,祝使用愉快,如果有问题或建议,欢迎提 issue

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].