smarter testing
This commit is contained in:
@@ -156,8 +156,7 @@ step "the supplier main board list total should be updated" do
|
||||
end
|
||||
|
||||
step "the supplier placed orders counter should be reduced" do
|
||||
sleep 0.8
|
||||
find('.supplier-orders-placed-count-number').text.should == "10"
|
||||
expect_that_eventually selector: '.supplier-orders-placed-count-number', has_text: "10"
|
||||
end
|
||||
|
||||
step "confirm the supplier close list modal" do
|
||||
|
||||
+1
-1
@@ -139,7 +139,7 @@ RSpec.configure do |config|
|
||||
|
||||
# Use color in STDOUT
|
||||
config.color = true
|
||||
config.fail_fast = true
|
||||
config.fail_fast = false
|
||||
|
||||
# Use color not only in STDOUT but also in pagers and files
|
||||
config.tty = true
|
||||
|
||||
@@ -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')")
|
||||
|
||||
Reference in New Issue
Block a user