发布时间:2025-12-09 15:56:12 浏览次数:4
pyse 更名为 seldom
WebUI automation testing framework based on Selenium and unittest.
基于 selenium 和 unittest 的 Web UI自动化测试框架。
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@master1、查看帮助:
> seldom -husage: 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 STARTPROJECTSpecify new project name.-r R run test case2、创建项目:
>seldom --startproject mypro3、目录结构:
mypro/├── test_dir/│ ├── test_sample.py├── report/└── run.py3、运行项目:
> seldom -r run.pyPython 3.7.1 _ _| | | |___ ___ | | __| | ___ _ __ ___/ __| / _ \| | / _` | / _ \ | '_ ` _ \\__ \| __/| || (_| || (_) || | | | | ||___/ \___||_| \__,_| \___/ |_| |_| |_|-----------------------------------------@itest.infogenerated html file: file:///D:\mypro\reports\2019_11_12_22_28_53_result.html .14、查看报告
你可以到 mypro\reports\ 目录查看测试报告。
请查看 demo/test_sample.py 文件
import seldomclass 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.main()方法中通过browser 参数设置。
import seldomif __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
==========================================================
定位方式:
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 seldomfrom 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 seldomfrom poium import Page, PageElementclass 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层的创建更加简单。