lib/site-object/site.rb
# Looks at the page currently being displayed in the browser and tries to return a page object for
# it. Does this by looking at the currently displayed URL in the browser. The first page that gets
# checked is the page that was most recently accessed. After that it will cycle through all available
# pages looking for a match. Returns nil if it can't find a matching page object.
Looks at the page currently being displayed in the browser and tries to return a page object for
it. Does this by looking at the currently displayed URL in the browser. The first page that gets
checked is the page that was most recently accessed. After that it will cycle through all available
pages looking for a match. Returns nil if it can't find a matching page object.
Looks at the page currently being displayed in the browser and tries to return a page object for it . Does this by looking at the currently displayed URL in the browser . The first page that gets checked is the page that was most recently accessed . After that it will cycle through all available pages looking for a match . Returns nil if it can ' t find a matching page object .
def page
    return @most_recent_page if @most_recent_page && @most_recent_page.on_page?
    if @browser.is_a? Watir::Browser
      url = @browser.url
    elsif @browser.is_a? Selenium::WebDriver::Driver
      url = @browser.current_url
    else
      raise SiteObject::BrowserLibraryNotSupportedError, "Unsupported browser library: #{@browser.class}"
    end
    found_page = nil
    @pages.each do |p|
      if p.url_matcher && p.url_matcher =~ url
        found_page = p
      elsif p.query_arguments && p.url_template.match(url)
        found_page = p
      elsif !p.query_arguments && p.url_template.match(url.split(/(\?|#)/)[0])
        found_page = p
      end
      break if found_page
    end
    if found_page && !found_page.required_arguments.empty?
      if hsh = found_page.url_template.extract(url)
        return found_page.new(self, found_page.url_template.extract(url))
      else
        return found_page.new(self, found_page.url_template.extract(url.split(/(\?|#)/)[0]))
      end
    elsif found_page
      return found_page.new(self)
    else
      return nil
    end
  end
def page return @most_recent_page if @most_recent_page && @most_recent_page . on_page? if @browser . is_a? Watir :: Browser url = @browser . url elsif @browser . is_a? Selenium :: WebDriver :: Driver url = @browser . current_url else raise SiteObject :: BrowserLibraryNotSupportedError , "Unsupported browser library: #{@browser.class}" end found_page = nil @pages . each do | p | if p . url_matcher && p . url_matcher =~ url found_page = p elsif p . query_arguments && p . url_template . match ( url ) found_page = p elsif ! p . query_arguments && p . url_template . match ( url . split ( / ( \? |#) / ) [ 0 ] ) found_page = p end break if found_page end if found_page && ! found_page . required_arguments . empty? if hsh = found_page . url_template . extract ( url ) return found_page . new ( self , found_page . url_template . extract ( url ) ) else return found_page . new ( self , found_page . url_template . extract ( url . split ( / ( \? |#) / ) [ 0 ] ) ) end elsif found_page return found_page . new ( self ) else return nil end end
Looks at the page currently being displayed in the browser and tries to return a page object for
it.
Looks at the page currently being displayed in the browser and tries to return a page object for it .