Created
March 30, 2011 18:24
-
-
Save mrmemes-eth/894947 to your computer and use it in GitHub Desktop.
Scope assertions to portions of the page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SectionLocator | |
def within_parent(content, elements = ['*'], &block) | |
expr = %(//*[(#{elements.join('|')})/descendant-or-self::*[contains(., "#{content}")]]) | |
within(:xpath, expr, &block) | |
end | |
def within_parent_preceding(content, elements = ['*'], &block) | |
expr = %(//*[(#{elements.join('|')})[contains(., "#{content}")]]/..) | |
within(:xpath, expr, &block) | |
end | |
end | |
World(SectionLocator) | |
sections = %w(h1 h2 h3 h4 h5 h6 legend caption dt strong p label a) | |
When /^(.*) in the "([^\"]*)" section$/ do |action, title| | |
within_parent(title, sections) do | |
When action | |
end | |
end | |
When /^(.*) in the "([^\"]*)" section:$/ do |action, title, table| | |
within_parent(title, sections) do | |
When "#{action}:", table | |
end | |
end | |
When /^(.*) in the "([^\"]*)" row$/ do |action, title| | |
within_parent(title, %w(th td)) do | |
When action | |
end | |
end | |
When /^(.*) in the section before "([^\"]*)"/ do |action, title| | |
within_parent_preceding(title, sections) do | |
When action | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment