public
Created

sleep vs. wait_until

  • Download Gist
my_sample.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#my_target_page.rb
 
def add_and_save_notes notes
fill_in("my_target_text_box", :with => notes)
click_button "Save" # This makes an AJAX request and adds new row to the table upon successfully saving
sleep(3) #<-- This is BAD code. You should have the line below in place of this one.
#wait_until { has_text?(notes) } #<-- This is GOOD practice that enables test stability and hence faith in test results
end
 
def has_note? notes
has_text?(notes)
end
 
 
#my_target_spec.rb
 
describe "save notes" do
it "should add notes as new row to table upon successful save" do
notes = "sample notes"
@my_target_page. add_and_save_notes notes
@my_target_page.has_note?(notes).should be_true
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.