Currently, I am engaged in testing views using Cucumber and Rails, and so far, the experience has been very enjoyable. The following steps can easily be executed:
Background:
Given I am logged in as a customer
Scenario: View the Welcome Page
When I navigate to the home page
Then I should land on the "Welcome" page
And I should see the following elements in the sidebar:
| selector | text |
| h3 | Search |
| .home-page | Home |
| .about-page | About |
However, I am now curious about going a step further with the command:
And I should observe the specific colors on the "Welcome" page:
| selector | background |
| #content | white |
| #sidebar | grey |
| #navigation | blue |
I believe that achieving this may require tools like Node.js or other serverside javascript due to browser dependencies. Is it possible to accomplish this task using Selenium specifically in Safari and Firefox?
My objective is to primarily test colors and fonts, rather than layouts, given the challenges posed by cross-browser discrepancies. How could this be achieved? Perhaps through a combination of Jasmine and Cucumber?
Thank you!
Update
Credit goes to @idlefingers for providing a solution that works:
Tools used: Cucumber, Capybara.
features/support/env.rb:
Capybara.javascript_driver = :selenium
*features/step_definitions/css_steps.rb:*
Then /^I should view the color "([^"]+)" on the ([^"]+)$/ do |color, selector|
element_color = page.evaluate_script('$("##{selector}").css("border-left-color");') # "rgb(221, 221, 221)"
assert_equal color, some_color_conversion_method(element_color)
end
features/some.feature:
And I should view the color "red" on the sidebar
If there's a more effective approach, I would greatly appreciate any suggestions!