Posted over 4 years ago. Visible to the public.

How to inspect RSS feeds with Spreewald, XPath, and Selenium

Spreewald gives you the <step> within <selector> meta step that will constrain page inspection to a given scope.

Unfortunately, this does not work with RSS feeds, as they're XML documents and not valid when viewed from Capybara's internal browser (e.g. a <link> tag cannot have content in HTML).

Inspecting XML

If you're inspecting XML that is invalid in HTML, you need to inspect the page source instead of the DOM. You may use Spreewald's "... in the HTML" meta step, or add this proxy step for better semantics:

Copy
Then /^I should( not)? see "(.+?)" in the page source$/ do |negate, text| step %(I should#{ negate } see "#{ text }" in the HMTL) end

Now you can say Then I should see "Application title" in the page source within "channel > title" whenever a simple "within ..." does not work.

Note that you need to write all selectors in lowercase letters in your tests. Capybara talks HTML, after all, and in HTML tags and attributes are case-insensitive (as opposed to XML).

Using Xpath

If you need xpath to express things that CSS selectors cannot do, add the following selector in selectors.rb:

Copy
when /^"(.+?)" \(xpath\)$/ [:xpath, $1]

Then use it like this: Then I should see "Application title" in the page source within "//channel/title" (xpath)

Using Selenium and Firefox

Selenium doesn't seem to be able to inspect RSS when you follow a link to the feed. (At least) Firefox seems to intercept those RSS links, and Capybara internally remains on the previous page.
This behavior can be circumvented with the following simple step:

Copy
# Firefox seems to intercept RSS links. Use this step to circumvent that. When /^I open the RSS feed behind "(.+?)"$/ do |link_label| link = find_link(link_label) visit link[:href] end

Once an application no longer requires constant development, it needs periodic maintenance for stable and secure operation. makandra offers monthly maintenance contracts that let you focus on your business while we make sure the lights stay on.

Owner of this card:

Avatar
Dominik Schöler
Last edit:
over 4 years ago
by Dominik Schöler
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Dominik Schöler to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more