简单Web UI 自动化测试框架 seldom

WebUI automation testing framework based on Selenium and unittest.

基于 selenium 和 unittest 的 Web UI自动化测试框架。

特点

  • 提供更加简单API编写自动化测试。
  • 提供脚手架,快速生成自动化测试项目。
  • 自动生成HTML测试报告生成。
  • 自带断言方法,断言title、URL 和 text。
  • 支持用例参数化。
  • 支持用例失败重跑。
  • 用例失败/错误截图。
安装
> 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
Quick Start

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\ 目录查看测试报告。

API Documents

simple demo

请查看 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 开头。
  • seldom的封装了assertTitleassertUrl 和 assertText等断言方法。
main() 方法
import seldom

# ...

if __name__ == '__main__':
    
    seldom.main(path="./",
              browser="chrome",
              title="百度测试用例", 
              description="测试环境:chrome", 
              debug=False,
              rerun=0,
              save_last_run=False
    )

说明:

  • path : 指定测试目录或文件。
  • browser: 指定测试浏览器,默认Chrome
  • title : 指定测试报告标题。
  • description : 指定测试报告描述。
  • debug : debug模式,设置为True不生成测试HTML测试,默认为False
  • rerun : 设置失败重新运行次数,默认为 0
  • save_last_run : 设置只保存最后一次的结果,默认为False
Run the test
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

==========================================================

元素定位
<form id="form" class="fm" action="/s" name="f">
    <span class="bg s_ipt_wr quickdelete-wrap">
        <input id="kw" class="s_ipt" name="wd">


![img](https://img-blog.csdnimg.cn/img_convert/d95a8a985a2829c9272a35416235c26a.png)
![img](https://img-blog.csdnimg.cn/img_convert/ea1f7d6073a8ced37ca68d4d8f7293d5.png)

**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

 name="wd">


[外链图片转存中...(img-1HcuVO1g-1719275531068)]
[外链图片转存中...(img-sQl5KyA5-1719275531069)]

**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值