ruby on rails - Is there a way to Test (Unit/Integration) that CSS is applied to the expected HTML Elements? -


i testing views cucumber , rails right , enjoy experience. can say:

background:   given logged in customer scenario: view welcome page   when go home page   should on "welcome" page   , should see following in sidebar:     | selector                  | text                |     | h3                        | search              |     | .home-page                | home                |     | .about-page               |               | 

now i'm wondering, how can go 1 step further , say:

and should see following colors on "welcome" page:   | selector                  | background          |   | #content                  | white               |   | #sidebar                  | grey                |   | #navigation               | blue                | 

i feel saw possible node.js or other serverside javascript, because it's browser dependent. there way this, maybe selenium in safari , firefox?

i want test colors , fonts, not layout b/c of cross browser craziness. how this? maybe little jasmine cucumber?

thanks!

update

thanks @idlefingers, here's works:

setup: cucumber, capybara.

features/support/env.rb:

capybara.javascript_driver = :selenium 

*features/step_definitions/css_steps.rb:*

then /^i should see color "([^"]+)" on ([^"]+)$/ |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 should see color "red" on sidebar 

if there's better way, i'd love know!

i can understand why might want check correct id or class has been applied element, can't see why you'd want check it's css directly? that'll brittle - changing shade of colour break tests!

also, think you're missing cucumber's main strength - testing behaviour, not implementation. should have read of this - makes points pertinent way you're testing.

in answer actual question, if want this, way can think of execute javascript on page test values. can done in selenium (with get eval). same thing can achieved through capybara long js driver working.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -