Skip to content

Instantly share code, notes, and snippets.

@libo
Created November 19, 2012 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save libo/4110529 to your computer and use it in GitHub Desktop.
Save libo/4110529 to your computer and use it in GitHub Desktop.
Evaluation with selector
def evaluate_css(property, selector = 'body')
page.evaluate_script("(typeof jQuery !== 'undefined') && $('#{selector}').css('#{property}')")
end
def expect_css(property, values)
values.each do |selector, value|
begin
wait_until { evaluate_css(property, selector) == value}
rescue Capybara::TimeoutError
evaluate_css(property, selector).should == value
end
end
end
@dasch
Copy link

dasch commented Nov 19, 2012

Won't work. You want to have

expect_css "body", "color" => "#fff"

So you need to do

def expect_css(selector, styles)
  styles.each do |property, expected_value|
    begin
      wait_until { evaluate_css(selector, property) == expected_value }
    rescue Capybara::TimeoutError
      evaluate_css(selector, property).should == expected_value
  end
end

@libo
Copy link
Author

libo commented Nov 19, 2012

You are calling evaluate_css(selector, property) inverted?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment