阅读 190

seldom - 基于unittest 的 Web UI/HTTP自动化测试框架

一.项目地址:https://github.com/SeldomQA/seldom

 

二.特点:

  • 提供更加简单API编写自动化测试
  • 提供脚手架,快速生成自动化测试项目
  • 全局启动和关闭浏览器,减少浏览器的启动次数
  • 提供支持多种数据文件参数化
  • 支持用例失败/错误重跑
  • 支持生成HTML/XML测试报告
  • 支持HTTP接口测试 (v 2.0)

 

三.安装:

  1.  pip install seldom

  2. 或者:pip install -U git+https://github.com/SeldomQA/seldom.git@master

 

四.快速开始:

  1.查看帮助:    

    • > seldom -h

      usage: seldom [-h] [-v] [-project PROJECT] [-r R] [-m M] [-install INSTALL]

      WebUI automation testing framework based on Selenium.

      optional arguments:

      -h, --help show this help message and exit

      -v, --version show version

      -project PROJECT Create an Seldom automation test project.

      -r R run test case

      -m M run tests modules, classes or even individual test methods

      from the command line

      -install INSTALL Install the browser driver, For example, ‘chrome‘,

      ‘firefox‘.

  

  2.创建项目:

    > seldom -project mypro

    目录结构如下:

      mypro/
      ├── test_dir/
      │ ├── test_sample.py
      ├── test_data/
      │ ├── data.json
      ├── reports/
      └── run.py  

    •  test_dir/ 测试用例目录。
    •  test_data/ 测试数据文件目录。
    •  reports/ 测试报告目录。
    •  run.py 运行测试用例主文件。

 

   3.运行项目:

      > python3 run.py

 

   4.查看报告:

    • 可以到 mypro\reports\ 目录查看测试报告

 

五.Demo示例:

  1.简单的实例 demo/test_dir/test_first_demo.py:   

    import seldom


    class BaiduTest(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()

 

  说明:

    • 创建测试类必须继承 seldom.TestCase
    • 测试用例文件命名必须以 test 开头。
    • seldom的封装了assertTitleassertUrl 和 assertText等断言方法。

 

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

 

    说明:   

    import seldom

    seldom.main() # 默认运行当前测试文件
    seldom.main(path="./") # 当前目录下的所有测试文件
    seldom.main(path="./test_dir/") # 指定目录下的所有测试文件
    seldom.main(path="./test_dir/test_sample.py") # 指定目录下的测试文件

 

原文:https://www.cnblogs.com/xiao-bai-long/p/15206871.html

文章分类
代码人生
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐