Capybara: How to check page style sheet?

I want to be able to verify the correct style sheet replacement in my test suite. With this post about testing the page title with Capybara, I thought I could test the tags linkin the section headon the page. But it seems I'm wrong.

With this step:

save_and_open_page
page.should have_xpath("//link") # just something as simple as this, first.

save_and_open_page generates such HTML (with some removal for brevity):

<head>
  ...
  <link href="/home/ramon/source/unstilted/public/system_test/stylesheets/fancake/css/2.css?1323572998" type="text/css" class="jquery-styler" rel="stylesheet">
  ...
</head>

But I get this crash:

expected xpath "//link" to return something (RSpec::Expectations::ExpectationNotMetError)

Given all this, how to check the stylesheet ?

Thank!

+5
source share
2 answers

If you want to verify that the CSS file exists on the page, you can do the following:

page.should have_xpath("//link[contains(@href, 'style.css')]")

, - <link>, href style.css. " xpath -" , XPath, , , - , , , <link> HTML, .

+4

css, , -

expect(page.body).to include('/home/ramon/source/unstilted/public/system_test/stylesheets/fancake/css/2.css')

+1

All Articles