Seldom automation testing framework based on unittest

Seldom is an automation testing framework based on unittest.
seldom ๆฏๅบไบunittest ็่ชๅจๅๆต่ฏๆกๆถใ
Features
โญ web/app/apiๅ จๅ่ฝๆต่ฏๆกๆถ
โญ ๆไพ่ๆๆถๅฟซ้ๅๅปบ่ชๅจๅ้กน็ฎ
โญ ้ๆXTestRunnerๆต่ฏๆฅๅ๏ผ็ฐไปฃ็พ่ง
โญ ๆไพไธฐๅฏ็ๆญ่จ
โญ ๆไพๅผบๅคง็ๆฐๆฎ้ฉฑๅจ
โญ ๅนณๅฐๅๆฏๆ
Install
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
๐ค Quick Start
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่ฟ่ก้ ็ฝฎๆไปถใ
- โ๏ธ ๅจ
PyCharmไธญๅณ้ฎๆง่กใ
- โ๏ธ ้่ฟๅฝไปค่กๅทฅๅ ทๆง่กใ
> seldom -p testdir # ่ฟ่ก testdir ๆต่ฏ็ฎๅฝmypro\reports\/ // / __ / / \/ / / \/
_/ ( ) / / // / // / / / / / / /_/\//\,/\_// // // v3.x.x
@itest.info ...2022-04-30 18:37:36 log.py | INFO | โ Find 1 element: id=sbformq -> 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=sbformq -> 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=sbformq -> 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\20220430183729result.html 2022-04-30 18:37:52 log.py | SUCCESS | generated log file: file:///D:\mypro\reports\seldom_log.log</code></pre>
4ใๆฅ็ๆฅๅ
ไฝ ๅฏไปฅๅฐ
็ฎๅฝๆฅ็ๆต่ฏๆฅๅใseldom.main()
๐ฌ Demo
> seldom็ปงๆฟunittestๅๅ ๆต่ฏๆกๆถ๏ผๅฎๅ จ้ตๅพชunittest็ผๅ็จไพ่ง่ใ
demo ๆไพไบไธฐๅฏๅฎไพ๏ผๅธฎไฝ ๅฟซ้ไบ่งฃseldom็็จๆณใ
Web UI ๆต่ฏ
<pre><code class="lang-python">import seldom from seldom import Steps
class BaiduTest(seldom.TestCase):
def testcaseone(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 testcasetwo(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")</code></pre>
่ฏดๆ๏ผ
้่ฟbrowserๆๅฎ่ฟ่ก็ๆต่งๅจใseldom.main()HTTP ๆต่ฏ
seldom 2.0 ๆฏๆHTTPๆต่ฏ
<pre><code class="lang-python">import seldom
class TestRequest(seldom.TestCase):
def testputmethod(self): self.put('/put', data={'key': 'value'}) self.assertStatusCode(200)
def testpostmethod(self): self.post('/post', data={'key': 'value'}) self.assertStatusCode(200)
def testgetmethod(self): payload = {'key1': 'value1', 'key2': 'value2'} self.get("/get", params=payload) self.assertStatusCode(200)
def testdeletemethod(self): self.delete('/delete') self.assertStatusCode(200)
if name == 'main': seldom.main(base_url="http://httpbin.org")</code></pre>
่ฏดๆ๏ผ
้่ฟbase_urlๆๅฎๆฅๅฃ้กน็ฎๅบๆฌURLๅฐๅใseldom.main()App ๆต่ฏ
seldom 3.0 ๆฏๆAppๆต่ฏ
<pre><code class="lang-python">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 testbingsearch(self): """ test bing App search """ self.sleep(2) self.click(id="com.microsoft.bing:id/sahpheadersearch_box") self.type(id="com.microsoft.bing:id/sapphiresearchheaderinput", 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(appserver="http://127.0.0.1:4723", appinfo=options, debug=True)</code></pre>
่ฏดๆ๏ผ
้่ฟappinfoๆๅฎAppไฟกๆฏ๏ผappserver` ๆๅฎappium server ๅฐๅใ๐ Document
้กน็ฎๅฎไพ
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
ๅพฎไฟก๏ผWeChat๏ผ
็ธๅ ณไนฆ็ฑๆจ่๏ผ ๅบไบ SeldomQA ็ธๅ ณๅผๆบ้กน็ฎ๏ผ่ซๅธ ็ผ่ใๆฌข่ฟๆทปๅ ๅพฎไฟก๏ผไบคๆตๅๅ้ฆ้ฎ้ขใ
Star History
ๆ่ฐข
ๆ่ฐขไปไปฅไธ้กน็ฎไธญๅพๅฐๆ่ทฏๅๅธฎๅฉใ
่ดก็ฎ่
ไบคๆต
QQ็พค๏ผ948994709

