0

I'm trying to write a test to make sure existing users can't register (Using Cucumber, Watir-Webdriver and Page Objects)

I have the following code:

  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

But the @existing variable is returning nothing. These two lines are giving me back nothing:

puts "exisiting username: #{@existing}"
self.email = @exisiting

So I guess I'm trying to figure out how to pass the @existing variable from the 'sign_up' method to the 'sign_up_with_existing_account' method? Thoughts?

Farooq
  • 1,925
  • 3
  • 15
  • 36
  • 1
    There is a typo in 'exisiting' – Bala Oct 27 '14 at 18:41
  • 1
    I think you need to show how you are using the page object (likely the Cucumber steps). In particular, are you calling `sign_up` and `sign_up_with_existing_account` on the same instance? – Justin Ko Oct 27 '14 at 18:55
  • @JustinKo Like this in my step defs: on_page(RegistrationNew).sign_up on_page(RegistrationNew).sign_up_with_existing_account – Farooq Oct 27 '14 at 19:04
  • That will create two different instances of the RegistrationNew page. The `@existing` will only be set in the first instance. – Justin Ko Oct 27 '14 at 19:20

1 Answers1

1

You can't and should not want to do that. Testing would be a tangled mess if running one test could affect the result of another. You should set up the existing user ahead of time (using e.g. Before) so that any test that needs an existing user can take advantage of it.

Max
  • 21,123
  • 5
  • 49
  • 71