cucumber跑起来了,发现不行,没法启动webdriver,需要设置个support/env.rb
网上找了好多资料,发现这个完全不行,都是关于ruby rails的环境设置的
找了这个:1. 首先gem list查看你的环境,看是否有:
selenium
selenium-client
selenium-webdriver
如果没有请使用geminstall 安装缺失模块。(可能只需要selenium-client 以及selenium)
2.确认模块已安装后,编辑features/support/env.rb,添加:
require'selenium/client'
Capybara.default_driver= :selenium
Capybara.server_boot_timeout= 50
3. 启动selenium:
bash$ selenium
4. 运行测试:
bash$ cucumber
一切正常的话应可看到selenium启动firefox并运行测试步骤。
源文档 <http://www.th7.cn/Program/Ruby/2011-07-07/28540.shtml>
发现完全不行
gem'capybara'
源文档 <https://github.com/jnicklas/capybara/>
以前我们有项目做过,但是我的代码都删除了。
然后我sudo geminstall capybara
然后是在无奈了,装rubyrails
cucumber-–help 查看命令的帮助
cucumber默认运行features目录下面的所有feature
cucumber-–require features features/first.feature 只运行指定feature文件中的用例
cucumberfeatures –name “hello” 运行指定Scenario名称的用例
cucumberfeatures/first.feature:11 运行文件中指定行数对于的Scenario用例
源文档 <http://www.tuicool.com/articles/aeaAra>
click_link('id-of-link')
click_button('Save')
表单:
fill_in('FirstName', :with => 'John')
fill_in('Password', :with => 'Seekrit')
fill_in('Description', :with => 'Really Long Text...')
choose('A Radio Button')
check('A Checkbox')
uncheck('A Checkbox')
attach_file('Image', '/path/to/image.jpg')
select('Option', :from => 'Select Box')
XPath
page.has_selector?(:xpath,'//table/tr')
查找
find_field('FirstName').value
find('#navigation').click_link('Home')
部分驱动支持执行 JavaScript:
page.execute_script("$('body').empty()")
result = page.evaluate_script('4 + 4');
源文档 <http://segmentfault.com/a/1190000000506988>
然后装ruby rails,
gem install rails
源文档 <https://ruby-china.org/wiki/install_ruby_guide>
然后跑ruby rails的环境
$ bundle install
源文档 <http://ihower.tw/rails3/firststep.html>
但是我们系统是PHP做的,用rails不行
http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Selenium/Driver
https://ruby-china.org/topics/7119
然后找篇文章
Given /^I am on theDDG homepage$/ do
visit 'http://duckduckgo.com'
end
When /^I search for"([^\"]*)"$/ do |query|
@query = query
fill_in 'q', :with =>query
click_button "search_button_homepage"
end
Then /^I should seean exact match on the Ruby Gems search page$/ do
gem_name = @query.split('').last
page.shouldhave_selector("a[href='/gems/#{gem_name}']")
end
源文档 <https://github.com/saucelabs/sauce_ruby/wiki/Cucumber-and-Capybara>
发现要装
In order to useCucumber + Capybara, install the sauce-cucumber gem with gem installsauce-cucumber and add the following to your features/support/env.rb
require'sauce/cucumber'
源文档 <https://github.com/saucelabs/sauce_ruby/wiki/Cucumber-and-Capybara>
最后运行
require 'capybara'
require 'cucumber'
require 'capybara/cucumber'
//Capybara.app_host = "http://www.stackoverflow.com"
//Capybara.run_server = false
Capybara.default_driver = :selenium
源文档 <http://stackoverflow.com/questions/14057532/how-to-include-capybara-into-module-in-cucumber-project>
结果就行了,擦!