smarter testing

This commit is contained in:
2015-08-07 12:44:11 +02:00
parent 74ba0dd27d
commit 3aef45a94e
5 changed files with 37 additions and 6 deletions
+30
View File
@@ -27,6 +27,36 @@ module SpecEmberHelpers
classes.should include class_name
end
# expect_that_eventually selector: '.supplier-orders-placed-count-number', has_text: "10"
def expect_that_eventually(options = {})
selector = options[:selector] or raise "An argument selector: '.my-selector' is required"
time = 0
expected_value, value_method = case options
when ->(h){ h.has_key? :has_text } then [options[:has_text], 'text()']
when ->(h){ h.has_key? :has_value } then [options[:has_value], 'val()']
else
raise "No matcher can be found, possible matchers: :has_text, ..."
end
current_value = page.evaluate_script("$('#{selector}').#{value_method}")
while current_value != expected_value and time < 30
sleep 0.1
current_value = page.evaluate_script("$('#{selector}').text()")
time += 1
end
#current_value.should eq expected_text
#if expected_text = options[:has_text]
#current_value = page.evaluate_script("$('#{selector}').#{value_method}")
#while current_text != expected_text and time < 30
#sleep 0.1
#current_text = page.evaluate_script("$('#{selector}').text()")
#time += 1
#end
#current_text.should eq expected_text
#else
#raise "No matcher can be found, possible matchers: :has_text, ..."
#end
end
def js_set_field(selector, value)
find selector
page.execute_script("$('#{selector}').val('#{value}').trigger('change')")