Class: Polonium::Driver
- Inherits:
-
Selenium::SeleniumDriver
- Object
- Selenium::SeleniumDriver
- Polonium::Driver
- Includes:
- WaitFor
- Defined in:
- lib/polonium/driver.rb
Instance Attribute Summary collapse
-
#server_host ⇒ Object
readonly
Returns the value of attribute server_host.
-
#server_port ⇒ Object
readonly
Returns the value of attribute server_port.
Attributes included from WaitFor
Instance Method Summary collapse
- #assert_element_not_present(locator, params = {}) ⇒ Object
-
#assert_element_present(locator, params = {}) ⇒ Object
—– Waiting for conditions.
- #assert_location_ends_with(ends_with, options = {}) ⇒ Object
- #browser_start_command ⇒ Object
- #browser_url ⇒ Object
- #click(locator) ⇒ Object
-
#click_and_wait(locator, wait_for = default_timeout) ⇒ Object
Click a link and wait for the page to load.
-
#configuration ⇒ Object
The Configuration object.
- #element(locator) ⇒ Object
-
#element_does_not_contain_text(locator, text) ⇒ Object
Does the element at locator not contain the text?.
-
#fast_mode ⇒ Object
Speeds up each Selenese step to normal speed after this method is called.
-
#get_inner_html(locator) ⇒ Object
Get the inner html of the located element.
-
#go_back_and_wait ⇒ Object
Click the back button and wait for the page to load.
- #inner_html_js(locator) ⇒ Object
- #insert_javascript_file(uri) ⇒ Object
- #insert_user_extensions ⇒ Object
- #location_ends_with?(ends_with) ⇒ Boolean
-
#open(url) ⇒ Object
(also: #open_and_wait)
Open the home page of the Application and wait for the page to load.
-
#open_home_page ⇒ Object
Open the home page of the Application and wait for the page to load.
- #page ⇒ Object
-
#reload ⇒ Object
Reload the current page that the browser is on.
- #select(select_locator, option_locator) ⇒ Object
-
#show_log(log_level = "debug") ⇒ Object
Open the log window on the browser.
-
#slow_mode ⇒ Object
Slow down each Selenese step after this method is called.
- #timeout_in_milliseconds ⇒ Object
-
#type(locator, value) ⇒ Object
Type text into a page element.
- #wait_for_page_to_load(timeout = default_timeout) ⇒ Object (also: #assert_page_loaded)
Methods included from WaitFor
#default_wait_for_time, #flunk, #time_class, #wait_for
Instance Attribute Details
#server_host ⇒ Object (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_port ⇒ Object (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, ={}) = { :message => "Expected '#{get_location}' to end with '#{ends_with}'" }.merge() wait_for() do location_ends_with? ends_with end end |
#browser_start_command ⇒ Object
11 12 13 |
# File 'lib/polonium/driver.rb', line 11 def browser_start_command @browserStartCommand end |
#browser_url ⇒ Object
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 |
#configuration ⇒ Object
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_mode ⇒ Object
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_wait ⇒ Object
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_extensions ⇒ Object
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
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_page ⇒ Object
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 |
#reload ⇒ Object
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_mode ⇒ Object
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_milliseconds ⇒ Object
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 |