Seldom is an automation testing framework based on unittest.
seldom ๆฏๅบไบunittest ็่ชๅจๅๆต่ฏๆกๆถใ
โญ web/app/apiๅ จๅ่ฝๆต่ฏๆกๆถ
โญ ๆไพ่ๆๆถๅฟซ้ๅๅปบ่ชๅจๅ้กน็ฎ
โญ ้ๆXTestRunner
ๆต่ฏๆฅๅ๏ผ็ฐไปฃ็พ่ง
โญ ๆไพไธฐๅฏ็ๆญ่จ
โญ ๆไพๅผบๅคง็ๆฐๆฎ้ฉฑๅจ
โญ ๅนณๅฐๅๆฏๆ
pip install seldom
If you want to keep up with the latest version, you can install with GitHub/Gitee repository url:
> pip install -U git+https://github.com/SeldomQA/seldom.git@master
> pip install -U git+https://gitee.com/fnngj/seldom.git@master
1ใๆฅ็ๅธฎๅฉ๏ผ
seldom --help
Usage: seldom [OPTIONS]
seldom CLI.
โญโ Options โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ --version -v Show version. โ
โ --project-api -api TEXT Create a project of API type. [default: None] โ
โ --project-app -app TEXT Create a project of App type [default: None] โ
โ --project-web -web TEXT Create a project of Web type [default: None] โ
โ --clear-cache -cc Clear all caches of seldom. โ
โ --log-level -ll TEXT Set the log level [TRACE |DEBUG | INFO | SUCCESS | โ
โ WARNING | ERROR]. โ
โ [default: None] โ
โ --mod -m TEXT Run tests modules, classes or even individual test โ
โ methods from the command line. โ
โ [default: None] โ
โ --path -p TEXT Run test case file path. [default: None] โ
โ --env -e TEXT Set the Seldom run environment `Seldom.env`. โ
โ [default: None] โ
โ --browser -b TEXT The browser that runs the Web UI automation tests โ
โ [chrome | edge | firefox | chromium]. Need the --path. โ
โ [default: None] โ
โ --base-url -u TEXT The base-url that runs the HTTP automation tests. Need โ
โ the --path. โ
โ [default: None] โ
โ --debug -d Debug mode. Need the --path/--mod. โ
โ --rerun -rr INTEGER The number of times a use case failed to run again. โ
โ Need the --path. โ
โ [default: 0] โ
โ --report -r TEXT Set the test report for output. Need the --path. โ
โ [default: None] โ
โ --collect -c Collect project test cases. Need the --path. โ
โ --level -l TEXT Parse the level of use cases [data | case]. Need the โ
โ --path. โ
โ [default: data] โ
โ --case-json -j TEXT Test case files. Need the --path. [default: None] โ
โ --har2case -h2c TEXT HAR file converts an seldom test case. [default: None] โ
โ --swagger2case -s2c TEXT Swagger file converts an seldom test case. โ
โ [default: None] โ
โ --api-excel TEXT Run the api test cases in the excel file. โ
โ [default: None] โ
โ --install-completion Install completion for the current shell. โ
โ --show-completion Show completion for the current shell, to copy it or โ
โ customize the installation. โ
โ --help Show this message and exit. โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
2ใๅๅปบ้กน็ฎ๏ผ
> seldom -api myapi # API automation test project.
> seldom -app myapp # or App automation test project.
> seldom -web myweb # or Web automation test project.
็ฎๅฝ็ปๆๅฆไธ๏ผ
myweb/
โโโ test_dir/
โ โโโ __init__.py
โ โโโ test_sample.py
โโโ test_data/
โ โโโ data.json
โโโ reports/
โโโ confrun.py
test_dir/
ๆต่ฏ็จไพ็ฎๅฝใtest_data/
ๆต่ฏๆฐๆฎๆไปถ็ฎๅฝใreports/
ๆต่ฏๆฅๅ็ฎๅฝใconfrun.py
่ฟ่ก้ ็ฝฎๆไปถใ
3ใ่ฟ่ก้กน็ฎ๏ผ
-
โ๏ธ ๅจ
PyCharm
ไธญๅณ้ฎๆง่กใ -
โ๏ธ ้่ฟๅฝไปค่กๅทฅๅ ทๆง่กใ
> seldom -p test_dir # ่ฟ่ก test_dir ๆต่ฏ็ฎๅฝ
__ __
________ / /___/ /___ ____ ____
/ ___/ _ \/ / __ / __ \/ __ ` ___/
(__ ) __/ / /_/ / /_/ / / / / / /
/____/\___/_/\__,_/\____/_/ /_/ /_/ v3.x.x
-----------------------------------------
@itest.info
...
2022-04-30 18:37:36 log.py | INFO | โ
Find 1 element: id=sb_form_q -> input 'seldom'.
2022-04-30 18:37:39 log.py | INFO | ๐ assertIn title: seldom - ๆ็ดข.
.52022-04-30 18:37:39 log.py | INFO | ๐ https://cn.bing.com
2022-04-30 18:37:41 log.py | INFO | โ
Find 1 element: id=sb_form_q -> input 'poium'.
2022-04-30 18:37:42 log.py | INFO | ๐ assertIn title: poium - ๆ็ดข.
.62022-04-30 18:37:42 log.py | INFO | ๐ https://cn.bing.com
2022-04-30 18:37:43 log.py | INFO | โ
Find 1 element: id=sb_form_q -> input 'XTestRunner'.
2022-04-30 18:37:44 log.py | INFO | ๐ assertIn title: XTestRunner - ๆ็ดข.
.72022-04-30 18:37:44 log.py | INFO | ๐ http://www.itest.info
2022-04-30 18:37:52 log.py | INFO | ๐ assertIn url: http://www.itest.info/.
.82022-04-30 18:37:52 log.py | SUCCESS | generated html file: file:///D:\mypro\reports\2022_04_30_18_37_29_result.html
2022-04-30 18:37:52 log.py | SUCCESS | generated log file: file:///D:\mypro\reports\seldom_log.log
4ใๆฅ็ๆฅๅ
ไฝ ๅฏไปฅๅฐ mypro\reports\
็ฎๅฝๆฅ็ๆต่ฏๆฅๅใ
seldom็ปงๆฟunittestๅๅ ๆต่ฏๆกๆถ๏ผๅฎๅ จ้ตๅพชunittest็ผๅ็จไพ่ง่ใ
demo ๆไพไบไธฐๅฏๅฎไพ๏ผๅธฎไฝ ๅฟซ้ไบ่งฃseldom็็จๆณใ
import seldom
from seldom import Steps
class BaiduTest(seldom.TestCase):
def test_case_one(self):
"""a simple test case """
self.open("https://www.baidu.com")
self.type(id_="kw", text="seldom")
self.click(css="#su")
self.assertTitle("seldom_็พๅบฆๆ็ดข")
def test_case_two(self):
"""method chaining """
Steps().open("https://www.baidu.com").find("#kw").type("seldom").find("#su").click()
self.assertTitle("seldom_็พๅบฆๆ็ดข")
if __name__ == '__main__':
seldom.main(browser="chrome")
่ฏดๆ๏ผ
seldom.main()
้่ฟbrowser
ๆๅฎ่ฟ่ก็ๆต่งๅจใ
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")
่ฏดๆ๏ผ
seldom.main()
้่ฟbase_url
ๆๅฎๆฅๅฃ้กน็ฎๅบๆฌURLๅฐๅใ
seldom 3.0 ๆฏๆAppๆต่ฏ
import seldom
from seldom.appium_lab.keyboard import KeyEvent
from seldom.appium_lab.android import UiAutomator2Options
class TestBingApp(seldom.TestCase):
def start(self):
self.ke = KeyEvent(self.driver)
def test_bing_search(self):
"""
test bing App search
"""
self.sleep(2)
self.click(id_="com.microsoft.bing:id/sa_hp_header_search_box")
self.type(id_="com.microsoft.bing:id/sapphire_search_header_input", text="seldomQA")
self.ke.press_key("ENTER")
self.sleep(1)
elem = self.get_elements(xpath='//android.widget.TextView')
self.assertIn("seldom", elem[0].text.lower())
if __name__ == '__main__':
capabilities = {
'deviceName': 'ELS-AN00',
'automationName': 'UiAutomator2',
'platformName': 'Android',
'appPackage': 'com.microsoft.bing',
'appActivity': 'com.microsoft.sapphire.app.main.MainSapphireActivity',
'noReset': True,
}
options = UiAutomator2Options().load_capabilities(capabilities)
seldom.main(app_server="http://127.0.0.1:4723", app_info=options, debug=True)
่ฏดๆ๏ผ
seldom.main()
้่ฟapp_info
ๆๅฎAppไฟกๆฏ๏ผapp_server
ๆๅฎappium server ๅฐๅใ
B็ซๅฎๆ่ง้ข๏ผ
https://www.bilibili.com/video/BV1QHQVYoEHC
ๅบไบseldom็web UI่ชๅจๅ้กน็ฎ๏ผ
https://github.com/SeldomQA/seldom-web-testing
ๅบไบseldom็ๆฅๅฃ่ชๅจๅ้กน็ฎ:
https://github.com/defnngj/seldom-api-testing
็ธๅ ณไนฆ็ฑๆจ่๏ผ ๅบไบ SeldomQA ็ธๅ ณๅผๆบ้กน็ฎ๏ผ่ซๅธ ็ผ่ใ
ๆฌข่ฟๆทปๅ ๅพฎไฟก๏ผไบคๆตๅๅ้ฆ้ฎ้ขใ
ๆ่ฐขไปไปฅไธ้กน็ฎไธญๅพๅฐๆ่ทฏๅๅธฎๅฉใ
QQ็พค๏ผ948994709