我正在使用黄瓜和水豚在大型消费者网站上测试帐户的创建。当我在常规撬开会话中运行我的水豚代码时,一切正常。但是当我运行黄瓜测试时,within
块似乎没有运行,并且注册表单没有填写。
env.rb
require 'capybara/cucumber'
require 'selenium-webdriver'
Before do
Capybara.default_driver = :selenium
end
test.feature
Scenario: Test consumer site account creation
* I create a new example.com account
step_definition.rb
When(/^I create a new account$/) do
visit 'http://example.com/myaccount'
find("#cboxClose").click if page.has_css?("#cboxClose")
require 'pry';binding.pry
within("form[name='newCustomer']") do
random_letters = SecureRandom.urlsafe_base64(5)
fill_in "Email Address", :with => "test-#{random_letters}@example.com"
fill_in "Create Password", :with => "Password123"
fill_in "Confirm Password", :with => "Password123"
click_on "Create Account"
end
end
当我运行cucumber
并尝试在pry中运行within
块时,我明白了:
#<RSpec::Matchers::AliasedMatcher:0x007ff5e86b16e8
@base_matcher=
#<RSpec::Matchers::BuiltIn::BeWithin:0x007ff5e86b1710
@delta="form[name='newCustomer']">,
@description_block=
#<Proc:0x007ff5e4c34d08@/Users/anthonychung/.rvm/gems/ruby-2.1.2/gems/rspec-expectations-3.2.0/lib/rspec/matchers.rb:245 (lambda)>>
所以我怀疑RSpec的别名匹配器会以某种方式覆盖方法中的水豚。
当我尝试within(:css, "form[etc.]")
时,我得到一个参数错误ArgumentError: wrong number of arguments (2 for 1)
。
答案 0 :(得分:2)
page.within
我觉得自己很愚蠢,但至少我明白了。