Class: OLE_QA::Framework::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/ole_qa_framework/session.rb

Overview

Handle Browser Functions, Headless Session

Invoke with @ole = Session.new(opts)
Exit with @ole.quit

Default options loaded from

config/options.yml

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Session

Options hash keys:

:url => "http://tst.ole.kuali.org/"
  (URL for OLE Installation)
:docstore_url => 'http://tst.docstore.ole.kuali.org/'
  (URL for OLE DocStore Installation)
:headless? => true/false
  (Use Headless gem to handle XVFB session)
:implicit_wait => NN
  (Set Selenium Webdriver's default wait period)
:explicit_wait => NN
  (Set the wait period used by Watir Webdriver and custom functions)
:doc_wait => NN
  (Set the wait period for eDoc routing to complete)
:browser => watir_webdriver
  (Where browser is a Watir WebDriver session)
:profile => profile
  (Where profile is a Selenium::WebDriver::Firefox::Profile instance)

To configure the default options, edit

config/options.yml


104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/ole_qa_framework/session.rb', line 104

def initialize( options={} )
  options_defaults = YAML.load_file(OLE_QA::Framework::load_dir + '/../config/options.yml')
  @options = options_defaults.merge(options)

  # Set local variable if @options[:browser] is given a Watir::Browser session.
  browser_given = @options.has_key?(:browser) && @options[:browser].is_a?(Watir::Browser)

  # Use Headless if requested.
  if @options[:headless?] && ! browser_given
    self.class.start_headless
  else
    self.class.stop_headless if self.is_headless?
  end

  # Set trailing slash on URLs for consistency if not set.
  add_slash = ->(which) { which =~ /\/$/ ? which : which + '/' }

  # Globalize options to accessors
  @url            = add_slash.call(@options[:url])
  @docstore_url   = add_slash.call(@options[:docstore_url])
  @explicit_wait  = @options[:explicit_wait]
  @doc_wait       = @options[:doc_wait]

  # Pass explicit_wait to a module accessor for use with OLE_QA::Tools
  OLE_QA::Framework.instance_variable_set(:@explicit_wait,@options[:explicit_wait])

  # Pass doc_wait to a module accessor for use with OLE_QA::Tools
  OLE_QA::Framework.instance_variable_set(:@doc_wait,@options[:doc_wait])

  # Browser Start
  if browser_given
    @browser = @options[:browser]
  else
    # Use a Firefox profile, if given.
    @options.has_key?(:profile) ?
        @browser = Watir::Browser.new(:firefox, :profile => @options[:profile]) :
        @browser = Watir::Browser.new(:firefox)
    @browser.driver.manage.timeouts.implicit_wait = @options[:implicit_wait]
  end

  # Set cutomizable default timeout on Watir-Webdriver (v0.6.5+).
  Watir.default_timeout = @explicit_wait
end

Class Attribute Details

.headless_sessionObject

Return the current Headless session.



29
30
31
# File 'lib/ole_qa_framework/session.rb', line 29

def headless_session
  @headless_session
end

Instance Attribute Details

#docstore_urlObject (readonly) Also known as: docstore

OLE Document Store Installation Base URL

(e.g. http://docstore.ole.your-site.edu/)


74
75
76
# File 'lib/ole_qa_framework/session.rb', line 74

def docstore_url
  @docstore_url
end

#explicit_waitObject

Wait period (in seconds) used by OLE QAF Web Element functions



78
79
80
# File 'lib/ole_qa_framework/session.rb', line 78

def explicit_wait
  @explicit_wait
end

#optionsObject (readonly)

The options with which this OLE_QA Framework Session was invoked



81
82
83
# File 'lib/ole_qa_framework/session.rb', line 81

def options
  @options
end

#urlObject (readonly) Also known as: fs_url, base_url, ls_url

OLE Installation Base URL

(e.g. http://ole.your-site.edu/)


66
67
68
# File 'lib/ole_qa_framework/session.rb', line 66

def url
  @url
end

Class Method Details

.is_headless?Boolean

Is Headless started?

Returns:

  • (Boolean)


32
33
34
# File 'lib/ole_qa_framework/session.rb', line 32

def is_headless?
  @is_headless
end

.quit_headlessObject

Quit the headless session entirely.



56
57
58
# File 'lib/ole_qa_framework/session.rb', line 56

def quit_headless
  @headless_session.destroy if self.is_headless?
end

.start_headlessObject

Start a new Headless session.



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

def start_headless
  @headless_session ||= Headless.new
  unless self.is_headless? then
    @is_headless      = true
    @headless_session.start
  end
end

.stop_headlessObject

Stop the headless session.



46
47
48
49
50
51
52
53
# File 'lib/ole_qa_framework/session.rb', line 46

def stop_headless
  if self.is_headless? then
    @headless_session.stop
    @is_headless = false
  else
    raise OLE_QA::Framework::Error,"Headless is not running."
  end
end

Instance Method Details

#browserObject

Access Watir-Webdriver’s browser session.



159
160
161
# File 'lib/ole_qa_framework/session.rb', line 159

def browser
  @browser
end

#closeObject

Exit the browser only, stop the Headless (XVFB) session, but don’t destroy it entirely.



174
175
176
# File 'lib/ole_qa_framework/session.rb', line 174

def close
  @browser.quit
end

#headless_sessionObject

Access the Headless session class-level instance variable.



149
150
151
# File 'lib/ole_qa_framework/session.rb', line 149

def headless_session
  self.class.headless_session
end

#is_headless?Boolean

Return whether Headless is running.

Returns:

  • (Boolean)


154
155
156
# File 'lib/ole_qa_framework/session.rb', line 154

def is_headless?
  self.class.is_headless?
end

#open(url = @url) ⇒ Object

Open a page via URL. (Defaults to @base_url.)



169
170
171
# File 'lib/ole_qa_framework/session.rb', line 169

def open(url = @url)
  @browser.goto(url)
end

#quitObject

Teardown the OLE QA Framework.

  • Exit the Selenium WebDriver browser session.

  • Exit the Headless (XVFB) session if necessary.



181
182
183
184
185
186
# File 'lib/ole_qa_framework/session.rb', line 181

def quit
  @browser.quit
  if self.is_headless? then
    self.class.quit_headless
  end
end

#windowsObject

Access Watir-Webdriver’s Window Handling Method



164
165
166
# File 'lib/ole_qa_framework/session.rb', line 164

def windows
  @browser.windows
end