셀레늄 및 유닛 테스트를 기반으로 UI를 자동화 테스트 프레임 워크.
셀레늄 및 유닛 테스트를 기반으로 웹 UI 테스트 자동화 프레임 워크.
특징
- 기본 CSS 위치, 여러 위치 방법을 지원하면서 (ID \ 이름 \ 클래스 \ LINK_TEXT \ XPath는 \ CSS).
- 두 번째 패키지를 기반으로 셀레늄, 쉽게 사용하기.
- 신속하게 테스트 자동화 프로젝트를 생성하는 발판을 제공합니다.
- 자동 생성 / 보고서 / 디렉토리 및 HTML 테스트 보고서 생성.
- 자신의 주장, 주장 제목, URL 및 텍스트입니다.
- 예 지원으로 파라미터.
설치
> pip install -U git+https://github.com/defnngj/pyse.git@master
pyse 명령
1, 도움말을 참조하십시오 :
> pyse -h
usage: pyse [-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, 프로젝트를 생성 :
>pyse --startproject mypro
2019-11-07 00:24:57,783 - INFO - Start to create new test project: mypro
2019-11-07 00:24:57,784 - INFO - CWD: D:\
2019-11-07 00:24:57,785 - INFO - created folder: mypro
2019-11-07 00:24:57,786 - INFO - created folder: mypro\test_dir
2019-11-07 00:24:57,787 - INFO - created folder: mypro\reports
2019-11-07 00:24:57,788 - INFO - created file: mypro\test_dir\test_sample.py
2019-11-07 00:24:57,789 - INFO - created file: mypro\run.py
3, 프로젝트를 실행 :
> cd mypro\
> pyse -r run.py
Python 3.7.1
______ __ __ _______ _______
| _ || | | || _____|| ____|
| |_| || |_| || |_____ | |____
| ___||_ _||_____ || ____|
| | | | _____| || |____
|__| |___| |_______||_______|
generated html file: file:///D:\mypro\reports\2019_11_12_22_28_53_result.html
.1
4. 보고서보기
당신은 갈 수 mypro\reports\
시험 보고서를 볼 디렉토리.
API 문서
간단한 데모
참고 항목 test_sample.py
파일을
import pyse
class BaiduTest(pyse.TestCase):
def test_baidu(self):
''' baidu search key : pyse '''
self.open("https://www.baidu.com/")
self.type("#kw", "pyse")
self.click("#su")
self.assertTitle("pyse_百度搜索")
if __name__ == '__main__':
pyse.main("test_sample.py", debug=True)
설명 :
- 테스트 클래스해야 상속을 만듭니다
pyse.TestCase
. - 테스트 케이스 파일 이름을 지정해야합니다
test
시작 부분에. - CSS 구문의 기본 모드를 사용하여 요소의 위치
#kw
, 당신은 또한 디스플레이를 사용할 수 있습니다css=>#kw
. - pyse 캡슐화
assertTitle
,assertUrl
그리고assertText
다른 주장. - 하여
main()
테스트 케이스 메소드를 실행.
API
pyse 제공하는 API
self.accept_alert()
self.clear("css=>#el")
self.click("css=>#el")
self.click_text("新闻")
self.dismiss_alert()
self.double_click("css=>#el")
self.drag_and_drop("css=>#el","css=>#ta")
self.get_alert_text()
self.get_attribute("css=>#el","type")
self.get_display("css=>#el")
self.get_text("css=>#el")
self.get_title()
self.get_url()
self.js("window.scrollTo(200,1000);")
self.max_window()
self.move_to_element("css=>#el")
self.open("https://www.baidu.com")
self.open_new_window("link_text=>注册")
self.close()
self.quit()
self.refresh()
self.right_click("css=>#el")
self.screenshots('/Screenshots/foo.png')
self.select("#nr", '20')
self.select("xpath=>//[@name='NR']", '20')
self.set_window(wide, high)
self.submit("css=>#el")
self.switch_to_frame("css=>#el")
self.switch_to_frame_out()
self.type("css=>#el","selenium")
self.wait(10)
main () 메소드
pyse.main(path="./",
browser="chrome",
title="百度测试用例",
description="测试环境:Firefox",
debug=True
)
설명 :
- 경로 : 테스트 디렉토리를 지정합니다.
- 브라우저 : 지정 시험 브라우저 기본 크롬.
- 제목 : 테스트 프로젝트의 제목을 지정합니다.
- 설명 : 테스트 설명을 지정합니다.
- 디버그 : HTML 테스트 테스트를 생성하지 않고 True로 설정된 디버그 모드.
테스트를 실행
pyse.main(path="./") # 当前目录下的所有测试文件
pyse.main(path="./test_dir/") # 指定目录下的所有测试文件
pyse.main(path="./test_dir/test_sample.py") # 指定目录下的测试文件
pyse.main(path="test_sample.py") # 指定当前目录下的测试文件
설명 :
- 지정된 디렉토리 경우, 테스트 파일이 있어야합니다
test
로 시작합니다. - 당신이 하위 디렉토리에있는 파일을 실행하려면 하위 디렉토리에 추가해야합니다
__init__.py
파일.
지원되는 브라우저 및 드라이브
당신이 다른 브라우저에서 실행할 테스트 케이스를 지정하려는 경우, 그것은 매우 간단에만 필요하다 pyse.main()
메소드 통과 browser
세트.
if __name__ == '__main__':
pyse.main(browser="firefox")
지원되는 브라우저는 "chrome"
다음과 같습니다 : "firefox"
, "ie"
, "opera"
, "edge"
,, "chrome_headless"
과에 이렇게.
다른 브라우저 드라이버 다운로드 주소 :
geckodriver (파이어 폭스) : HTTPS : //github.com/mozilla/geckodriver/releases
Chromedriver (크롬) : HTTPS : //sites.google.com/a/chromium.org/chromedriver/home
IEDriverServer (IE) : HTTP : //selenium-release.storage.googleapis.com/index.html
operadriver (오페라) : HTTPS : //github.com/operasoftware/operachromiumdriver/releases
MicrosoftWebDriver (에지) : HTTPS : //developer.microsoft.com/en-us/microsoft-edge/tools/webdriver
================================================== ========
요소를 위치 지정
pyse 타겟팅, ID, 이름, 클래스, 링크 텍스트, XPath와 CSS의 다양한 지원합니다. 위치 결정 방법과 위치 콘텐츠 통합, 더 간결을 썼다.
<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">
위치 모드 (권장 CSS) :
# 默认支持CSS语法
self.type(".s_ipt","pyse") #css
self.type("#su","pyse") #css
# id
self.type("id=>kw", "pyse") #id
# class name
self.type("class=>s_ipt", "pyse") #class定位
# name
self.type("name=>wd", "pyse") #name
# xpath
self.type("xpath=>//*[@class='s_ipt']","pyse") #xpath
self.type("xpath=>//*[@id='kw']","pyse") #xpath
# link text
self.click_text("新闻") #link text (点击百度首页上的"新闻"链接)
CSS 선택기 참조 설명서 :
http://www.w3school.com.cn/cssref/css_selectors.asp
매개 변수화 된 테스트 케이스
pyse 지지체 파라 메트릭 테스트는 집적 매개 변수화 .
import pyse
from pyse import ddt
class BaiduTest(pyse.TestCase):
@ddt.data([
(1, 'pyse'),
(2, 'selenium'),
(3, 'unittest'),
])
def test_baidu(self, name, keyword):
"""
used parameterized test
:param name: case name
:param search_key: search keyword
"""
self.open("https://www.baidu.com")
self.clear("id=>kw")
self.type("id=>kw", keyword)
self.click("css=>#su")
self.assertTitle(keyword)