【问题标题】:Passing in an existing variable into a Ruby method将现有变量传递给 Ruby 方法
【发布时间】: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_upsign_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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-20
    • 1970-01-01
    • 1970-01-01
    • 2012-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多