Skip to main content

pypise

WebUI automation testing framework based on Selenium and unittest.

介绍:

pypise基于selenium(webdriver)进行了简单的二次封装,比selenium所提供的方法操作更简洁。

特点:

  • 默认使用CSS定位,同时支持多种定位方法(id\name\class\link_text\xpath\css)。
  • 本框架只是对selenium(webdriver)原生方法进行了简单的封装,精简为大约30个方法,这些方法基本能够胜任于我们的web自动化测试。
  • 以测试类为单位,自动打开和关闭浏览器,减少浏览器的打开/关闭次数,节省时间。
  • 自动生成/report/目录,以及HTML测试报告生成。
  • 自带断言方法,断言title、URL 和 text。

安装说明:

> python setup.py install

例子:

请查看demo/test_case.py目录

import pypise

class BaiduTest(pypise.TestCase):

    def test_baidu(self):
        ''' baidu search key : pypise '''
        self.open("https://www.baidu.com/")
        self.type("#kw", "pypise")
        self.click("#su")
        self.assertTitle("pypise_百度搜索")

if __name__ == '__main__':
    runner = pypise.TestRunner()
    runner.run()

运行测试用例说明:

  • 测试用例文件命名必须以“test”开头。
  • 默认情况下使用 Chrome 浏览器运行测试用例。
  • 元素定位方式默认使用 CSS 语法 #kw, 也可以显示的使用 css=>#kw。
  • pypise的TestCase类中默认封装了assertTitle、assertUrl 和 assertText等断言。
  • TestRunner() 默认匹配当前目录下"test*.py"的文件并执行。当然也可以指定测试目录,例如: TestRunner("path/you/project/test_case/") # 注意用斜线"/"表示路径。
  • 执行run()方法运行测试用例并生成测试报告,在调试测试用例过程中可以使用 debug() 方法将不会生成HTML测试报告。

支持的浏览器及驱动:

指定运行的浏览器:

import pypise

class YouTest(pypise.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.driver = Pypise("chrome")

    def test_case(self):
        #……

支持的浏览器:

cls.driver = Pypise("firefox")   #Firefox
cls.driver = Pypise("chrome")    # Chrome
cls.driver = Pypise("ie")        #IE
cls.driver = Pypise("opera")     #Opera
cls.driver = Pypise("edge")      #Edge
cls.driver = Pypise("chrome_headless")  #Chrome headless模式

浏览器驱动下载地址:

geckodriver(Firefox):https://github.com/mozilla/geckodriver/releases

Chromedriver(Chrome):https://sites.google.com/a/chromium.org/chromedriver/home

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

operadriver(Opera):https://github.com/operasoftware/operachromiumdriver/releases

MicrosoftWebDriver(Edge):https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver

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

元素定位:

pypise支持多种定位方式,id、name、class、link text、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" autocomplete="off" maxlength="255" value="" name="wd">

定位方式(推荐使用 CSS):

# 默认支持CSS语法
driver.type(".s_ipt","pypise")     #css
driver.type("#su","pypise")        #css

driver.type("id=>kw", "pypise")  #id

driver.type("class=>s_ipt", "pypise")  #class定位

driver.type("name=>wd", "pypise")  #name

driver.type("xpath=>//*[@class='s_ipt']","pypise")  #xpath
driver.type("xpath=>//*[@id='kw']","pypise")        #xpath

driver.click_text("link_text=>新闻") #link text (点击百度首页上的"新闻"链接)

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

css选择器参考手册: http://www.w3school.com.cn/cssref/css_selectors.asp

测试报告

Release files for pypise 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pypise 0.0.1
File Size Uploaded
pypise-0.0.1.tar.gz 18.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pypise 0.0.1
File Interpreter ABI Platform
pypise-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 37.7 kB

Release files / pypise-0.0.1.tar.gz

Download URL pypise-0.0.1.tar.gz
Size 18.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ec2e15b1f66bd48c2b1982749f363a8406e11054a0454fa51890c72073c447ad
BLAKE2b-256 checksum
How to use checksums
0f8149ce1d1d168aa58d8e13787a11879a02acf46ec8f438db9f2cc74f3a09f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

Release files / pypise-0.0.1-py3-none-any.whl

Download URL pypise-0.0.1-py3-none-any.whl
Size 19.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f252b151f5383d880207918791610f24ae0c1fd63716aa9c4dc908b3b8ff3ea6
BLAKE2b-256 checksum
How to use checksums
4c4acc6e1a2075507f0fd780abd9291cd790d3ab2cf61e58ef2c1e239f1c01c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page