Class: Polonium::Driver

Inherits:
Selenium::SeleniumDriver
  • Object
show all
Includes:
WaitFor
Defined in:
lib/polonium/driver.rb

Instance Attribute Summary collapse

Attributes included from WaitFor

#default_timeout

Instance Method Summary collapse

Methods included from WaitFor

#default_wait_for_time, #flunk, #time_class, #wait_for

Instance Attribute Details

#server_hostObject (readonly)

Returns the value of attribute server_host.



4
5
6
# File 'lib/polonium/driver.rb', line 4

def server_host
  @server_host
end

#server_portObject (readonly)

Returns the value of attribute server_port.



4
5
6
# File 'lib/polonium/driver.rb', line 4

def server_port
  @server_port
end

Instance Method Details

#assert_element_not_present(locator, params = {}) ⇒ Object



114
115
116
117
118
119
120
121
# File 'lib/polonium/driver.rb', line 114

def assert_element_not_present(locator, params={})
  params = {
    :message => "Expected element '#{locator}' to be absent, but it was not"
  }.merge(params)
  wait_for(:message => params[:message]) do
    !is_element_present(locator)
  end
end

#assert_element_present(locator, params = {}) ⇒ Object

—– Waiting for conditions



105
106
107
108
109
110
111
112
# File 'lib/polonium/driver.rb', line 105

def assert_element_present(locator, params={})
  params = {
    :message => "Expected element '#{locator}' to be present, but it was not"
  }.merge(params)
  wait_for(params) do
    is_element_present(locator)
  end
end

#assert_location_ends_with(ends_with, options = {}) ⇒ Object



123
124
125
126
127
128
129
130
# File 'lib/polonium/driver.rb', line 123

def assert_location_ends_with(ends_with, options={})
  options = {
    :message => "Expected '#{get_location}' to end with '#{ends_with}'"
  }.merge(options)
  wait_for(options) do
    location_ends_with? ends_with
  end
end

#browser_start_commandObject



11
12
13
# File 'lib/polonium/driver.rb', line 11

def browser_start_command
  @browserStartCommand
end

#browser_urlObject



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

def browser_url
  @browserURL
end

#click(locator) ⇒ Object



59
60
61
62
# File 'lib/polonium/driver.rb', line 59

def click(locator)
  assert_element_present locator
  super
end

#click_and_wait(locator, wait_for = default_timeout) ⇒ Object

Click a link and wait for the page to load.



75
76
77
78
# File 'lib/polonium/driver.rb', line 75

def click_and_wait(locator, wait_for = default_timeout)
  click locator
  assert_page_loaded(wait_for)
end

#configurationObject

The Configuration object.



7
8
9
# File 'lib/polonium/driver.rb', line 7

def configuration
  Configuration.instance
end

#element(locator) ⇒ Object



37
38
39
# File 'lib/polonium/driver.rb', line 37

def element(locator)
  Element.new(self, locator)
end

#element_does_not_contain_text(locator, text) ⇒ Object

Does the element at locator not contain the text?



99
100
101
102
# File 'lib/polonium/driver.rb', line 99

def element_does_not_contain_text(locator, text)
  return true unless is_element_present(locator)
  return !element(locator).contains?(text)
end

#fast_modeObject

Speeds up each Selenese step to normal speed after this method is called.



160
161
162
163
# File 'lib/polonium/driver.rb', line 160

def fast_mode
  get_eval "slowMode = false"
  get_eval 'window.document.getElementsByName("FASTMODE")[0].checked = false'
end

#get_inner_html(locator) ⇒ Object

Get the inner html of the located element.



94
95
96
# File 'lib/polonium/driver.rb', line 94

def get_inner_html(locator)
  get_eval(inner_html_js(locator))
end

#go_back_and_waitObject

Click the back button and wait for the page to load.



81
82
83
84
# File 'lib/polonium/driver.rb', line 81

def go_back_and_wait
  go_back
  assert_page_loaded
end

#inner_html_js(locator) ⇒ Object



165
166
167
# File 'lib/polonium/driver.rb', line 165

def inner_html_js(locator)
  %Q|this.page().findElement("#{locator}").innerHTML|
end

#insert_javascript_file(uri) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/polonium/driver.rb', line 23

def insert_javascript_file(uri)
  js = <<-USEREXTENSIONS
  var headTag = document.getElementsByTagName("head").item(0);
  var scriptTag = document.createElement("script");
  scriptTag.src = "#{uri}";
  headTag.appendChild( scriptTag );
  USEREXTENSIONS
  get_eval(js)
end

#insert_user_extensionsObject



33
34
35
# File 'lib/polonium/driver.rb', line 33

def insert_user_extensions
  insert_javascript_file("/selenium/user-extensions.js")
end

#location_ends_with?(ends_with) ⇒ Boolean

Returns:

  • (Boolean)


132
133
134
135
136
137
138
# File 'lib/polonium/driver.rb', line 132

def location_ends_with?(ends_with)
  if get_location =~ Regexp.new("#{Regexp.escape(ends_with)}$")
    true
  else
    false
  end
end

#open(url) ⇒ Object Also known as: open_and_wait

Open the home page of the Application and wait for the page to load.



87
88
89
90
# File 'lib/polonium/driver.rb', line 87

def open(url)
  super
  assert_page_loaded
end

#open_home_pageObject

Open the home page of the Application and wait for the page to load.



46
47
48
# File 'lib/polonium/driver.rb', line 46

def open_home_page
  open(configuration.browser_url)
end

#pageObject



41
42
43
# File 'lib/polonium/driver.rb', line 41

def page
  Page.new(self)
end

#reloadObject

Reload the current page that the browser is on.



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

def reload
  get_eval("selenium.browserbot.getCurrentWindow().location.reload()")
end

#select(select_locator, option_locator) ⇒ Object



64
65
66
67
# File 'lib/polonium/driver.rb', line 64

def select(select_locator, option_locator)
  assert_element_present select_locator
  super
end

#show_log(log_level = "debug") ⇒ Object

Open the log window on the browser. This is useful to diagnose issues with Selenium Core.



149
150
151
# File 'lib/polonium/driver.rb', line 149

def show_log(log_level = "debug")
  get_eval "LOG.setLogLevelThreshold('#{log_level}')"
end

#slow_modeObject

Slow down each Selenese step after this method is called.



154
155
156
157
# File 'lib/polonium/driver.rb', line 154

def slow_mode
  get_eval "slowMode = true"
  get_eval 'window.document.getElementsByName("FASTMODE")[0].checked = true'
end

#timeout_in_millisecondsObject



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

def timeout_in_milliseconds
  @timeout
end

#type(locator, value) ⇒ Object

Type text into a page element



54
55
56
57
# File 'lib/polonium/driver.rb', line 54

def type(locator, value)
  assert_element_present(locator)
  super
end

#wait_for_page_to_load(timeout = default_timeout) ⇒ Object Also known as: assert_page_loaded



140
141
142
143
144
145
# File 'lib/polonium/driver.rb', line 140

def wait_for_page_to_load(timeout=default_timeout)
  super
  if get_title.include?("Exception caught")
    flunk "We got a new page, but it was an application exception page.\n\n#{get_html_source}"
  end
end