[英]Rspec overriding Capybara 'within' method in Cucumber
I am testing the creation of an account on a large consumer website using cucumber and capybara. 我正在测试一个使用黄瓜和水豚在大型消费者网站上创建的帐户。 When I run my capybara code in a regular pry session it all works. 当我在常规的撬动会话中运行水豚代码时,一切正常。 But when I run the cucumber test, the within
block doesn't seem to run and the sign up form doesn't get filled out. 但是,当我运行黄瓜测试时, 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
When I run cucumber
and try to run the within
block in pry, I get this: 当我运行cucumber
并尝试在撬中运行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)>>
So I suspect RSpec's aliased matcher is overriding capybara's within method somehow. 因此,我怀疑RSpec的别名匹配器以某种方式覆盖了水豚的内部方法。
When I try to do within(:css, "form[etc.]")
I get an argument error ArgumentError: wrong number of arguments (2 for 1)
. 当我尝试within(:css, "form[etc.]")
出现参数错误ArgumentError: wrong number of arguments (2 for 1)
。
page.within
我觉得很傻,但至少我想通了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.