웹 UI 자동화 테스트 프레임워크

pyse는 드물게로 이름이 변경되었습니다.

Selenium 및 unittest를 기반으로 하는 WebUI 자동화 테스트 프레임워크입니다.

Selenium 및 unittest를 기반으로 하는 웹 UI 자동화 테스트 프레임워크입니다.

특징

  • 자동화된 테스트를 작성하기 위한 더 간단한 API를 제공합니다.
  • 자동 테스트 프로젝트를 신속하게 생성할 수 있도록 스캐폴딩을 제공합니다.
  • HTML 테스트 보고서 생성을 자동으로 생성합니다.
  • 자체 포함된 어설션 방법, 어설션 제목, URL 및 텍스트.
  • 사용 사례 매개변수화 지원.
  • 사용 사례 실패의 재실행을 지원합니다.
  • 사용 사례 실패/오류 스크린샷.

설치하다

> pip install seldom

최신 버전을 유지하려면 github 저장소 URL을 사용하여 설치할 수 있습니다.

> pip install -U git+https://github.com/defnngj/seldom.git@master

빠른 시작

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 문서

간단한 데모

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 .
  • assertTitle, assertUrl 및 와  assertText같은 어설션 메서드를 거의 캡슐화하지 않습니다 .

메인() 메소드

import seldom

# ...

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

설명하다:

  • path : 테스트 디렉터리 또는 파일을 지정합니다.
  • 브라우저: 테스트 브라우저를 지정합니다. 기본값은 Chrome.
  • 제목 : 테스트 보고서의 제목을 지정합니다.
  • description : 테스트 보고서 설명을 지정합니다.
  • debug : 디버그 모드, 테스트 HTML 테스트를 생성하지 않으려면 True로 설정, 기본값은 False.
  • rerun : 실패 시 재실행 횟수를 설정합니다. 기본값은 입니다  0.
  • save_last_run : 마지막 결과만 저장하도록 설정, 기본값은 False.

테스트 실행

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): 릴리스 · mozilla/geckodriver · GitHub

크롬드라이버(크롬): https://sites.google.com/a/chromium.org/chromedriver/home

IEDriverServer(IE): http://selenium-release.storage.googleapis.com/index.html

operadriver(Opera): 릴리스 · operasoftware/operachromiumdriver · GitHub

MicrosoftWebDriver(Edge): Microsoft Edge WebDriver - Microsoft Edge 개발자

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

요소 위치 지정

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

타겟팅:

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

매개변수화된 테스트 케이스

매개변수화된 테스트 사례를 거의 지원하지 않으며 매개 변수화된 .


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 객체 디자인 패턴을 거의 지원하지 않으며 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은 페이지 레이어를 쉽게 생성할 수 있도록 보다 유용한 기능을 제공합니다.

추천

출처blog.csdn.net/nhb687095/article/details/129749712