Web UI automation testing framework

pyse renamed to seldom

WebUI automation testing framework based on Selenium and unittest.

Web UI automation testing framework based on selenium and unittest.

features

  • Provide a simpler API to write automated tests.
  • Provide scaffolding to quickly generate automated test projects.
  • Automatically generate HTML test report generation.
  • Self-contained assertion method, assert title, URL and text.
  • Support for use case parameterization.
  • Support re-run of use case failure.
  • Use case failure/error screenshot.

Install

> 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. View help:

> 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. Create a project:

>seldom --startproject mypro

3. Directory structure:

mypro/
├── test_dir/
│   ├── test_sample.py
├── report/
└── run.py
  • test_dir/The catalog implements use case writing.
  • report/ The directory stores the generated test reports.
  • run.py file to run the test cases.

3. Run the project:

> 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. View the report

You can go to  mypro\reports\ the directory to view the test report.

API Documents

simple demo

Please view  demo/test_sample.py the file

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

illustrate:

  • To create a test class must inherit  seldom.TestCase.
  • Test case file names must  test start with .
  • Seldom encapsulates assertion methods such as assertTitle, assertUrl , and  .assertText

main() method

import seldom

# ...

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

illustrate:

  • path : Specifies the test directory or file.
  • browser: Specify the test browser, the default Chrome.
  • title : Specifies the title of the test report.
  • description : Specifies the test report description.
  • debug : debug mode, set to True to not generate test HTML tests, default to False.
  • rerun : Set the number of reruns on failure, the default is  0.
  • save_last_run : Set to save only the last result, the default is 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")  # 指定当前目录下的测试文件

illustrate:

  • If a directory is specified, the test file must test start with .
  • If you want to run the files in the subdirectory, you must add the files in the subdirectory  __init__.py .

Supported browsers and drivers

If you want to specify that the test cases run in different browsers, it is very simple, you only need to pass  parameter settings in seldom.main()the method .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模式

Different browser driver download addresses:

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

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

element positioning

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

Targeting:

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

Parameterized test cases

seldom supports parameterized test cases and integrates 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+"_百度搜索")

page objects design pattern

seldom supports the Page objects design pattern and can be used with 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 provides more useful functions to make the creation of the Page layer easier.

Guess you like

Origin blog.csdn.net/nhb687095/article/details/129749712