Module: Sapphire::WebAbstractions::RubySeleniumWebDriver
- Includes:
- Pluggable
- Included in:
- ChromeBrowser, FireFoxBrowser, InternetExplorerBrowser, MetaBrowser
- Defined in:
- lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb
Instance Attribute Summary collapse
-
#rootUrl ⇒ Object
readonly
Returns the value of attribute rootUrl.
Instance Method Summary collapse
- #AcceptAlert ⇒ Object
- #AlertShown ⇒ Object
- #Browser ⇒ Object
- #Close ⇒ Object
- #ClosePopup ⇒ Object
- #Create(*args) ⇒ Object
- #CurrentUrl ⇒ Object
- #ExecuteScript(script) ⇒ Object
- #FindAlert ⇒ Object
- #FindAllItems(array) ⇒ Object
- #FindElement(discriminator, selector) ⇒ Object
- #FindElements(discriminator, selector) ⇒ Object
- #FindItem(array, comparator = nil) ⇒ Object
- #FindItemWithoutWait(array, comparator = nil) ⇒ Object
- #FindItemWithWait(array, comparator = nil) ⇒ Object
- #GetValue(item, key) ⇒ Object
- #Init(url) ⇒ Object
- #NavigateTo(page) ⇒ Object
- #Reload ⇒ Object
- #Run(background) ⇒ Object
- #Screenshot(file_name) ⇒ Object
- #SetAlert(text) ⇒ Object
- #SetRootUrl(url) ⇒ Object
- #ShouldNavigateTo(page, comparator) ⇒ Object
- #ShouldTransitionTo(url, comparator) ⇒ Object
- #Switch ⇒ Object
- #SwitchToIFrame(frame) ⇒ Object
- #SwitchToPopup ⇒ Object
- #Type(keys) ⇒ Object
Methods included from Pluggable
Instance Attribute Details
Instance Method Details
permalink #AcceptAlert ⇒ Object
[View source]
32 33 34 35 36 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 32 def AcceptAlert alert = self.Browser().switch_to.alert alert.accept() self.Browser().switch_to.window(self.Browser().window_handles[0]) end |
permalink #AlertShown ⇒ Object
[View source]
53 54 55 56 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 53 def AlertShown() alert = self.FindAlert() return alert != nil end |
permalink #Browser ⇒ Object
[View source]
11 12 13 14 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 11 def Browser() raise "Browser is null. Did you forget to start the browser?" if self.browser.nil? self.browser end |
permalink #Close ⇒ Object
[View source]
20 21 22 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 20 def Close self.Browser().close end |
permalink #ClosePopup ⇒ Object
[View source]
58 59 60 61 62 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 58 def ClosePopup self.Browser().switch_to.window(self.Browser().window_handles.last) self.Browser().close self.Browser().switch_to.window(self.Browser().window_handles[0]) end |
permalink #Create(*args) ⇒ Object
[View source]
296 297 298 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 296 def Create(*args) Selenium::WebDriver.for *args end |
permalink #CurrentUrl ⇒ Object
[View source]
92 93 94 95 96 97 98 99 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 92 def CurrentUrl wait = Selenium::WebDriver::Wait.new(:timeout => 20) url = wait.until { x = self.Browser().current_url x unless x == nil } url end |
permalink #ExecuteScript(script) ⇒ Object
[View source]
292 293 294 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 292 def ExecuteScript(script) self.Browser().execute_script(script) end |
permalink #FindAlert ⇒ Object
[View source]
45 46 47 48 49 50 51 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 45 def FindAlert() begin return self.Browser().switch_to.alert rescue return nil end end |
permalink #FindAllItems(array) ⇒ Object
[View source]
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 242 def FindAllItems(array) masterWait = Selenium::WebDriver::Wait.new(:timeout => 5) x = nil by = nil value = nil element, by, value = masterWait.until { array.each do |item| if item.is_a? Hash begin x = self.FindElements item.keys.first, item.fetch(item.keys.first) x = nil if x.is_a? Array and x.empty? if !x.nil? by = item.keys.first value = item[item.keys.first] end rescue #do nothing, let it keep looping end end x, by, value = self.FindElements item[0], item[1] if item.is_a? Array x = nil if x.is_a? Array and x.empty? return x, by, value if x != nil end if array.is_a? Array x = self.FindElements array.keys.first, array.fetch(array.keys.first) if array.is_a? Hash if !x.nil? by = item.keys.first value = item[item.keys.first] end return x, by, value if x != nil } return element, by, value if element != nil raise "Could not find control for array: " + array.to_s end |
permalink #FindElement(discriminator, selector) ⇒ Object
[View source]
284 285 286 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 284 def FindElement(discriminator, selector) self.Browser().find_element discriminator, selector end |
permalink #FindElements(discriminator, selector) ⇒ Object
[View source]
288 289 290 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 288 def FindElements(discriminator, selector) self.Browser().find_elements discriminator, selector end |
permalink #FindItem(array, comparator = nil) ⇒ Object
[View source]
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 178 def FindItem(array, comparator = nil) x = nil by = nil value = nil array.each do |item| if item.is_a? Hash begin x = self.FindElement item.keys.first, item.fetch(item.keys.first) by = item.keys.first value = item.fetch(item.keys.first) rescue #do nothing, let it keep looping end end if item.is_a? Array x = self.FindElement item[0], item[1] by = item[0] value = item[1] end return x, by, value if x != nil return x, by, value if comparator.Compare(x != nil, true) if comparator != nil end if array.is_a? Array if array.is_a? Hash x = self.FindElement array.keys.first, array.fetch(array.keys.first) by = array.keys.first value = array.fetch(array.keys.first) end return x, by, value if x != nil return x, by, value if comparator.Compare(x != nil, true) if comparator != nil end |
permalink #FindItemWithoutWait(array, comparator = nil) ⇒ Object
[View source]
232 233 234 235 236 237 238 239 240 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 232 def FindItemWithoutWait(array, comparator=nil) element, by, value = FindItem(array, comparator) return element, by, value if element != nil return element, by, value if comparator.Compare(element != nil, true) if comparator != nil raise "Could not find control for array: " + array.to_s end |
permalink #FindItemWithWait(array, comparator = nil) ⇒ Object
[View source]
217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 217 def FindItemWithWait(array, comparator=nil) masterWait = Selenium::WebDriver::Wait.new(:timeout => 5) element, by, value = masterWait.until { x, by, value = FindItem(array, comparator) return x, by, value if x != nil return x, by, value if comparator.Compare(x != nil, true) if comparator != nil } return element, by, value if element != nil return element, by, value if comparator.Compare(element != nil, true) if comparator != nil raise "Could not find control for array: " + array.to_s end |
permalink #GetValue(item, key) ⇒ Object
[View source]
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 105 def GetValue(item, key) if item.is_a? Array item.each do |sub_item| value = GetValue(sub_item, key) return value if !value.nil? end end if item.is_a? Class and key.nil? return item.new end if item.is_a? Hash return item[key] if item.has_key? key end nil end |
permalink #Init(url) ⇒ Object
[View source]
7 8 9 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 7 def Init(url) @rootUrl = url end |
permalink #NavigateTo(page) ⇒ Object
[View source]
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 81 def NavigateTo(page) if(page.is_a? Class) $page = page.new else $page = page end self.Browser().get $page.Url $page.Init end |
permalink #Reload ⇒ Object
[View source]
101 102 103 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 101 def Reload self.Browser().get self.CurrentUrl end |
permalink #Run(background) ⇒ Object
[View source]
160 161 162 163 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 160 def Run(background) scenario = background.new scenario.Run end |
permalink #Screenshot(file_name) ⇒ Object
[View source]
16 17 18 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 16 def Screenshot(file_name) self.Browser().save_screenshot(file_name) end |
permalink #SetAlert(text) ⇒ Object
[View source]
38 39 40 41 42 43 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 38 def SetAlert(text) alert = self.Browser().switch_to.alert alert.send_keys(text) alert.accept() self.Browser().switch_to.window(self.Browser().window_handles[0]) end |
permalink #SetRootUrl(url) ⇒ Object
[View source]
72 73 74 75 76 77 78 79 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 72 def SetRootUrl(url) if(url.instance_of?(String)) self.Init(url) else x = url.new().Url self.Init(x) end end |
permalink #ShouldNavigateTo(page, comparator) ⇒ Object
[View source]
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 125 def ShouldNavigateTo(page, comparator) $page = GetValue(page, nil) $page ||= page timeout = GetValue(page, :wait) timeout ||= 20 $page.Init wait = Selenium::WebDriver::Wait.new(:timeout => timeout) begin item = wait.until { x = self.CurrentUrl.upcase.start_with?($page.Url.upcase) y = StartsWithComparison.new(Evaluation.new(self.CurrentUrl.upcase, $page.Url.upcase)) if(comparator.Compare(x == false, true)) $page.AlternateUrls.each do |url| if(comparator.Compare(x == false, true)) x = self.CurrentUrl.upcase.start_with?(url.upcase) y = StartsWithComparison.new(Evaluation.new(self.CurrentUrl.upcase, url.upcase)) end end end return y if comparator.Compare(x == true, true) } rescue temp = StartsWithComparison.new(Evaluation.new(self.CurrentUrl, $page.Url)) return temp end temp = item return temp end |
permalink #ShouldTransitionTo(url, comparator) ⇒ Object
[View source]
165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 165 def ShouldTransitionTo(url, comparator) if(url.instance_of?(String)) temp = StartsWithComparison.new(Evaluation.new(self.CurrentUrl.upcase, url.upcase)) @rootUrl = url else x = url.new().Url temp = StartsWithComparison.new(Evaluation.new(self.CurrentUrl.upcase, x.upcase)) @rootUrl = x end return temp end |
permalink #Switch ⇒ Object
[View source]
24 25 26 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 24 def Switch self.Browser().switch_to.window(self.Browser().window_handles[0]) end |
permalink #SwitchToIFrame(frame) ⇒ Object
[View source]
68 69 70 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 68 def SwitchToIFrame(frame) self.Browser().switch_to.frame(frame) end |
permalink #SwitchToPopup ⇒ Object
[View source]
64 65 66 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 64 def SwitchToPopup self.Browser().switch_to.window(self.Browser().window_handles.last) end |
permalink #Type(keys) ⇒ Object
[View source]
28 29 30 |
# File 'lib/sapphire/Adapters/Selenium/RubySeleniumWebDriver.rb', line 28 def Type(keys) self.Browser().action.send_keys(keys).perform() end |