WebUI automation testing framework based on Selenium and unittest.

基于 selenium 和 unittest 的 Web UI自动化测试框架。

特点

  • 默认使用CSS定位,同时支持多种定位方法(id\name\class\link_text\xpath\css)。
  • 基于Selenium二次封装,使用更简单。
  • 提供脚手架,快速生成自动化测试项目。
  • 自动生成/reports/目录,以及HTML测试报告生成。
  • 自带断言方法,断言title、URL 和 text。
  • 支持用例参数化。

安装

> pip install -U git+https://github.com/defnngj/pyse.git@master

pyse命令

1、查看帮助:

> pyse -h usage: pyse [-h] [-V] [--startproject STARTPROJECT] [-r R]  WebUI automation testing framework based on Selenium.  optional arguments:   -h, --help            show this help message and exit   -V, --version         show version   --startproject STARTPROJECT                         Specify new project name.   -r R                  run test case

2、创建项目:

>pyse --startproject mypro  2019-11-07 00:24:57,783 - INFO - Start to create new test project: mypro  2019-11-07 00:24:57,784 - INFO - CWD: D:\  2019-11-07 00:24:57,785 - INFO - created folder: mypro 2019-11-07 00:24:57,786 - INFO - created folder: mypro\test_dir 2019-11-07 00:24:57,787 - INFO - created folder: mypro\reports 2019-11-07 00:24:57,788 - INFO - created file: mypro\test_dir\test_sample.py 2019-11-07 00:24:57,789 - INFO - created file: mypro\run.py

3、运行项目:

> cd mypro\ > pyse -r run.py Python 3.7.1                                                                       ______  __   __  _______  _______                                               |   _  ||  | |  ||  _____||   ____|                                              |  |_| ||  |_|  || |_____ |  |____                                               |   ___||_     _||_____  ||   ____|                                              |  |      |   |   _____| ||  |____                                               |__|      |___|  |_______||_______|                                                                                      generated html file: file:///D:\mypro\reports\2019_11_12_22_28_53_result.html    .1                                                                              

4、查看报告

你可以到 mypro\reports\ 目录查看测试报告。

API Documents

simple demo

请查看 test_sample.py 文件

import pyse  class BaiduTest(pyse.TestCase):      def test_baidu(self):         ''' baidu search key : pyse '''         self.open("upload/201911131115263737.gif"); background-position: 0px 9px; background-repeat: no-repeat; padding: 0px 0px 0px 15px; list-style-type: disc;">创建测试类必须继承 pyse.TestCase
  • 测试用例文件命名必须以 test 开头。
  • 元素定位方式默认使用 CSS 语法 #kw, 也可以显示的使用