将现有变量传递到Ruby方法

将现有变量传递到Ruby方法,ruby,cucumber,watir-webdriver,pageobjects,page-object-gem,Ruby,Cucumber,Watir Webdriver,Pageobjects,Page Object Gem,我正在尝试编写一个测试,以确保现有用户无法注册(使用Cucumber、watirwebdriver和Page对象) 我有以下代码: text_field(:email, :id => "user_email") text_field(:password, :id => "user_password") text_field(:password_confirmation, :id => "user_password_confirmation") checkbox(

我正在尝试编写一个测试,以确保现有用户无法注册(使用Cucumber、watirwebdriver和Page对象)

我有以下代码:

  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\u up”方法传递到“sign\u up\u with\u existing\u account”方法?想法

你不能也不应该这样做。如果运行一个测试可能会影响另一个测试的结果,那么测试将是一团混乱。您应该提前设置现有用户(例如在之前使用),以便任何需要现有用户的测试都可以利用它。

在“exisiting”中有一个输入错误,我认为您需要显示如何使用页面对象(可能是步骤)。特别是,您是否在同一实例上调用
注册
使用现有账户注册?@JustinKo在我的步骤defs:on_页面(RegistrationNew)。注册页面(RegistrationNew)。使用现有账户注册将创建两个不同的注册新页面实例。现有的
@将仅在第一个实例中设置。