Using variable values within different scenarios in a feature, capybara -


i have feature 4 scenarios. use value of 1 variable set in scenario 1 across different steps , in scenario 2.

i use $ not set. assuming $ value remains same across feature

when(/^the user goes manageusers, picks 1 of secondary users$/)   click_link "admin"   click_link "manage users"   emailofuser=env["email"].to_s   atpos = emailofuser.index('@')   emailofuser = emailofuser[0,atpos]   page.body.to_s.scan(/<td>(.*?)@abc.com<\/td>/).flatten().each |w|     if "#{w}" != emailofuser     $secondaryuseremail = "#{w}" + "@abc.com"     break     end   end end  when(/^the secondary user logs in password "([^"]*)"$/) |arg|   if  geturl != uri.parse(current_url)     visit geturl   end   find(:xpath,"//input[@id='user_email']").set($secondaryuseremail )   fill_in "user_password", :with => arg   click_button "sign in" end 

in above step, steps in 1 scenario in feature file , have same step secondary user in scenario 2 within feature. variable $secondaryuseremail times not set , login secondary user fails.

whats best way me declare variables can access across steps within scenario , across scenarios within feature.

you should find out why $secondaryuseremail not set. sounds bug somewhere in app you're testing. if it's not bug, should try handle exception.

to original question, might idea set variables in helper methods, call these methods access them using instance variables. people recommend against sharing variables across scenarios i've used helper methods in order store variables throughout specs go unchanged.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -