Module: TerminusSpec

Includes:
Locators, Matchers, Platforms
Defined in:
lib/terminus_spec.rb,
lib/terminus_spec/logger.rb,
lib/terminus_spec/factory.rb,
lib/terminus_spec/version.rb,
lib/terminus_spec/locators.rb,
lib/terminus_spec/matchers.rb,
lib/terminus_spec/platforms.rb,
lib/terminus_spec/generators.rb,
lib/terminus_spec/platform_watir.rb,
lib/terminus_spec/web_objects/all.rb,
lib/terminus_spec/web_objects/link.rb,
lib/terminus_spec/platform_selenium.rb,
lib/terminus_spec/web_objects/button.rb,
lib/terminus_spec/web_objects/text_field.rb,
lib/terminus_spec/platform_watir/platform_object.rb,
lib/terminus_spec/platform_watir/web_objects/all.rb,
lib/terminus_spec/platform_selenium/platform_object.rb,
lib/terminus_spec/platform_selenium/web_objects/all.rb,
lib/terminus_spec/platform_selenium/web_objects/link.rb,
lib/terminus_spec/platform_selenium/web_objects/button.rb,
lib/terminus_spec/platform_watir/web_objects/text_field.rb,
lib/terminus_spec/platform_selenium/web_objects/text_field.rb

Defined Under Namespace

Modules: Factory, Generators, Locators, Matchers, Platforms, WebObjects

Constant Summary collapse

VERSION =
"0.5.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Locators

#button_web_object, #link_web_object, #text_field_web_object

Methods included from Platforms

associate, list, #platform_for

Instance Attribute Details

#browserWatir::Browser, Selenium::WebDriver::Driver (readonly)

Returns:

  • (Watir::Browser)

    the platform browser

  • (Selenium::WebDriver::Driver)

    the platform browser



15
16
17
# File 'lib/terminus_spec.rb', line 15

def browser
  @browser
end

#platformTerminusSpec::Platforms::WatirWebDriver::PlatformObject, TerminusSpec::Platforms::SeleniumWebDriver::PlatformObject (readonly)



19
20
21
# File 'lib/terminus_spec.rb', line 19

def platform
  @platform
end

Class Method Details

.included(caller) ⇒ Object

This makes sure that any page classes that include TerminusSpec will be given access to the generator methods based on web objects that are declared in the page class.



24
25
26
# File 'lib/terminus_spec.rb', line 24

def self.included(caller)
  caller.extend TerminusSpec::Generators
end

.trace(message, level = 2) ⇒ Object



3
4
5
# File 'lib/terminus_spec/logger.rb', line 3

def self.trace(message, level=2)
  puts("*" * level + " #{message}") if ENV['TRACE'] == 'on'
end

Instance Method Details

#attach_to_window(identifier, &block) ⇒ Object

Attaches to a displayed window. The window can be located using either the title attribute of the window or a direct URL. The URL does not have to be the entire URL; it can just be a page name (like index.html). Since attaching to a window can be problematic due to race conditions, a second try will be attempted if any exceptions occur.

window that is being attached to

Examples:

page.attach_to_window(:title => "Display Results")
page.attach_to_window(:url => results.html)

Parameters:

  • either (Hash)

    :title or :url of the window.

  • block

    any code that should be executed before actions taken on the



159
160
161
162
163
164
165
166
# File 'lib/terminus_spec.rb', line 159

def attach_to_window(identifier, &block)
  begin
    @platform.attach_to_window(identifier, &block)
  rescue
    sleep 2
    @platform.attach_to_window(identifier, &block)
  end
end

#backObject

Goes back to the preceding page in history.



70
71
72
# File 'lib/terminus_spec.rb', line 70

def back
  @platform.back
end

#clear_cookiesObject

Clears the cookies from the browser.



80
81
82
# File 'lib/terminus_spec.rb', line 80

def clear_cookies
  @platform.clear_cookies
end

#current_urlObject

Returns the current page URL.



60
61
62
# File 'lib/terminus_spec.rb', line 60

def current_url
  @platform.current_url
end

#forwardObject

Goes forward to the succeeding page in history.



75
76
77
# File 'lib/terminus_spec.rb', line 75

def forward
  @platform.forward
end

#htmlObject

Returns the html of the current page



55
56
57
# File 'lib/terminus_spec.rb', line 55

def html
  @platform.html
end

#initialize(browser, visit = nil) ⇒ Object

Creates a platform object.

Parameters:

  • the (Watir::Browser or Selenium::WebDriver::Driver)

    platform browser to use



30
31
32
33
34
35
# File 'lib/terminus_spec.rb', line 30

def initialize(browser, visit=nil)
  @browser = browser
  establish_platform_driver_for browser
  setup_page if respond_to?(:setup_page)
  goto if visit && respond_to?(:goto)
end

Navigate to the specified URL. The URL can be specified as a domain address or as a file-based link.

Parameters:

  • the (String)

    full URL to navigate to



40
41
42
# File 'lib/terminus_spec.rb', line 40

def navigate_to(url)
  @platform.navigate_to url
end

#refreshObject

Refreshes the current page.



65
66
67
# File 'lib/terminus_spec.rb', line 65

def refresh
  @platform.refresh
end

#save_screenshot(file_name) ⇒ Object

Saves the current screenshot to a provided URL. The file will be saved as a PNG file.



86
87
88
# File 'lib/terminus_spec.rb', line 86

def save_screenshot(file_name)
  @platform.save_screenshot file_name
end

#textObject

Returns the text of the current page.



45
46
47
# File 'lib/terminus_spec.rb', line 45

def text
  @platform.text
end

#titleObject

Returns the title of the current page as displayed in the browser.



50
51
52
# File 'lib/terminus_spec.rb', line 50

def title
  @platform.title
end

#wait_until(timeout = 15, message = nil, &block) ⇒ Object

Waits until a condition is found to be true or a timeout occurs.

Examples:

page.wait_until(3, 'Record Saved message was not found.') do
  page.text.should match(/^Record Saved$/)
end

Parameters:

  • the (Numeric)

    amount of time to wait for the condition to return true.

  • the (String)

    message to include with the error if the timeout duration is exceeded.

  • block

    the logic to execute.



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

def wait_until(timeout=15, message=nil, &block)
  @platform.wait_until(timeout, message, &block)
end

#will_alert(&block) ⇒ String

Captures the execution of an alert popup.

Examples:

message = page.will_alert do
  page.submit
end

Parameters:

  • block

    the action that will cause the alert to display

Returns:

  • (String)

    the message that was contained in the alert



113
114
115
# File 'lib/terminus_spec.rb', line 113

def will_alert(&block)
  @platform.will_alert(&block)
end

#will_be_modal(&block) ⇒ Object

Captures the execution of a model dialog opens that dialog as a window. The new window can then be attached to.

Examples:

page.will_be_modal do
  page.submit
end

Parameters:

  • block

    the action that will cause the modal dialog



177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/terminus_spec.rb', line 177

def will_be_modal(&block)
  script =
  %Q{
    window.showModalDialog = function(sURL, vArguments, sFeatures) {
      window.dialogArguments = vArguments;
      modalWin = window.open(sURL, 'modal', sFeatures);
      return modalWin;
    }
  }
  browser.execute_script script
  yield if block_given?
end

#will_confirm(response, &block) ⇒ String

Captures the execution of a confirmation popup.

Examples:

message = page.will_confirm(true) do
  page.submit
end

Parameters:

  • what (bool)

    response you want to return back from the confirmation popup

  • block

    the action that will cause the confirmation to display

Returns:

  • (String)

    the message that was prompted in the confirmation



127
128
129
# File 'lib/terminus_spec.rb', line 127

def will_confirm(response, &block)
  @platform.will_confirm(response, &block)
end

#will_prompt(response, &block) ⇒ Hash

Captures the execution of a prompt popup.

:default_value contains the default value for the prompt if provided

Examples:

message = page.will_prompt("Question") do
  page.submit
end

Parameters:

  • the (string)

    user entered value that is returned from the prompt

  • block

    the action that will cause the prompt to display

Returns:

  • (Hash)

    A has containing two keys. :message contains the prompt message and



142
143
144
# File 'lib/terminus_spec.rb', line 142

def will_prompt(response, &block)
  @platform.will_prompt(response, &block)
end