Module: Tapestry::Interface::Page

Includes:
Situation
Defined in:
lib/tapestry/attribute.rb,
lib/tapestry/interface.rb

Defined Under Namespace

Modules: Attribute

Instance Method Summary collapse

Instance Method Details

#apiObject



221
222
223
# File 'lib/tapestry/interface.rb', line 221

def api
  methods - Object.public_methods
end

#clear_cookiesObject Also known as: remove_cookies

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



203
204
205
# File 'lib/tapestry/interface.rb', line 203

def clear_cookies
  browser.cookies.clear
end

#definition_apiObject



225
226
227
# File 'lib/tapestry/interface.rb', line 225

def definition_api
  public_methods(false) - Object.public_methods
end

A call to ‘get_cookie` allows you to specify a particular cookie, by name, and return the information specified in the cookie.



194
195
196
197
198
199
# File 'lib/tapestry/interface.rb', line 194

def get_cookie(name)
  browser.cookies.to_a.each do |cookie|
    return cookie[:value] if cookie[:name] == name
  end
  nil
end

#has_correct_title?Boolean

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.

Returns:

  • (Boolean)


68
69
70
71
# File 'lib/tapestry/interface.rb', line 68

def has_correct_title?
  no_title_is_provided if title_attribute.nil?
  !title.match(title_attribute).nil?
end

#has_correct_url?Boolean Also known as: displayed?

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.

Returns:

  • (Boolean)


55
56
57
58
59
60
# File 'lib/tapestry/interface.rb', line 55

def has_correct_url?
  if url_attribute.nil? && url_match_attribute.nil?
    no_url_match_is_possible
  end
  !(url =~ url_match_attribute).nil?
end

#markupObject Also known as: html

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.



100
101
102
# File 'lib/tapestry/interface.rb', line 100

def markup
  browser.html
end

#maximizeObject

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



125
126
127
# File 'lib/tapestry/interface.rb', line 125

def maximize
  browser.window.resize_to(screen_width, screen_height)
end

#move_to(x, y) ⇒ Object

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



139
140
141
# File 'lib/tapestry/interface.rb', line 139

def move_to(x, y)
  browser.window.move_to(x, y)
end

#refreshObject Also known as: refresh_page

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



117
118
119
# File 'lib/tapestry/interface.rb', line 117

def refresh
  browser.refresh
end

#resize(width, height) ⇒ Object Also known as: resize_to

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



131
132
133
# File 'lib/tapestry/interface.rb', line 131

def resize(width, height)
  browser.window.resize_to(width, height)
end

#run_script(script, *args) ⇒ Object Also known as: execute_script

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('Tapestry ran a script.')")

You can also run full JavaScript snippets.

script = "  return arguments[0].innerHTML\n"

page.run_script(script, page.)

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.



161
162
163
# File 'lib/tapestry/interface.rb', line 161

def run_script(script, *args)
  browser.execute_script(script, *args)
end

#screen_heightObject

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.



188
189
190
# File 'lib/tapestry/interface.rb', line 188

def screen_height
  run_script("return screen.height;")
end

#screen_widthObject

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.



181
182
183
# File 'lib/tapestry/interface.rb', line 181

def screen_width
  run_script("return screen.width;")
end

#screenshot(file) ⇒ Object Also known as: save_screenshot

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.



172
173
174
# File 'lib/tapestry/interface.rb', line 172

def screenshot(file)
  browser.save.screenshot(file)
end

#secure?Boolean

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’.

Returns:

  • (Boolean)


76
77
78
# File 'lib/tapestry/interface.rb', line 76

def secure?
  !url.match(/^https/).nil?
end

#selenium_apiObject



217
218
219
# File 'lib/tapestry/interface.rb', line 217

def selenium_api
  Tapestry.browser.driver.methods - Object.public_methods
end

#textObject Also known as: page_text

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.



110
111
112
# File 'lib/tapestry/interface.rb', line 110

def text
  browser.text
end

#titleObject Also known as: page_title

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



91
92
93
# File 'lib/tapestry/interface.rb', line 91

def title
  @browser.title
end

#title_attributeObject

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, if any.



47
48
49
# File 'lib/tapestry/interface.rb', line 47

def title_attribute
  self.class.title_attribute
end

#urlObject Also known as: page_url, current_url

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



82
83
84
# File 'lib/tapestry/interface.rb', line 82

def url
  @browser.url
end

#url_attributeObject

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, if any.



28
29
30
# File 'lib/tapestry/interface.rb', line 28

def url_attribute
  self.class.url_attribute
end

#url_match_attributeObject

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.



36
37
38
39
40
41
# File 'lib/tapestry/interface.rb', line 36

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

#visit(url = nil, &block) ⇒ Object Also known as: view, navigate_to, goto, perform

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.



11
12
13
14
15
16
17
# File 'lib/tapestry/interface.rb', line 11

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

#watir_apiObject



209
210
211
# File 'lib/tapestry/interface.rb', line 209

def watir_api
  Tapestry.browser.methods - Object.public_methods
end

#watir_selectorsObject



213
214
215
# File 'lib/tapestry/interface.rb', line 213

def watir_selectors
  Watir::Container.instance_methods
end