Created
November 2, 2009 11:12
-
-
Save kornysietsma/224090 to your computer and use it in GitHub Desktop.
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
class TwitterHomePage | |
PAGE_URL = "http://www.twitter.com" | |
def initialize(world) | |
@world = world | |
@browser = $selenium_helper.browser | |
end | |
def visit | |
@browser.open PAGE_URL | |
@browser.wait_for_page_to_load | |
@browser.title.should == "Twitter" | |
end | |
def has_popular_topics? | |
@browser.element? POP_TOPICS_LOCATOR | |
end | |
def most_popular_topic | |
@browser.text FIRST_POP_TOPIC_LOCATOR | |
end | |
def search(topic) | |
@browser.type SEARCH_BOX_LOCATOR, topic | |
@browser.click SEARCH_BUTTON_LOCATOR | |
@browser.wait_for_element RESULTS_HEADING_LOCATOR | |
end | |
private | |
POP_TOPICS_LOCATOR = %Q{//div[@id = "trends"]//div[@class = "current"]} | |
FIRST_POP_TOPIC_LOCATOR = "#{POP_TOPICS_LOCATOR}/ul/li[1]/a" | |
SEARCH_BOX_LOCATOR = %Q{//input[@id="home_search_q"]} | |
SEARCH_BUTTON_LOCATOR = %Q{//a[@id="home_search_submit"]} | |
RESULTS_HEADING_LOCATOR = %Q{//div[@id="content"]/h2[@id="timeline_heading"]} | |
end |
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
class TwitterResultsPage | |
def initialize(world) | |
@world = world | |
@browser = $selenium_helper.browser | |
end | |
def tweets | |
# ajax results, give them a chance to load | |
@browser.wait_for_element(TIMELINE_LOCATOR) | |
result_count = @browser.get_xpath_count(TIMELINE_LOCATOR).to_i | |
(1..result_count).collect do |count| | |
{ | |
:author => @browser.get_text(tweet_author_locator(count)), | |
:tweet => @browser.get_text(tweet_text_locator(count)) | |
} | |
end | |
end | |
def wait_for_more_results(timeout_secs) | |
@browser.wait_for_element(MORE_RESULTS_LOCATOR,{:timeout_in_secs => timeout_secs}) | |
end | |
private | |
def tweet_author_locator(count) | |
%Q{#{tweet_locator(count)}//a[contains(@class, "screen-name")]} | |
end | |
def tweet_text_locator(count) | |
%Q{#{tweet_locator(count)}//span[contains(@class, "msgtxt")]} | |
end | |
def tweet_locator(count) | |
%Q{#{TIMELINE_LOCATOR}[#{count}]} | |
end | |
TIMELINE_LOCATOR = %Q{//ol[@id="timeline"]/li} | |
MORE_RESULTS_LOCATOR = %Q{//div[@id="new_results_notification"]/a[@id="results_update" and not(contains(@style, "display: none"))]} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment