[英]cucumber - RackTest isn't working on test that both Selenium and WebKit succeeded on
I am using Cucumber with Capybara to build my testing framework for a site. 我正在将Cucumber与Capybara结合使用来构建站点的测试框架。 I have found a way using hooks to switch between the Capybara driver in Cucumber.
我找到了一种使用钩子在Cucumber中的Capybara驱动程序之间切换的方法。 I want to be able just to use RackTest when I am not testing for JavaScript because I was lead to believe RackTest is faster since it doesn't render the page.
我想只在不测试JavaScript时使用RackTest,因为我被认为RackTest速度更快,因为它不呈现页面。 Right now I have create 3 identical test that jump to Google and check that the title says Google.
现在,我已经创建了3个相同的测试,可以跳到Google并检查标题是否为Google。 Each test uses a different driver.
每个测试使用不同的驱动程序。 The Selenium and WebKit test work fine but the RackTest fails on the " I should see the title "Google" " test.
Selenium和WebKit测试工作正常,但是RackTest在“ 我应该看到标题“ Google” ”测试上失败。 I have attached a copy of my feature and steps and testing gems to this post.
我已在此帖子中附上了我的功能和步骤以及测试gem的副本。
Feature: 特征:
Feature: Rack Test
In order to run test faster
As a tester
I want to use Rack Test to preform all non-javascript related test
Scenario: Visit a page and check title
When I go to "http://www.google.com"
Then I should see the title "Google"
@firefox
Scenario: Visit a page and check title in Firefox
When I go to "http://www.google.com"
Then I should see the title "Google"
@webkit
Scenario: Visit a page and check title in WebKit
When I go to "http://www.google.com"
Then I should see the title "Google"
Steps: 脚步:
When /^I go to "(http:\/\/[^"]*)"$/ do |url|
visit url
end
Then /^I should see the title "([^"]*)"$/ do |title_cont|
page.should have_selector "title", text: title_cont
end
Hooks: 挂钩:
Before('@firefox') do
Capybara.current_driver = :selenium
end
Before('@webkit') do
Capybara.current_driver = :webkit
end
After('@firefox, @webkit') do
Capybara.use_default_driver
end
Gemfile: 宝石文件:
group :test do
gem 'capybara'
gem 'capybara-webkit'
gem 'cucumber'
gem 'cucumber-rails'
gem 'database_cleaner'
gem 'factory_girl_rails'
gem "rack-test", require: "rack/test"
gem 'rspec'
gem 'selenium-webdriver'
end
That's because rack-test
can only test Rack applications (eg your Ruby On Rails website). 这是因为
rack-test
只能测试Rack应用程序(例如,您的Ruby On Rails网站)。 It's not browser-based solution, while both Selenium and WebKit are. 它不是基于浏览器的解决方案,而Selenium和WebKit都是。 That's why
rack-test
can't access external websites (Google in your case). 这就是
rack-test
无法访问外部网站(在您的情况下为Google)的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.