Splinter是一个使用Python开发的开源Web应用测试工具。它可以帮你实现自动浏览站点和与其进行交互。
简介
Splinter(至2016年12月,最新版本为0.7.5)。
Splinter对已有的自动化工具(如:Selenium、PhantomJS和zope.testbrowser)进行抽象,形成一个全新的上层应用API,它使为Web应用编写自动化测试脚本变的更容易。
依赖包
Splinter0.7.2依赖以下包:
Selenium(版本>=2.44.0)
Django(版本>=1.5.8,<1.7)
Flask(版本>=0.10)
lxml(版本>=2.3.6)
zope.testbrowser(版本>=4.0.4)
cssselect
代码示例
使用示例
1234567891011121314from splinter import Browserwith Browser() as browser: # Visit URL url = "搜索引擎" browser.visit(url) browser.fill('q', 'splinter - python acceptance testing for web applications') # Find and click the 'search' button button = browser.find_by_name('btnG') # Interact with elements button.click() if browser.is_text_present('splinter.readthedocs.org'): print "Yes, the official website was found!" else: print "No, it wasn't found... We need to improve our SEO techniques"
与Selenium的比较
使用Splinter填充一个form的字段如下:
1browser.fill('username', 'janedoe')
而使用Selenium需要:
12elem = browser.find_element.by_name('username')elem.send_keys('janedoe')