【发布时间】:2014-10-27 18:29:35
【问题描述】:
我正在尝试编写测试以确保现有用户无法注册(使用 Cucumber、Watir-Webdriver 和页面对象)
我有以下代码:
text_field(:email, :id => "user_email")
text_field(:password, :id => "user_password")
text_field(:password_confirmation, :id => "user_password_confirmation")
checkbox(:terms_privacy, :id => "user_accepts_terms")
button(:sign_up_button, :text => "Sign Up")
def unique_username
@username = "qa_automation"+"#{rand(6 ** 6)}"+"@gmail.com"
end
def sign_up
unique_username
self.email = @username
self.password = USERS['PASSWORD']
self.password_confirmation = USERS['PASSWORD']
self.check_terms_privacy
self.sign_up_button
puts "username: #{@username}"
@existing = @username
end
def sign_up_with_existing_account
puts "exisiting username: #{@existing}"
self.email = @exisiting
self.password = USERS['PASSWORD']
self.password_confirmation = USERS['PASSWORD']
self.check_terms_privacy
self.sign_up_button
puts "username: #{@existing}"
end
但@existing 变量没有返回任何内容。这两行没有给我任何回报:
puts "exisiting username: #{@existing}"
self.email = @exisiting
所以我想我想弄清楚如何将@existing 变量从'sign_up' 方法传递给'sign_up_with_existing_account' 方法?想法?
【问题讨论】:
-
“现有”中有错字
-
我认为您需要展示如何使用页面对象(可能是 Cucumber 步骤)。特别是,您是否在同一实例上调用
sign_up和sign_up_with_existing_account? -
@JustinKo 在我的步骤中这样定义:on_page(RegistrationNew).sign_up on_page(RegistrationNew).sign_up_with_existing_account
-
这将创建 RegistrationNew 页面的两个不同实例。
@existing只会在第一个实例中设置。
标签: ruby cucumber watir-webdriver pageobjects page-object-gem