如何跟随黄瓜和水豚的锚标记/外部链接

时间:2014-11-10 04:24:35

标签: ruby-on-rails ruby cucumber capybara bdd

When(/^I click the "(.*?)" link$/) do |subscribe|
  click_on subscribe 
end

订阅链接转到外部网站:

https://www.somesite.com/path/to/something?this=that

然而,当我运行该功能时,我收到此错误:

No route matches [GET] "/path/to/something" (ActionController::RoutingError)

如何让capybara关注此外部链接而不是忽略该查询?

1 个答案:

答案 0 :(得分:1)

Cucumber和Capybara很遗憾没有使用外部链接。我建议使用Capybara-Mechanize:https://github.com/jeroenvandijk/capybara-mechanize

试试这个(虽然只适用于一个链接):

When(/^I click the "(.*?)" link$/) do
  Capybara.current_driver = :mechanize
  visit 'https://www.somesite.com/path/to/something?this=that'
end

以下是一些使用示例: http://turriate.com/articles/2011/feb/testing-twitter-oauth-with-real-data/