WebUI automation testing framework based on Selenium and unittest.
> 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/defnngj/seldom.git@master
1、查看帮助:
- > seldom -h
- usage: seldom [-h] [-V] [--startproject STARTPROJECT] [-r R]
-
- WebUI automation testing framework based on Selenium.
-
- optional arguments:
- -h, --help show this help message and exit
- -V, --version show version
- --startproject STARTPROJECT
- Specify new project name.
- -r R run test case
2、创建项目:
>seldom --startproject mypro
3、目录结构:
- mypro/
- ├── test_dir/
- │ ├── test_sample.py
- ├── report/
- └── run.py
test_dir/目录实现用例编写。report/ 目录存放生成的测试报告。run.py 文件运行测试用例。3、运行项目:
- > seldom -r run.py
- Python 3.7.1
-
- _ _
- | | | |
- ___ ___ | | __| | ___ _ __ ___
- / __| / _ \| | / _` | / _ \ | '_ ` _ \
- \__ \| __/| || (_| || (_) || | | | | |
- |___/ \___||_| \__,_| \___/ |_| |_| |_|
- -----------------------------------------
- @itest.info
- generated html file: file:///D:\mypro\reports\2019_11_12_22_28_53_result.html
- .1
4、查看报告
你可以到 mypro\reports\ 目录查看测试报告。
请查看 demo/test_sample.py 文件
- import seldom
-
-
- class YouTest(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("test_sample.py")
-
说明:
seldom.TestCase。test 开头。assertTitle、assertUrl 和 assertText等断言方法。- import seldom
-
- # ...
-
- if __name__ == '__main__':
-
- seldom.main(path="./",
- browser="chrome",
- title="百度测试用例",
- description="测试环境:chrome",
- debug=False,
- rerun=0,
- save_last_run=False
- )
说明:
Chrome。False。0。False。- import seldom
-
- seldom.main(path="./") # 当前目录下的所有测试文件
- seldom.main(path="./test_dir/") # 指定目录下的所有测试文件
- seldom.main(path="./test_dir/test_sample.py") # 指定目录下的测试文件
- seldom.main(path="test_sample.py") # 指定当前目录下的测试文件
说明:
test 开头。__init__.py 文件。如果你想指定测试用例在不同的浏览器中运行,非常简单,只需要在seldom.main()方法中通过browser 参数设置。
- import seldom
-
- if __name__ == '__main__':
- seldom.main(browser="chrome") # chrome浏览器,默认值
- seldom.main(browser="firefox") # firefox浏览器
- seldom.main(browser="ie") # IE浏览器
- seldom.main(browser="opera") # opera浏览器
- seldom.main(browser="edge") # edge浏览器
- seldom.main(browser="chrome_headless") # chrome浏览器headless模式
- seldom.main(browser="firefox_headless") # Firefox浏览器headless模式
-
不同浏览器驱动下载地址:
geckodriver(Firefox):Releases · mozilla/geckodriver · GitHub
Chromedriver(Chrome):https://sites.google.com/a/chromium.org/chromedriver/home
IEDriverServer(IE):http://selenium-release.storage.googleapis.com/index.html
operadriver(Opera):Releases · operasoftware/operachromiumdriver · GitHub
MicrosoftWebDriver(Edge):Microsoft Edge WebDriver - Microsoft Edge Developer
==========================================================
- class="bg s_ipt_wr quickdelete-wrap">
- <input id="kw" class="s_ipt" name="wd">
定位方式:.
- self.type(id_="kw", text="seldom")
- self.type(name="wd", text="seldom")
- self.type(class_name="s_ipt", text="seldom")
- self.type(tag="input", text="seldom")
- self.type(link_text="hao123", text="seldom")
- self.type(partial_link_text="hao", text="seldom")
- self.type(xpath="//input[@id='kw']", text="seldom")
- self.type(css="#kw", text="seldom")
-
seldom 支持参数化测试用例,集成了parameterized。
-
- import seldom
- from seldom import ddt
-
- # ...
-
- class BaiduTest(seldom.TestCase):
-
- @ddt.data([
- (1, 'seldom'),
- (2, 'selenium'),
- (3, 'unittest'),
- ])
- def test_baidu(self, name, keyword):
- """
- used parameterized test
- :param name: case name
- :param keyword: search keyword
- """
- self.open("https://www.baidu.com")
- self.type(id_="kw", text=keyword)
- self.click(css="#su")
- self.assertTitle(search_key+"_百度搜索")
-
seldom 支持Page objects设计模式,可以配合poium 使用。
- import seldom
- from poium import Page, PageElement
-
-
- class BaiduPage(Page):
- """baidu page"""
- search_input = PageElement(id_="kw")
- search_button = PageElement(id_="su")
-
-
- class BaiduTest(seldom.TestCase):
- """Baidu serach test case"""
-
- def test_case(self):
- """
- A simple test
- """
- page = BaiduPage(self.driver)
- page.get("https://www.baidu.com")
- page.search_input = "seldom"
- page.search_button.click()
- self.assertTitle("seldom_百度搜索")
-
-
- if __name__ == '__main__':
- seldom.main("test_po_demo.py")
-
-
poium提供了更多好用的功能,使Page层的创建更加简单。
最后感谢每一个认真阅读我文章的人,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:

这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你!
