mac*_*ost 42 python acceptance-testing functional-testing
Ruby在Selenium之上有一个很棒的抽象层,称为Capybara,您可以使用它进行功能/接受/集成测试.它还有另一个名为Cucumber的库,它更进了一步,让你真正用英语编写测试.
这两个库都是在Selenium之上构建的,可以用来测试任何主要的浏览器,但由于它们的抽象层,使用它们编写测试非常容易(好吧,就像功能测试一样简单).
我的问题是:Python有类似的东西吗?我发现Pythonistas使用各种工具进行功能测试但是......
A)Splinter:不使用Selenium(并且没有IE驱动程序)
-EDIT- 看来Spliter现在确实使用了Selenium(见下面的答案).
B)Alfajor:一年多来没有更新; 看起来死了
C)Selenium(原始):很多人似乎直接使用Selenium,但它似乎是一个抽象层可以使它更容易使用
那么,对于Python来说,有没有人知道类似Capybara的东西,或者更好的类似Cucumber的东西(它不必实际使用Selenium,但它需要支持所有主流浏览器)?
*编辑*
对于那些不熟悉Capybara的人来说,它基本上只是添加了一个API,因此您可以执行以下操作来代替正常的Selenium API:
When /I sign in/ do
within("#session") do
fill_in 'Login', :with => 'user@example.com'
fill_in 'Password', :with => 'password'
end
click_link 'Sign in'
end
Run Code Online (Sandbox Code Playgroud)
它被Cucumber使用,让你进一步抽象(几乎到英文):
Scenario Outline: Add two numbers
Given I have entered <input_1> into the calculator
And I have entered <input_2> into the calculator
When I press <button>
Then the result should be <output> on the screen
Examples:
| input_1 | input_2 | button | output |
| 20 | 30 | add | 50 |
Run Code Online (Sandbox Code Playgroud)
我会喜欢Python Cucumber等价物,但即使只是Capybara等效也会有所帮助.
D_B*_*Bye 23
您可以使用Cucumber测试Python代码 - 有关更多信息,请参阅github上的Cucumber wiki.
如果你想要一个纯Python解决方案,请查看Lettuce.我从来没有使用它,但有一个相当有用的博客条目关于它和分裂在这里.
Ste*_*son 19
A.黄瓜喜欢:(英文喜欢)
RedwoodHQ(基于方法关键字)(RedwoodHQ具有比'English-Like'标准更大的功能并且包含以下功能:基于关键字,基于Web的测试框架,支持python作为语言之一等等.关于RedwoodHQ的其他信息:理论上它可能,所有现有的机器人框架内置库和所有机器人框架外部测试库或任何python库,可以从这个基于Web的测试框架调用或使用,只需稍加修改)
Gauge(Gherkin方法):python的参考:(https://gauge-python.readthedocs.io/en/latest/index.html)
在Cucumber下面,人们可以像Capybara那样隐藏/分组许多硒行为的抽象层
B. Capybara喜欢:(抽象:隐藏/团体行动)
作为一个例如单击一个元素,它足以提供像click(定位器)的命令而不是使用raw selenium api
,其中需要找到一个元素然后单击.下面的可选库中存在更多这样的抽象
我的研究:差不多有六个人.活跃的,b.成熟的c.developed选项.
python自带各种电池!!
选项-1:Selenium2Library
Github网址: https ://github.com/rtomac/robotframework-selenium2library
发展: 积极
目的:
众多库中的一个robotframework
,也可以用作框架的"独立"库(请查看下面的使用方法).
思考:
用法:
pip install robotframework-selenium2library
在你的ipython或空闲控制台中导入并开始播放,例如:
>>from Selenium2Library import Selenium2Library
>>start_testing= Selenium2Library()
>>start_testing.create_webdriver("Firefox")
>>start_testing.go_to("http://www.google.com")
>>.
...so on
Run Code Online (Sandbox Code Playgroud)
选项-2:Pageobjects
Github网址: https ://github.com/ncbi/robotframework-pageobjects
开发: InActive(没有显示最新版本的塞子)
目的:
其中一个库robotframework
.提供页面对象抽象Selenium2Library
.可以作为框架的独立使用(请参见下面的使用方法),也可以与机器人框架一起使用.
思考:
用法:
pip install robotframework-pageobjects
例如:在ipython或idle中:
>>from robotpageobjects import Page
>>start_testing=Page()
>>start_testing.create_webdriver("Firefox")
>>start_testing.go_to("http://google.com")
Run Code Online (Sandbox Code Playgroud)
选项-3:robotframework-pageobjectlibrary
Github Url: https ://github.com/boakley/robotframework-pageobjectlibrary
发展: 积极
希望作者支持LTS(长期支持):)),手指越过!!
用法:
pip install robotframework-pageobjectlibrary
思考:
选项-4:分裂
Github网址: https ://github.com/cobrateam/splinter
发展: 积极
用法: splinter.readthedocs.org/en/latest/index.html
pip install splinter
在ipython或空闲时做:
>>from splinter import Browser
>>browser = Browser()
>>browser.visit('http://google.com')
>>browser.fill('q', 'splinter - python acceptance testing for web applications')
>>browser.find_by_name('btnG').click()
Run Code Online (Sandbox Code Playgroud)
选项-5:SST库
Github网址: https ://github.com/Work4Labs/selenium-simple-test
开发: 功能完整/主动
用法: testutils.org/sst/
pip install -U sst
在ipython或idle do:
>>> from sst.actions import *
>>> start()
Starting Firefox
>>> go_to('http://google.com')
Going to... http://google.com
Waiting for get_element
Run Code Online (Sandbox Code Playgroud)
选项-6:氦气 非开源(商业)
选项-7:holmium.core
Github网址: https ://github.com/alisaifee/holmium.core
选项-8:wtframework
Github网址: https ://github.com/wiredrive/wtframework
选项9:webium
Github网址: https ://github.com/wgnet/webium
选项-10:elementium
Github网址: https ://github.com/actmd/elementium
选项-11:漫步
Github网址: https ://github.com/Element-34/py.saunter
用法: 闲逛
选项-12:webdriverplus
Github网址: https ://github.com/tomchristie/webdriverplus
用法: webdriverplus
评论: 存储库没有维护,但体面的参考
选项-12:简单的Pageobject
Github网址: https ://github.com/rama-bornfree/simple-pageobject/tree/master/PageObjectLibrary
评论: 围绕selenium2library构建的最简单的页面对象包装器.我是回购的所有者
测试设置:
选项-1-13中的"全部"测试库; 可以使用下列任何框架的运行:Lettuce, Behave, Robotframework
或就此而言,任何单元测试框架(例如PyUnit
,Nose
)...等等.
测试框架通常用于管理测试用例,例如
什么重要的是一个多么舒适与上面的选项库得到.
选项-5:就其SST
而言,它具有框架本身的特征,例如它可以生成报告并执行更多操作.
因此,在SST的情况下,库和框架的定义是模糊的,取决于要从该包中使用的功能的范围
一些有趣的数学:
一个人可以拥有好的,坏的和丑陋的测试设置的总数=(测试框架和测试库+你的自定义代码夹在框架和库中):
7*13 = 91种方式
选择适合需要的最佳组合(测试框架和测试库)!
我个人会选择带有Selenium2Library的机器人框架或带有一些pageobject库的Robot-framework
当然,我在关于机器人框架和Selenium2Library的帖子中倾向于并且有偏见
现在确实存在一个Python的Capybara端口:
https://github.com/elliterate/capybara.py
你可以在这里找到它的文档:
https://elliterate.github.io/capybara.py/
Capybara通过模拟真实用户与您的应用程序交互的方式来帮助您测试Web应用程序.它与运行测试的驱动程序无关,并且内置了Selenium支持.
小智 7
你检查过清新,还是豌豆?
豌豆不使用黄瓜的语法,但作者说这更容易 https://github.com/gfxmonk/pea
而且Freshen试图克隆Cucumber的语法和功能
https://github.com/rlisagor/freshen