module Testable::Pages

Public Instance Methods

clear_cookies() click to toggle source

A call to `clear_cookies` removes all the cookies from the current instance of the browser that is being controlled by WebDriver.

# File lib/testable/page.rb, line 199
def clear_cookies
  browser.cookies.clear
end
Also aliased as: remove_cookies
current_url()
Alias for: url
definition_api() click to toggle source

This provides a list of the methods that are defined on the page definition. This is helpful is you need to query the page to see if an element has been provided since all elements automatically become methods on a definition instance.

# File lib/testable/page.rb, line 11
def definition_api
  public_methods(false) - Object.public_methods
end
displayed?()
Alias for: has_correct_url?
execute_script(script, *args)
Alias for: run_script
goto(url = nil, &block)
Alias for: visit
has_correct_title?() click to toggle source

A call to `has_correct_title?` returns true or false if the actual title of the current page in the browser matches the `title_is` attribute. Notice that this check is done as part of a match rather than a direct check. This allows for regular expressions to be used.

# File lib/testable/page.rb, line 92
def has_correct_title?
  no_title_is_provided if title_attribute.nil?
  !title.match(title_attribute).nil?
end
has_correct_url?() click to toggle source

A call to `has_correct_url?`returns true or false if the actual URL found in the browser matches the `url_matches` assertion. This is important to note. It's not using the `url_is` attribute nor the URL displayed in the browser. It's using the `url_matches` attribute.

# File lib/testable/page.rb, line 64
def has_correct_url?
  no_url_match_is_possible if url_attribute.nil? && url_match_attribute.nil?
  !(url =~ url_match_attribute).nil?
end
Also aliased as: displayed?, loaded?
html()
Alias for: markup
loaded?()
Alias for: has_correct_url?
markup() click to toggle source

A call to `markup` returns all markup on a page. Generally you don't just want the entire markup but rather want to parse the output of the `markup` call.

# File lib/testable/page.rb, line 107
def markup
  browser.html
end
Also aliased as: html
maximize() click to toggle source

This method provides a means to maximize the browser window. This is done by getting the screen width and height via JavaScript calls.

# File lib/testable/page.rb, line 163
def maximize
  browser.window.resize_to(screen_width, screen_height)
end
move_to(x_coord, y_coord) click to toggle source

This method provides a call to the browser window to move the window to the specified x and y screen coordinates.

# File lib/testable/page.rb, line 175
def move_to(x_coord, y_coord)
  browser.window.move_to(x_coord, y_coord)
end
navigate_to(url = nil, &block)
Alias for: visit
page_text()
Alias for: text
page_title()
Alias for: title
page_url()
Alias for: url
perform(url = nil, &block)
Alias for: visit
refresh() click to toggle source

This method sends a standard “browser refresh” message to the browser.

# File lib/testable/page.rb, line 182
def refresh
  browser.refresh
end
Also aliased as: refresh_page
refresh_page()
Alias for: refresh
remove_cookies()
Alias for: clear_cookies
resize(width, height) click to toggle source

This method provides a call to the browser window to resize that window to the specified width and height values.

# File lib/testable/page.rb, line 169
def resize(width, height)
  browser.window.resize_to(width, height)
end
Also aliased as: resize_to
resize_to(width, height)
Alias for: resize
run_script(script, *args) click to toggle source

This method provides a call to the synchronous `execute_script` action on the browser, passing in JavaScript that you want to have executed against the current page. For example:

result = page.run_script("alert('Cogent ran a script.')")

You can also run full JavaScript snippets.

script = <<-JS
  return arguments[0].innerHTML
JS

page.run_script(script, page.account)

Here you pass two arguments to `run_script`. One is the script itself and the other are some arguments that you want to pass as part of of the execution. In this case, an element definition (`account`) is being passed in.

# File lib/testable/page.rb, line 141
def run_script(script, *args)
  browser.execute_script(script, *args)
end
Also aliased as: execute_script
save_screenshot(file)
Alias for: screenshot
screen_height() click to toggle source

A call to `screen_height` returns the height of the browser screen as reported by the browser API, using a JavaScript call to the `screen` object.

# File lib/testable/page.rb, line 157
def screen_height
  run_script("return screen.height;")
end
screen_width() click to toggle source

A call to `screen_width` returns the width of the browser screen as reported by the browser API, using a JavaScript call to the `screen` object.

# File lib/testable/page.rb, line 150
def screen_width
  run_script("return screen.width;")
end
screenshot(file) click to toggle source

A call to `screenshot` saves a screenshot of the current browser page. Note that this will grab the entire browser page, even portions of it that are off panel and need to be scrolled to. You can pass in the path and filename of the image that you want the screenshot saved to.

# File lib/testable/page.rb, line 210
def screenshot(file)
  browser.screenshot.save(file)
end
Also aliased as: save_screenshot
secure?() click to toggle source

A call to `secure?` returns true if the page is secure and false otherwise. This is a simple check that looks for whether or not the current URL begins with 'https'.

# File lib/testable/page.rb, line 100
def secure?
  !url.match(/^https/).nil?
end
text() click to toggle source

A call to `text` returns all text on a page. Note that this is text that is taken out of the markup context. It is unlikely you will just want the entire text but rather want to parse the output of the `text` call.

# File lib/testable/page.rb, line 117
def text
  browser.text
end
Also aliased as: page_text
title() click to toggle source

A call to `title` returns the actual title of the page that is displayed in the browser.

# File lib/testable/page.rb, line 82
def title
  @browser.title
end
Also aliased as: page_title
title_attribute() click to toggle source

A call to `title_attribute` returns what the value of the `title_is` attribute is for the given definition. It's important to note that this is not grabbing the title that is displayed in the browser; rather it's the one declared in the interface definition, if any.

# File lib/testable/page.rb, line 76
def title_attribute
  self.class.title_attribute
end
url() click to toggle source

A call to `url` returns the actual URL of the page that is displayed in the browser.

# File lib/testable/page.rb, line 41
def url
  @browser.url
end
Also aliased as: page_url, current_url
url_attribute() click to toggle source

A call to `url_attribute` returns what the value of the `url_is` attribute is for the given interface. It's important to note that this is not grabbing the URL that is displayed in the browser; rather it's the one declared in the interface definition, if any.

# File lib/testable/page.rb, line 35
def url_attribute
  self.class.url_attribute
end
url_match_attribute() click to toggle source

A call to `url_match_attribute` returns what the value of the `url_matches` attribute is for the given interface. It's important to note that the URL matching mechanism is effectively a regular expression check.

# File lib/testable/page.rb, line 52
def url_match_attribute
  value = self.class.url_match_attribute
  return if value.nil?

  value = Regexp.new(value) unless value.is_a?(Regexp)
  value
end
view(url = nil, &block)
Alias for: visit
visit(url = nil, &block) click to toggle source

The `visit` method provides navigation to a specific page by passing in the URL. If no URL is passed in, this method will attempt to use the `url_is` attribute from the interface it is being called on.

# File lib/testable/page.rb, line 18
def visit(url = nil, &block)
  no_url_provided if url.nil? && url_attribute.nil?
  @browser.goto(url) unless url.nil?
  @browser.goto(url_attribute) if url.nil?
  when_ready(&block) if block_given?
  self
end
Also aliased as: view, navigate_to, goto, perform