Simple Web UI automated testing framework 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
  • The test_dir/ directory implements use case writing.
  • The report/ directory stores the generated test reports.
  • The run.py file runs 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 the mypro\reports\ directory to view test reports.

API Documents

simple demo

Please check the demo/test_sample.py 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")

Description:

  • Create a test class must inherit seldom.TestCase.
  • The name of the test case file must start with test.
  • seldom encapsulates assertion methods such as assertTitle, assertUrl and assertText.

main() method

import seldom

#...

if __name__ == '__main__':
    
    seldom.main(path="./",
              browser="chrome",
              title="Baidu test case",
              description="Test environment: chrome",
              debug=False,
              rerun=0,
              save_last_run=False
    )

illustrate:

  • path : Specifies the test directory or file.
  • browser: Specify the test browser, the default is 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="./") # All test files in the current directory
seldom.main(path="./test_dir/") # All test files in the specified directory
seldom.main(path="./test_dir/test_sample.py") # test file in the specified directory
seldom.main(path="test_sample.py") # Specify the test file in the current directory

illustrate:

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

Supported browsers and drivers

If you want to specify the test cases to run in different browsers, it is very simple, just need to set the browser parameter in the seldom.main() method.

import seldom

if __name__ == '__main__':
    seldom.main(browser="chrome") # chrome browser, default value
    seldom.main(browser="firefox") # firefox browser
    seldom.main(browser="ie") # IE browser
    seldom.main(browser="opera") # opera browser
    seldom.main(browser="edge") # edge browser
    seldom.main(browser="chrome_headless") # chrome browser headless mode
    seldom.main(browser="firefox_headless") # Firefox browser headless mode

Download address of different browser drivers:

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 case

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 + "_Baidu Search")

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_ Baidu search")


if __name__ == '__main__':
    seldom.main("test_po_demo.py")

poium provides more useful functions to make the creation of the Page layer easier.

The following is the supporting information. For friends who do [software testing], it should be the most comprehensive and complete preparation warehouse. This warehouse also accompanied me through the most difficult journey. I hope it can help you too!

How to get it for free:

Join my software testing exchange group: 110685036 to get it for free~ (Academic exchanges with fellow leaders, and there will be live broadcasts to share technical knowledge points every night)

Software testing interview applet

The software test question bank maxed out by millions of people! ! ! Who is who knows! ! ! The most comprehensive quiz mini program on the whole network, you can use your mobile phone to do the quizzes, on the subway or on the bus, roll it up!

The following interview question sections are covered:

1. Basic theory of software testing, 2. web, app, interface function testing, 3. network, 4. database, 5. linux

6. web, app, interface automation, 7. performance testing, 8. programming basics, 9. hr interview questions, 10. open test questions, 11. security testing, 12. computer basics

How to get it: