1. pip install seldom
2. 或者:pip install -U git+https://github.com/SeldomQA/seldom.git@master
1.查看帮助:
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/
│ ├── test_sample.py
├── test_data/
│ ├── data.json
├── reports/
└── run.py
test_dir/
测试用例目录。 test_data/
测试数据文件目录。 reports/
测试报告目录。 run.py
运行测试用例主文件。
3.运行项目:
> python3 run.py
4.查看报告:
mypro\reports\
目录查看测试报告
1.简单的实例 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
开头。assertTitle
、assertUrl
和 assertText
等断言方法。
2.HTTP 测试,seldom 2.0 支持HTTP测试:
import seldom
class TestRequest(seldom.TestCase):
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.main(base_url="http://httpbin.org")
说明:
import seldom
seldom.main() # 默认运行当前测试文件
seldom.main(path="./") # 当前目录下的所有测试文件
seldom.main(path="./test_dir/") # 指定目录下的所有测试文件
seldom.main(path="./test_dir/test_sample.py") # 指定目录下的测试文件
seldom - 基于unittest 的 Web UI/HTTP自动化测试框架
原文:https://www.cnblogs.com/xiao-bai-long/p/15206871.html