lib/selenium/link.rb in Selenium-1.0.1 vs lib/selenium/link.rb in Selenium-1.0.2

- old
+ new

@@ -1,27 +1,41 @@ module Selenium -class Link - attr_reader :browser - - def Link::by_id(browser, id) - Link.new(browser, "id=#{id}") + + # Link class that models the behavior of a link + class Link + attr_reader :browser + + def Link::by_id(browser, id, target = nil) + Link.new(browser, "id=#{id}", target) + end + + def Link::by_text(browser, text, target = nil) + Link.new(browser, "link=#{text}", target) + end + + def initialize(browser, locator, target = nil) + @browser = browser + @locator = locator + @target = target + end + + # click the link + def click + @browser.click(@locator) + end + + # click the link and wait for page to load + def click_wait + click + @browser.wait_for_page_to_load + end + + # click the link, wait for the page to load, and asserts the target that + # was passed in during initialization + def go + raise "target page not defined for link #{@locator}" unless @target + click_wait + @target.assert_on_page + @target + end end - - def Link::by_text(browser, text) - Link.new(browser, "link=#{text}") - end - - def initialize(browser, locator) - @browser = browser - @locator = locator - end - - def click - @browser.click(@locator) - end - - def click_wait - click - @browser.wait_for_page_to_load - end -end end