8000 GitHub - xinqi192010/seldom: WebUI automation testing framework based on Selenium
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

xinqi192010/seldom

 
 

Repository files navigation

PyPI version PyPI - Python Version

WebUI/HTTP automation testing framework based on Selenium and unittest.

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

特点

  • 提供更加简单API编写自动化测试。
  • 提供脚手架,快速生成自动化测试项目。
  • 全局启动和关闭浏览器,减少浏览器的启动次数。
  • 支持用例参数化。
  • 支持用例失败/错误重跑。
  • 定制化HTML测试报告,用例失败/错误自动截图。
  • 支持XML测试报告
  • 支持HTTP接口测试 (v 2.0)🔥🔥

安装

> pip install seldom

If you want to keep up with the latest version, you can install with github repository url:

> pip install -U git+https://github.com/SeldomQA/seldom.git@master

Quick Start

1、查看帮助:

> seldom -h
usage: seldom [-h] [-v] [-project PROJECT] [-r R] [-m M] [-install INSTALL]

WebUI automation testing framework based on Selenium.

optional arguments:
  -h, --help        show this help message and exit
  -v, --version     show version
  -project PROJECT  Create an Seldom automation test project.
  -r R              run test case
  -m M              run tests modules, classes or even individual test methods
                    from the command line
  -install INSTALL  Install the browser driver, For example, 'chrome',
                    'firefox'.

2、创建项目:

> seldom -project mypro

目录结构如下:

mypro/
├── test_dir/
│   ├── data.json
│   ├── test_sample.py
├── reports/
└── run.py
  • test_dir/ 目录实现用例编写。
  • reports/ 目录存放生成的测试报告。
  • run.py 文件运行测试用例。

3、运行项目:

> python3 run.py
2020-05-16 11:34:36,014 INFO
            _      _
           | |    | |
 ___   ___ | |  __| |  ___   _ __ ___
/ __| / _ \| | / _` | / _ \ | '_ ` _ \
\__ \|  __/| || (_| || (_) || | | | | |
|___/ \___||_| \__,_| \___/ |_| |_| |_|
-----------------------------------------
                             @itest.info

2020-05-16 11:34:38,798 INFO ✅ Find element: id=kw
2020-05-16 11:34:38,813 INFO 🖋 input 'seldom'.
2020-05-16 11:34:38,991 INFO ✅ Find element: css selector=#su
2020-05-16 11:34:39,004 INFO 🖱 click.
2020-05-16 11:34:40,091 INFO 👀 assertIn title: seldom_百度搜索.
2020-05-16 11:34:40,092 INFO generated html file: file:////Users/tech/mypro/reports/2020_05_16_11_34_36_result.html
.1%

4、查看报告

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

test report

Documents

simple demo

demo 提供了丰富实例,帮你快速了解seldom的用法。

简单的实例 demo/test_dir/test_first_demo.py

import seldom


class BaiduTest(seldom.TestCase):

    def test_case(self):
        """a simple test case """
        self.open("https://www.baidu.com")
        self.type(id_="kw", text="seldom")
        self.click(css="#su")
        self.assertTitle("seldom_百度搜索")


if __name__ == '__main__':
    seldom.main()

说明:

  • 创建测试类必须继承 seldom.TestCase
  • 测试用例文件命名必须以 test 开头。
  • seldom的封装了assertTitleassertUrlassertText等断言方法。

Run the test

import seldom

seldom.main()  # 默认运行当前测试文件
seldom.main(path="./")  # 当前目录下的所有测试文件
seldom.main(path="./test_dir/")  # 指定目录下的所有测试文件
seldom.main(path="./test_dir/test_sample.py")  # 指定目录下的测试文件

说明:

  • 如果指定的目录,测试文件必须以test 开头。
  • 如果要运行子目录下的文件,必须在子目录下加 __init__.py 文件。

HTTP 测试

seldom 2.0 支持HTTP测试

import seldom


class TestRequest(seldom.HttpRequest):

    def test_put_method(self):
        self.put('/put', data={'key': 'value'})
        self.assertStatusCode(200)

    def test_post_method(self):
        self.post('/post', data={'key':'value'})
        self.assertStatusCode(200)

    def test_get_method(self):
        payload = {'key1': 'value1', 'key2': 'value2'}
        self.get("/get", params=payload)
        self.assertStatusCode(200)

    def test_delete_method(self):
        self.delete('/delete')
        self.assertStatusCode(200)


if __name__ == '__main__':
    seldom.run(base_url="http://httpbin.org")

seldom 文档

请阅读下面的文档,帮助你快速学会Seldom。

项目实例

如果你想快速的使用seldom开发自动化测试,请参考这个项目。

https://github.com/BarryYBL/UIAutoDemo

感谢

感谢从以下项目中得到思路和帮助。

交流

QQ群:948994709

About

WebUI automation testing framework based on Selenium

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 81.9%
  • HTML 18.1%
0