Created
August 1, 2011 14:21
Implementing Page Parts in watir-page-helper
This file contains 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
require 'watir-page-helper' | |
class BasePart | |
include WatirPageHelper | |
attr_reader :part_key | |
def initialize(browser, part_key) | |
@part_key = part_key | |
@browser = part_div(browser, part_key) | |
end | |
def part_div(browser, part_key) | |
raise 'this method should be overridden and return the HTML element that holds the page part' | |
end | |
end |
This file contains 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
<div class="cluster"> | |
<div> | |
<a class="title" href="http://www.smh.com.au/world/us-not-out-of-the-woods-yet-despite-deal-to-avert-default-20110801-1i8bt.html?from=smh_sb" rel="nofollow" id="n-hp-">US not out of the woods yet, despite deal to avert default</a> | |
</div> | |
<div class="byline"> | |
<span class="src">Sydney Morning Herald</span> | |
<span class="date" tm="1312209001"> - 17 minutes ago</span></div> | |
<!-- google_ad_section_end --> | |
<div class="snippet">A deal may have been reached but the US still faces some tough economic hurdles. Photo: AFP THE US could still lose its coveted AAA credit rating in coming months despite a last-minute deal struck yesterday between the White House and Republicans that ...</div> | |
<!-- google_ad_section_start --> | |
</div> | |
</div> |
This file contains 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
require 'watir-page-helper' | |
class GoogleFinance | |
include WatirPageHelper | |
div :news_items, :id => "market-news-stream" | |
def initialize(browser) | |
@browser = browser | |
end | |
def news_item(index) | |
news_items_div.divs[index] | |
end | |
def news_link(index) | |
news_link_link(index).click | |
end | |
def news_link_link(index) | |
news_item(index).a | |
end | |
def news_snippet_div_div(index) | |
news_item(index).div(:class, "snippet") | |
end | |
def news_snippet_div(index) | |
news_snippet_div_div(index).text | |
end | |
end |
This file contains 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
class GoogleFinancePart < BasePart | |
link :news_link, :index => 0 | |
div :news_snippet, :class => "snippet" | |
def initialize(browser, index) | |
super(browser, index) | |
end | |
def part_div(browser, index) | |
browser.div(:id, "market-news-stream").divs[index] | |
end | |
end |
This file contains 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
class GoogleFinancePart | |
def initialize(div) | |
@news_item = div | |
end | |
def news_link | |
news_link_link.click | |
end | |
def news_link_link | |
@news_item.a | |
end | |
def news_snippet_div_div | |
@news_item.div(:class, "snippet") | |
end | |
def news_snippet_div | |
news_snippet_div_div.text | |
end | |
end |
This file contains 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
require 'watir-page-helper' | |
class GoogleFinance | |
include WatirPageHelper | |
div :news_items, :id => "market-news-stream" | |
def initialize(browser) | |
@browser = browser | |
end | |
def news_item(index) | |
GoogleFinancePart.new(news_items_div.divs[index]) | |
end | |
def news_link(index) | |
news_link_link(index).click | |
end | |
def news_link_link(index) | |
news_item(index).a | |
end | |
def news_snippet_div_div(index) | |
news_item(index).div(:class, "snippet") | |
end | |
def news_snippet_div(index) | |
news_snippet_div_div(index).text | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment