Module: SpecTest

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

Defined Under Namespace

Modules: Enclosers, Generators, Matchers, Platforms, WebObjects

Constant Summary collapse

VERSION =
"0.0.4"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Platforms

associate, list, #platform_for

Instance Attribute Details

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

Returns:

  • (TerminusSpec::Platforms::WatirWebDriver::PlatformObject)

    the platform object

  • (TerminusSpec::Platforms::SeleniumWebDriver::PlatformObject)

    the platform object



14
15
16
# File 'lib/spectest.rb', line 14

def platform
  @platform
end

Class Method Details

.included(caller) ⇒ Object

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



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

def self.included(caller)
  caller.extend SpecTest::Generators
  caller.extend SpecTest::Enclosers
end

.trace(message, level = 1) ⇒ Object



2
3
4
# File 'lib/spectest/logger.rb', line 2

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

.version_infoObject



16
17
18
# File 'lib/spectest.rb', line 16

def self.version_info
  "SpecTest version #{SpecTest::VERSION}"
end

Instance Method Details

#initialize(browser, visit = nil) ⇒ Object



28
29
30
31
32
# File 'lib/spectest.rb', line 28

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

#is_enclosed_by(identifier, encloser = nil, &block) ⇒ Object

Used to identify a web object as existing within an enclosing object like a frame or an iframe. There is a duplicate method in enclosers.rb. This method needs to be here so that test steps can be placed in an enclosed context.

Parameters:

  • identifier (String)

    how an encloser will be referred to

  • encloser (defaults to: nil)

    a parent encloser that is passed from a previous call

  • block (optional)

    that contains calls to web objects within the encloser



64
65
66
67
68
# File 'lib/spectest.rb', line 64

def is_enclosed_by(identifier, encloser=nil, &block)
  encloser = [] if encloser.nil?
  encloser << identifier
  block.call(encloser)
end

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

Parameters:

  • url (String)

    the full URL to navigate to



37
38
39
40
41
42
43
44
# File 'lib/spectest.rb', line 37

def navigate_to(url)
  # Here is exactly why a platform object is needed. Which version do I call:
  #   @browser.goto(url)  <-- this is for Watir
  #   @browser.navigate.to(url)  <-- this is for Selenium
  # I have to call the platform that has been established. The platform will
  # be responsible for containing the correct call.
  @platform.navigate_to url
end

#textObject

Returns the text of the current page.



52
53
54
# File 'lib/spectest.rb', line 52

def text
  @platform.text
end

#titleObject

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



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

def title
  @platform.title
end