Skip to content

SeldomQA/seldom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

GitHub | Gitee |

PyPI version PyPI - Python Version

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 ่ฟ่กŒ้…็ฝฎๆ–‡ไปถใ€‚

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\ ็›ฎๅฝ•ๆŸฅ็œ‹ๆต‹่ฏ•ๆŠฅๅ‘Šใ€‚

test report

๐Ÿ”ฌ Demo

seldom็ปงๆ‰ฟunittestๅ•ๅ…ƒๆต‹่ฏ•ๆก†ๆžถ๏ผŒๅฎŒๅ…จ้ตๅพชunittest็ผ–ๅ†™็”จไพ‹่ง„่Œƒใ€‚

demo ๆไพ›ไบ†ไธฐๅฏŒๅฎžไพ‹๏ผŒๅธฎไฝ ๅฟซ้€Ÿไบ†่งฃseldom็š„็”จๆณ•ใ€‚

Web UI ๆต‹่ฏ•

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 ๆŒ‡ๅฎš่ฟ่กŒ็š„ๆต่งˆๅ™จใ€‚

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")

่ฏดๆ˜Ž๏ผš

  • seldom.main() ้€š่ฟ‡ base_url ๆŒ‡ๅฎšๆŽฅๅฃ้กน็›ฎๅŸบๆœฌURLๅœฐๅ€ใ€‚

App ๆต‹่ฏ•

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 ๅœฐๅ€ใ€‚

๐Ÿ“– 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

Star History Chart

ๆ„Ÿ่ฐข

ๆ„Ÿ่ฐขไปŽไปฅไธ‹้กน็›ฎไธญๅพ—ๅˆฐๆ€่ทฏๅ’ŒๅธฎๅŠฉใ€‚

่ดก็Œฎ่€…

ไบคๆต

QQ็พค๏ผš948994709

About

Seldom automation testing framework based on unittest

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 16

Languages