Class: Browza::Manager
- Inherits:
-
Object
- Object
- Browza::Manager
- Includes:
- Singleton
- Defined in:
- lib/browza/base/manager.rb
Instance Attribute Summary collapse
-
#appModels ⇒ Object
Returns the value of attribute appModels.
-
#browserMgr ⇒ Object
Returns the value of attribute browserMgr.
-
#browserType ⇒ Object
Returns the value of attribute browserType.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#defaultRetries ⇒ Object
Returns the value of attribute defaultRetries.
-
#defaultTimeout ⇒ Object
Returns the value of attribute defaultTimeout.
-
#driverList ⇒ Object
Returns the value of attribute driverList.
-
#drv ⇒ Object
Returns the value of attribute drv.
Instance Method Summary collapse
- #_addDriver(d) ⇒ Object
- #_getActionableElement(_locator, drv, _timeout = 30) ⇒ Object
- #_getBrowserType(browserType) ⇒ Object
- #_getDriverIndex(id) ⇒ Object
- #_isBrowser?(drv, s) ⇒ Boolean
- #_parseLocator(_locator) ⇒ Object
- #addModel(_a) ⇒ Object
- #browserName ⇒ Object
-
#click(_locator, _drv = nil, _timeout = 30) ⇒ Object
Browza.instance.click(‘page(sideNav).get(desktop)’).
- #connectSauce(id, _caps = nil) ⇒ Object
- #count ⇒ Object
- #createBrowser(*p) ⇒ Object
- #deleteDriver(id) ⇒ Object
- #displayed?(_locator, _drv = nil, _timeout = 30) ⇒ Boolean
- #findLocator(_locator, drv = nil) ⇒ Object
- #focusedText ⇒ Object
- #focusedValue ⇒ Object
- #focusedValue?(s, _timeout = 10) ⇒ Boolean
- #getCount(_locator, _drv = nil, _timeout = 30) ⇒ Object
- #getDate ⇒ Object
- #getDriver(id = nil) ⇒ Object
- #getElement(_locator, drv = nil, _timeout = 30) ⇒ Object
- #getElements(_locator, drv = nil, _timeout = 30) ⇒ Object
- #getStyle(_locator, _attr) ⇒ Object
- #getText(_locator) ⇒ Object
- #goto(url, id = nil) ⇒ Object
- #hasStyle?(_locator, tag, expected = nil, _timeout = 30) ⇒ Boolean
- #highlight(_locator = nil, color = 'red', _drv = nil, _timeout = 30) ⇒ Object
- #hover(_locator) ⇒ Object
-
#initialize(_logLevel = :warn) ⇒ Manager
constructor
A new instance of Manager.
- #isChrome?(drv = nil) ⇒ Boolean
- #isEdge(drv = nil) ⇒ Object
- #isFirefox?(drv = nil) ⇒ Boolean
- #isFocused?(_locator) ⇒ Boolean
- #isIE(drv = nil) ⇒ Object
-
#isNotDisplayed?(_locator, _timeout = 10) ⇒ Boolean
TODO: Proper handling of _timeout, instead of hack to globalize @defaultTimeout.
- #isNotVisible?(_locator, _timeout = 30) ⇒ Boolean
- #isText?(_locator, regex = nil) ⇒ Boolean
- #isTitle?(regex) ⇒ Boolean
- #isValue?(_locator, regex = nil, _timeout = 30) ⇒ Boolean
- #isVisible?(_locator, expected = true, _timeout = 30) ⇒ Boolean
- #maximize ⇒ Object
-
#navigate(*p) ⇒ Object
def navigate(url, id=nil).
-
#press(*p) ⇒ Object
press(‘enter’) press(‘tab’, 5) press(‘page(main).get(button)’, ‘enter’).
- #pressKey(k, n = 1, _delay = 0.25) ⇒ Object
- #quit(id = nil) ⇒ Object
- #scrollTo(_locator) ⇒ Object
- #selected?(_locator, _drv = nil, _timeout = 30) ⇒ Boolean
- #setDebug(b) ⇒ Object
-
#setDimension(width = 1035, height = 768) ⇒ Object
Set innerWidth and innerHeight Ref.: /selenium-webdriver/lib/selenium/webdriver/common/window.rb o resize_to(width, height).
- #setLogLevel(l) ⇒ Object
- #setSauceStatus(id, status) ⇒ Object
- #setTimeout(s) ⇒ Object
- #start(*p) ⇒ Object
- #switch_frame(e, drv = nil) ⇒ Object
- #switch_into_frame(drv, id) ⇒ Object
- #tabUntil(opts) ⇒ Object
- #text(_locator, _drv = nil, _timeout = 30) ⇒ Object
- #title ⇒ Object
- #type(_locator, _text, _timeout = 30) ⇒ Object
- #type!(data) ⇒ Object
Constructor Details
#initialize(_logLevel = :warn) ⇒ Manager
Returns a new instance of Manager.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/browza/base/manager.rb', line 22 def initialize(_logLevel = :warn) @debug = false @driverList = [] @logger = Logging.logger(STDOUT) @logger.level = _logLevel @defaultTimeout = 30 @appModels=[] @defaultRetries = 2 @browserMgr = Browza::BrowzaMgr.new() end |
Instance Attribute Details
#appModels ⇒ Object
Returns the value of attribute appModels.
14 15 16 |
# File 'lib/browza/base/manager.rb', line 14 def appModels @appModels end |
#browserMgr ⇒ Object
Returns the value of attribute browserMgr.
19 20 21 |
# File 'lib/browza/base/manager.rb', line 19 def browserMgr @browserMgr end |
#browserType ⇒ Object
Returns the value of attribute browserType.
15 16 17 |
# File 'lib/browza/base/manager.rb', line 15 def browserType @browserType end |
#debug ⇒ Object
Returns the value of attribute debug.
20 21 22 |
# File 'lib/browza/base/manager.rb', line 20 def debug @debug end |
#defaultRetries ⇒ Object
Returns the value of attribute defaultRetries.
16 17 18 |
# File 'lib/browza/base/manager.rb', line 16 def defaultRetries @defaultRetries end |
#defaultTimeout ⇒ Object
Returns the value of attribute defaultTimeout.
17 18 19 |
# File 'lib/browza/base/manager.rb', line 17 def defaultTimeout @defaultTimeout end |
#driverList ⇒ Object
Returns the value of attribute driverList.
18 19 20 |
# File 'lib/browza/base/manager.rb', line 18 def driverList @driverList end |
#drv ⇒ Object
Returns the value of attribute drv.
13 14 15 |
# File 'lib/browza/base/manager.rb', line 13 def drv @drv end |
Instance Method Details
#_addDriver(d) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/browza/base/manager.rb', line 37 def _addDriver(d) @logger.debug __FILE__ + (__LINE__).to_s + " _addDriver(#{d})" if @debug @browserMgr.add(d) if !d.is_a?(Hash) @driverList << { :is_sauce => false, :drv => d } else @driverList << d end @driverList.last end |
#_getActionableElement(_locator, drv, _timeout = 30) ⇒ Object
874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 |
# File 'lib/browza/base/manager.rb', line 874 def _getActionableElement(_locator, drv, _timeout = 30) obj = nil begin drv.switch_to.default_content isDisplayed = Selenium::WebDriver::Wait.new(timeout: _timeout).until { obj = findLocator(_locator, drv) obj.is_a?(Selenium::WebDriver::Element) && obj.displayed? && obj.enabled? } rescue Selenium::WebDriver::Error::NoSuchElementError ; rescue Selenium::WebDriver::Error::TimeOutError ; end obj end |
#_getBrowserType(browserType) ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/browza/base/manager.rb', line 207 def _getBrowserType(browserType) t = browserType if browserType.match(/chrome/i) t = :chrome elsif browserType.match(/firefox/i) t = :firefox elsif browserType.match(/ie/i) t = :ie elsif browserType.match(/edge/i) t = :edge end t end |
#_getDriverIndex(id) ⇒ Object
371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/browza/base/manager.rb', line 371 def _getDriverIndex(id) i = 0 @driverList.each do |b| if b.has_key?(:id) && b[:id] == id return i end i += 1 end return nil end |
#_isBrowser?(drv, s) ⇒ Boolean
578 579 580 581 582 583 584 585 586 |
# File 'lib/browza/base/manager.rb', line 578 def _isBrowser?(drv, s) @logger.debug __FILE__ + (__LINE__).to_s + " _isBrowser?(#{drv.class}, #{s})" if drv.nil? drv=@drv end !drv.browser.to_s.match(s).nil? end |
#_parseLocator(_locator) ⇒ Object
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 |
# File 'lib/browza/base/manager.rb', line 491 def _parseLocator(_locator) locator = _locator if _locator.is_a?(String) if _locator.match(/^\s*(\/|\.)/i) locator = { :xpath => _locator } elsif _locator.match(/^\s*\#/i) locator = { :css => _locator } elsif _locator.match(/^\s*css\s*=\s*(.*)\s*$/) locator = { :css => _locator.match(/^\s*css\s*=\s*(.*)$/)[1].to_s } end end locator end |
#addModel(_a) ⇒ Object
174 175 176 177 |
# File 'lib/browza/base/manager.rb', line 174 def addModel(_a) @logger.debug __FILE__ + (__LINE__).to_s + " [addModel]: #{_a}" if @debug @appModels << Appmodel::Model.new(_a) end |
#browserName ⇒ Object
50 51 52 |
# File 'lib/browza/base/manager.rb', line 50 def browserName @driverList[0][:drv].browser.to_s end |
#click(_locator, _drv = nil, _timeout = 30) ⇒ Object
Browza.instance.click(‘page(sideNav).get(desktop)’)
921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 |
# File 'lib/browza/base/manager.rb', line 921 def click(_locator, _drv=nil, _timeout = 30) @logger.debug __FILE__ + (__LINE__).to_s + " click(#{_locator})" rc = false @driverList.each do |b| begin drv = b[:drv] obj = nil drv.switch_to.default_content isDisplayed = Selenium::WebDriver::Wait.new(timeout: _timeout).until { obj = findLocator(_locator, drv) obj.is_a?(Selenium::WebDriver::Element) && obj.displayed? && obj.enabled? } # obj = _getActionableElement(_locator, drv, _timeout) # drv.action.move_to(obj).perform scrollElementIntoMiddle = "var viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);" + "var elementTop = arguments[0].getBoundingClientRect().top;" + "window.scrollBy(0, elementTop-(viewPortHeight/2));"; # drv.execute_script(scrollElementIntoMiddle, obj) # drv.execute_script("arguments[0].scrollIntoView(true);", obj); @logger.debug __FILE__ + (__LINE__).to_s + " [click]: obj => #{obj.class} : #{isDisplayed}" if !obj.nil? && obj.is_a?(Selenium::WebDriver::Element) && obj.displayed? @logger.debug __FILE__ + (__LINE__).to_s + " clicked #{_locator}" obj.click rc = true end rescue Selenium::WebDriver::Error::UnknownError rescue => ex @logger.debug __FILE__ + (__LINE__).to_s + " #{ex.class} : #{_locator}" @logger.debug "Backtrace:\n\t#{ex.backtrace.join("\n\t")}" end end unless rc @logger.debug __FILE__ + (__LINE__).to_s + " WARN: unable to click #{_locator}" end @logger.debug __FILE__ + (__LINE__).to_s + " ==== [click]: #{_locator} = #{rc} ====" rc end |
#connectSauce(id, _caps = nil) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/browza/base/manager.rb', line 86 def connectSauce(id, _caps=nil) @logger.debug __FILE__ + (__LINE__).to_s + " connectSauce(#{id}, #{_caps})" if @debug runLocal = false if _caps.is_a?(String) && File.exist?(caps) caps = JSON.parse(File.read(caps), :symbolize_names => true) else caps = _caps.dup end if caps.has_key?('platform') tmpCaps = caps.clone if !ENV['SELENIUM_NAME'].nil? && (ENV['SELENIUM_NAME'].is_a?(String) && !ENV['SELENIUM_NAME'].empty?) tmpCaps['name'] = ENV['SELENIUM_NAME'].to_s elsif !tmpCaps.has_key?('name') tmpCaps['name'] = Time.now.strftime("%m%d%y_#{caps['browserType'].to_s}") end if caps['platform'].match(/\s*(linux|macOS|osx|os x|windows)/i) if caps.has_key?('browserType') || ENV['SELENIUM_BROWSER'] browserType = caps['browserType'] || ENV['SELENIUM_BROWSER'] @logger.debug " browserType: #{browserType}" if browserType.match(/edge/i) caps = Selenium::WebDriver::Remote::Capabilities.edge() elsif browserType.match(/chrome/i) caps = Selenium::WebDriver::Remote::Capabilities.chrome() elsif browserType.match(/firefox/i) caps = Selenium::WebDriver::Remote::Capabilities.firefox() elsif browserType.match(/ie/i) caps = Selenium::WebDriver::Remote::Capabilities.internet_explorer() elsif browserType.match(/safari/) caps = Selenium::WebDriver::Remote::Capabilities.safari() else raise "Browza::UnexpectedBrowser::#{browserType}" end end else runLocal = true browserType = caps['browserType'] || ENV['SELENIUM_BROWSER'] || 'safari' end tmpCaps.each_pair do |k, v| caps[k.to_s] = v end @logger.debug __FILE__ + (__LINE__).to_s + " caps => #{caps}" if @debug begin if runLocal @drv=Selenium::WebDriver.for browserType.to_s.to_sym, :desired_capabilities => caps else sauce_endpoint = "http://#{ENV['SAUCE_USERNAME']}:#{ENV['SAUCE_ACCESS_KEY']}@ondemand.saucelabs.com:80/wd/hub" @drv=Selenium::WebDriver.for :remote, :url => sauce_endpoint, :desired_capabilities => caps # The following print to STDOUT is useful when running on JENKINS with SauceLabs plugin # Reference: # https://wiki.saucelabs.com/display/DOCS/Setting+Up+Reporting+between+Sauce+Labs+and+Jenkins puts "SauceOnDemandSessionID=#{@drv.session_id} job-name=#{caps[:name]}" end _addDriver( { :id => id, :drv => @drv, :is_sauce => !runLocal }) rescue => ex @logger.fatal __FILE__ + (__LINE__).to_s + " #{ex.class} : #{ex}" @logger.fatal "Backtrace:\n\t#{ex.backtrace.join("\n\t")}" end caps end end |
#count ⇒ Object
54 55 56 |
# File 'lib/browza/base/manager.rb', line 54 def count @driverList.length end |
#createBrowser(*p) ⇒ Object
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 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
# File 'lib/browza/base/manager.rb', line 249 def createBrowser(*p) timeout = nil if ENV['SELENIUM_RESOLUTION'] @logger.debug " SELENIUM_RESOLUTION=#{ENV['SELENIUM_RESOLUTION']}" if @debug _width = ENV['SELENIUM_RESOLUTION'].match(/\s*(\d+)\s*x\s*(\d+)\s*$/)[1].to_s _height = ENV['SELENIUM_RESOLUTION'].match(/\s*(\d+)\s*x\s*(\d+)\s*$/)[2].to_s else _width = 1035 _height = 768 end @logger.debug __FILE__ + (__LINE__).to_s + " createBrowser() : width x height : #{_width}, #{_height}" if @debug _id = Time.now.to_i.to_s @logger.debug __FILE__ + (__LINE__).to_s + " SELENIUM_BROWSER : #{ENV['SELENIUM_BROWSER']}" if @debug @browserType = ENV['SELENIUM_BROWSER'] || 'chrome' @browserType = _getBrowserType(@browserType) if @debug @logger.debug __FILE__ + (__LINE__).to_s + " createBrowser(#{@browserType}) (isSymbol: #{@browserType.is_a?(Symbol)} : #{p.class.to_s}" end if p.is_a?(Array) && p.length > 0 if @debug @logger.debug __FILE__ + (__LINE__).to_s + " createBrowser() size: #{p.size} p[0]=#{p[0]} p[0].class=#{p[0].class} p[0].size=#{p[0].size} isSymbol(#{p[0].is_a?(Symbol)})" end if p.size == 1 if p[0].is_a?(Array) && p[0].size==1 && ( p[0][0].is_a?(Symbol) || p[0][0].is_a?(String) ) @browserType = p[0][0].to_s.to_sym elsif p[0].is_a?(Array) && p[0].size==1 && p[0][0].is_a?(Hash) @logger.debug __FILE__ + (__LINE__).to_s + " #{p[0]}" h = p[0][0] if h.has_key?(:browserType) @browserType = h[:browserType] end if h.has_key?(:width) && h.has_key?(:height) _width = h[:width] _height = h[:height] end if h.has_key?(:timeout) timeout = h[:timeout] end if h.has_key?(:id) _id = h[:id] end elsif p[0].is_a?(Symbol) || p[0].is_a?(String) @browserType = p[0].to_s.to_sym elsif p[0].is_a?(Hash) && !p[0].empty? @logger.debug __FILE__ + (__LINE__).to_s + " #{p[0]}" h = p[0] if h.has_key?(:browserType) @logger.debug __FILE__ + (__LINE__).to_s + " UPDTE" @browserType = h[:browserType] end if h.has_key?(:width) && h.has_key?(:height) _width = h[:width] _height = h[:height] end if h.has_key?(:id) _id = h[:id] end end end else @logger.debug __FILE__ + (__LINE__).to_s + " createBrowser without parms (width/height: #{_width}, #{_height})" end @logger.debug "Selenium::WebDriver.for #{@browserType} (isSymbol: #{@browserType.is_a?(Symbol)})" if @debug begin if timeout.nil? && ENV['SELENIUM_PROXY'].nil? @drv = Selenium::WebDriver.for @browserType else if ENV['SELENIUM_PROXY'] if @browserType.to_s.match(/firefox/i) @logger.debug "createBrowser() with proxy: #{ENV['SELENIUM_PROXY']}" profile = Selenium::WebDriver::Firefox::Profile.new proxy = Selenium::WebDriver::Proxy.new(http: "#{ENV['SELENIUM_PROXY']}") profile.proxy = proxy = Selenium::WebDriver::Firefox::Options.new(profile: profile) @drv = Selenium::WebDriver.for :firefox, options: end elsif client = Selenium::WebDriver::Remote::Http::Default.new client.read_timeout = timeout.to_i @drv = Selenium::WebDriver.for @browserType, http_client: client end puts __FILE__ + (__LINE__).to_s + " Set NET::TIMEOUT to #{timeout.to_s}" end rescue TypeError @logger.warn __FILE__ + (__LINE__).to_s + " See https://github.com/mozilla/geckodriver/issues/676" if @browserType == :firefox end _addDriver( { :drv => @drv, :is_sauce => false, :id => _id }) setDimension(_width, _height) end |
#deleteDriver(id) ⇒ Object
385 386 387 388 389 390 |
# File 'lib/browza/base/manager.rb', line 385 def deleteDriver(id) i = _getDriverIndex(id) unless i.nil? @driverList.delete_at(i) end end |
#displayed?(_locator, _drv = nil, _timeout = 30) ⇒ Boolean
1199 1200 1201 1202 |
# File 'lib/browza/base/manager.rb', line 1199 def displayed?(_locator, _drv=nil, _timeout = 30) obj = findLocator(_locator) obj.is_a?(Selenium::WebDriver::Element) && obj.displayed? end |
#findLocator(_locator, drv = nil) ⇒ Object
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 |
# File 'lib/browza/base/manager.rb', line 741 def findLocator(_locator, drv=nil) drv = @driverList[0][:drv] if drv.nil? @logger.debug __FILE__ + (__LINE__).to_s + " [findLocator]: #{_locator} sz: #{@appModels.length}" obj = nil _hit = nil if Appmodel::Model.isPageObject?(_locator) && @appModels.length > 0 i=0 @appModels.each do |m| @logger.debug __FILE__ + (__LINE__).to_s + " >> #{i}. #{m.class} => #{_locator}" begin ## # FRAMES ## pageObject = m.getPageElement(_locator) unless pageObject.nil? _hit = {} if pageObject.has_key?('frame') _hit['frame'] = pageObject['frame'] end if pageObject.has_key?('locator') _hit['locator'] = Appmodel::Model.toBy(pageObject['locator'], m) end @logger.debug __FILE__ + (__LINE__).to_s + " pageObject => #{pageObject}" break end rescue => ex @logger.warn "Error during processing: #{$!}" @logger.warn "Backtrace:\n\t#{ex.backtrace.join("\n\t")}" end end elsif _locator.is_a?(String) _hit = Appmodel::Model.parseLocator(_locator) elsif _locator.is_a?(Hash) _hit = { 'locator' => _locator[:css] } if _locator.has_key?(:css) _hit = { 'locator' => _locator['css'] } if _locator.has_key?('css') _hit = { 'locator' => _locator[:xpath] } if _locator.has_key?(:xpath) _hit = { 'locator' => _locator['xpath'] } if _locator.has_key?('xpath') _hit['frame'] = _locator[:frame] if _locator.has_key?(:frame) _hit['frame'] = _locator['frame'] if _locator.has_key?('frame') end @logger.debug __FILE__ + (__LINE__).to_s + " hit => #{_hit}" if _hit.is_a?(Hash) @defaultRetries.times { begin rcFrame = true if _hit.has_key?('frame') @logger.debug __FILE__ + (__LINE__).to_s + " [findLocator]: swtich_to_frame : #{_hit['frame']}" drv.switch_to.default_content rcFrame = switch_frame(_hit['frame'], drv) end if rcFrame && _hit.has_key?('locator') obj = getElement(_hit['locator'], drv, @defaultTimeout) if !obj.nil? break end end sleep(0.25) rescue => e @logger.debug __FILE__ + (__LINE__).to_s + " Exception: #{e.class}" ; end } else obj = getElement(Appmodel::Model.toBy(_locator), drv, @defaultTimeout) end @logger.debug __FILE__ + (__LINE__).to_s + " [return findLocator(#{_locator})] : #{_hit}" _hit.nil? ? _locator : _hit obj end |
#focusedText ⇒ Object
1204 1205 1206 1207 |
# File 'lib/browza/base/manager.rb', line 1204 def focusedText() activeElt = @drv.switch_to.active_element activeElt.attribute('text') end |
#focusedValue ⇒ Object
1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 |
# File 'lib/browza/base/manager.rb', line 1209 def focusedValue() v = nil begin activeElt = @drv.switch_to.active_element v = activeElt.attribute('value') rescue => ex @logger.warn __FILE__ + (__LINE__).to_s + " #{ex.class}" @logger.warn "Backtrace:\n\t#{ex.backtrace.join("\n\t")}" end v end |
#focusedValue?(s, _timeout = 10) ⇒ Boolean
1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 |
# File 'lib/browza/base/manager.rb', line 1222 def focusedValue?(s, _timeout=10) rc = false Selenium::WebDriver::Wait.new(timeout: _timeout).until { activeElt = @drv.switch_to.active_element _v = activeElt.attribute('value') if _v.match(/#{s}/) rc = true end rc } end |
#getCount(_locator, _drv = nil, _timeout = 30) ⇒ Object
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 |
# File 'lib/browza/base/manager.rb', line 1487 def getCount(_locator, _drv=nil, _timeout=30) rc=0 elts = getElements(_locator, _drv, _timeout) if !elts.nil? # hits = elts.select { |obj| obj.displayed? } rc = elts.length end rc.to_i end |
#getDate ⇒ Object
831 832 833 |
# File 'lib/browza/base/manager.rb', line 831 def getDate() return @driverList[0][:drv].execute_script('var s = new Date().toString(); return s') end |
#getDriver(id = nil) ⇒ Object
392 393 394 395 396 397 398 399 400 401 402 403 404 |
# File 'lib/browza/base/manager.rb', line 392 def getDriver(id=nil) if id.nil? return @driverList[0][:drv] end i = _getDriverIndex(id) unless i.nil? return @driverList[i][:drv] end nil end |
#getElement(_locator, drv = nil, _timeout = 30) ⇒ Object
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
# File 'lib/browza/base/manager.rb', line 541 def getElement(_locator, drv=nil, _timeout=30) @logger.debug __FILE__ + (__LINE__).to_s + " getElement(#{_locator})" rc = nil begin locator = _parseLocator(_locator) if drv.nil? drv=getDriver() end @logger.debug __FILE__ + (__LINE__).to_s + " getElement() => #{locator}" Selenium::WebDriver::Wait.new(timeout: _timeout).until { _obj = drv.find_element(locator) if _obj.displayed? rc = _obj end !rc.nil? } rescue Selenium::WebDriver::Error::TimeOutError @logger.debug __FILE__ + (__LINE__).to_s + " TimeOutError: #{locator}" rescue Selenium::WebDriver::Error::NoSuchElementError @logger.warn __FILE__ + (__LINE__).to_s + " NoSuchElementError : #{locator}" rescue => ex @logger.warn __FILE__ + (__LINE__).to_s + " #{ex.class}" @logger.warn "Error during processing: #{$!}" @logger.warn "Backtrace:\n\t#{ex.backtrace.join("\n\t")}" end rc end |
#getElements(_locator, drv = nil, _timeout = 30) ⇒ Object
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 |
# File 'lib/browza/base/manager.rb', line 510 def getElements(_locator, drv=nil, _timeout=30) rc = nil begin if drv.nil? drv=getDriver() end Selenium::WebDriver::Wait.new(timeout: _timeout).until { _obj = drv.find_elements(_parseLocator(_locator)) if !_obj.nil? rc = _obj end !rc.nil? } rescue Selenium::WebDriver::Error::NoSuchElementError @logger.info __FILE__ + (__LINE__).to_s + " NoSuchElementError : #{_locator}" rescue => ex @logger.warn "Error during processing: #{$!}" @logger.warn "Backtrace:\n\t#{ex.backtrace.join("\n\t")}" end rc end |
#getStyle(_locator, _attr) ⇒ Object
1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 |
# File 'lib/browza/base/manager.rb', line 1342 def getStyle(_locator, _attr) attr = nil begin obj = findLocator(_locator) attr = obj.style(_attr) rescue => ex ; end attr end |
#getText(_locator) ⇒ Object
1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 |
# File 'lib/browza/base/manager.rb', line 1355 def getText(_locator) @logger.debug __FILE__ + (__LINE__).to_s + " getText?(#{_locator})" rc = false begin obj = findLocator(_locator) @logger.debug __FILE__ + (__LINE__).to_s + " | obj : #{obj}" if !obj.nil? @logger.debug __FILE__ + (__LINE__).to_s + " | obj.text: #{obj.text}" rc = obj.text end rescue => ex @logger.warn __FILE__ + (__LINE__).to_s + " #{ex.class}" @logger.warn "Backtrace:\n\t#{ex.backtrace.join("\n\t")}" end @logger.debug __FILE__ + (__LINE__).to_s + " [return]: isText?(#{_locator}) : #{rc}" rc end |
#goto(url, id = nil) ⇒ Object
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 |
# File 'lib/browza/base/manager.rb', line 454 def goto(url, id=nil) @logger.debug __FILE__ + (__LINE__).to_s + " goto(#{url})" rc = false if id.nil? @driverList.each do |b| @logger.debug __FILE__ + (__LINE__).to_s + " => #{b}" b[:drv].navigate.to url rc = true end else getDriver(id).navigate.to url rc = true #getDriver().navigate.to url end rc end |
#hasStyle?(_locator, tag, expected = nil, _timeout = 30) ⇒ Boolean
1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 |
# File 'lib/browza/base/manager.rb', line 1501 def hasStyle?(_locator, tag, expected = nil, _timeout = 30) @logger.debug __FILE__ + (__LINE__).to_s + " hasStyle?(#{_locator})" rc = nil @driverList.each do |b| begin drv = b[:drv] @logger.debug __FILE__ + (__LINE__).to_s + " [hasStyle]: switch_to.default_content" drv.switch_to.default_content obj = findLocator(_locator, drv) isDisplayed = Selenium::WebDriver::Wait.new(timeout: _timeout).until { obj = findLocator(_locator, drv) obj.is_a?(Selenium::WebDriver::Element) } if !obj.nil? @logger.debug __FILE__ + (__LINE__).to_s + " style #{_locator}" rc = obj.style(tag) end rescue => ex @logger.warn __FILE__ + (__LINE__).to_s + " #{ex.class}" @logger.warn "Backtrace:\n\t#{ex.backtrace.join("\n\t")}" end end unless expected.nil? regex = Regexp.new(expected) rc = !regex.match(rc.to_s).nil? || (expected.to_s == rc.to_s) @logger.debug __FILE__ + (__LINE__).to_s + " WARN: unable to get style #{tag} for #{_locator}" end @logger.debug __FILE__ + (__LINE__).to_s + " hasStyle(#{_locator}, #{tag}) : #{rc.to_s}" rc end |
#highlight(_locator = nil, color = 'red', _drv = nil, _timeout = 30) ⇒ Object
973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 |
# File 'lib/browza/base/manager.rb', line 973 def highlight(_locator=nil, color='red', _drv=nil, _timeout=30) rc = false rgb = nil obj = nil if _locator.nil? _locator = @drv.switch_to.active_element end if _locator.is_a?(Selenium::WebDriver::Element) obj = _locator else obj = findLocator(_locator) end if !obj.nil? if color.match(/\s*blue/i) rgb='rgb(0, 0, 255)' elsif color.match(/\s*red/i) rgb='rgb(255, 0, 0)' elsif color.match(/\s*yellow/i) rgb='rgb(255, 255, 0)' elsif color.match(/\s*green/i) rgb='rgb(0, 255, 0)' elsif color.match(/\s*gray/i) rgb='rgb(128, 128, 128)' end border = 2 begin @drv.execute_script("hlt = function(c) { c.style.border='solid #{border}px #{rgb}'; }; return hlt(arguments[0]);", obj) rc=true rescue => ex @logger.warn __FILE__ + (__LINE__).to_s + " #{ex.class}" end end obj.is_a?(Selenium::WebDriver::Element) && rc end |
#hover(_locator) ⇒ Object
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 |
# File 'lib/browza/base/manager.rb', line 1015 def hover(_locator) rc = false obj = findLocator(_locator) if !obj.nil? begin @drv.action.move_to(obj).perform rc = true rescue => ex @logger.warn "Error during processing: #{$!} - #{ex.class}" @logger.warn "Backtrace:\n\t#{ex.backtrace.join("\n\t")}" end else @logger.debug __FILE__ + (__LINE__).to_s + " hover(#{_locator}) not found." end @logger.debug __FILE__ + (__LINE__).to_s + " hover(#{_locator}) : #{rc}" rc end |
#isChrome?(drv = nil) ⇒ Boolean
588 589 590 591 592 593 594 |
# File 'lib/browza/base/manager.rb', line 588 def isChrome?(drv=nil) if drv.nil? drv=@drv end !drv.browser.to_s.match(/\s*chrome/i).nil? end |
#isEdge(drv = nil) ⇒ Object
596 597 598 599 600 601 602 |
# File 'lib/browza/base/manager.rb', line 596 def isEdge(drv=nil) if drv.nil? drv=@drv end !drv.browser.to_s.match(/\s*edge/i).nil? end |
#isFirefox?(drv = nil) ⇒ Boolean
612 613 614 615 616 617 618 619 |
# File 'lib/browza/base/manager.rb', line 612 def isFirefox?(drv=nil) if drv.nil? drv = @driverList[0][:drv] end Browza::Manager.instance._isBrowser?(drv, 'firefox') end |
#isFocused?(_locator) ⇒ Boolean
1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 |
# File 'lib/browza/base/manager.rb', line 1236 def isFocused?(_locator) rc = false activeElt = @drv.switch_to.active_element obj = findLocator(_locator) if !obj.nil? rc = (activeElt == obj) end rc end |
#isIE(drv = nil) ⇒ Object
604 605 606 607 608 609 610 |
# File 'lib/browza/base/manager.rb', line 604 def isIE(drv=nil) if drv.nil? drv=@drv end !drv.browser.to_s.match(/\s*ie/i).nil? end |
#isNotDisplayed?(_locator, _timeout = 10) ⇒ Boolean
TODO: Proper handling of _timeout, instead of hack to globalize @defaultTimeout.
1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 |
# File 'lib/browza/base/manager.rb', line 1174 def isNotDisplayed?(_locator, _timeout=10) rc = false _saveDefault = @defaultTimeout _saveRetries = @defaultRetries @defaultTimeout = _timeout @defaultRetries = 1 i=0 begin while i < 4 && !rc rc = !displayed?(_locator, getDriver(), _timeout) i+=1 sleep 0.25 end rescue => ex i+=1 ; end @defaultRetries = _saveDefault @defaultTimeout = _saveDefault rc end |
#isNotVisible?(_locator, _timeout = 30) ⇒ Boolean
1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 |
# File 'lib/browza/base/manager.rb', line 1279 def isNotVisible?(_locator, _timeout = 30) obj = nil rc = nil begin @drv.switch_to.default_content if _locator.is_a?(Selenium::WebDriver::Element) obj = _locator rc = Selenium::WebDriver::Wait.new(timeout: _timeout).until { obj.displayed? } else rc = Selenium::WebDriver::Wait.new(timeout: _timeout).until { obj = findLocator(_locator, @drv) obj.is_a?(Selenium::WebDriver::Element) && obj.displayed? } end rescue Selenium::WebDriver::Error::TimeOutError rc = true end rc end |
#isText?(_locator, regex = nil) ⇒ Boolean
1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 |
# File 'lib/browza/base/manager.rb', line 1378 def isText?(_locator, regex=nil) @logger.debug __FILE__ + (__LINE__).to_s + " isText?(#{_locator}, #{regex})" rc = false begin obj = findLocator(_locator) @logger.debug __FILE__ + (__LINE__).to_s + " | obj : #{obj}" if !obj.nil? @logger.debug __FILE__ + (__LINE__).to_s + " | obj.text: #{obj.text}" expected = Regexp.new(regex) rc = !expected.match(obj.text).nil? || regex==obj.text end rescue => ex @logger.warn __FILE__ + (__LINE__).to_s + " #{ex.class}" @logger.warn "Backtrace:\n\t#{ex.backtrace.join("\n\t")}" end @logger.debug __FILE__ + (__LINE__).to_s + " [return]: isText?(#{_locator}, #{regex}) : #{rc}" rc end |
#isTitle?(regex) ⇒ Boolean
448 449 450 451 452 |
# File 'lib/browza/base/manager.rb', line 448 def isTitle?(regex) current_title = getDriver().title expected_title = Regexp.new(regex) !expected_title.match(current_title).nil? || regex==current_title end |
#isValue?(_locator, regex = nil, _timeout = 30) ⇒ Boolean
1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 |
# File 'lib/browza/base/manager.rb', line 1307 def isValue?(_locator, regex=nil, _timeout = 30) @logger.debug __FILE__ + (__LINE__).to_s + " isValue?(#{_locator}, #{regex})" rc = false begin expected = Regexp.new(regex) drv = @driverList[0][:drv] obj = nil isExists = Selenium::WebDriver::Wait.new(timeout: _timeout).until { obj = findLocator(_locator, drv) if obj.is_a?(Selenium::WebDriver::Element) rc = !expected.match(obj.attribute('value')).nil? || regex==obj.attribute('value') end rc } @logger.debug __FILE__ + (__LINE__).to_s + " | obj : #{obj} => #{isExists}" if false && !obj.nil? && isExists @logger.debug __FILE__ + (__LINE__).to_s + " | obj.value: #{obj.attribute('value')}" expected = Regexp.new(regex) rc = !expected.match(obj.attribute('value')).nil? || regex==obj.attribute('value') end rescue => ex @logger.warn __FILE__ + (__LINE__).to_s + " #{ex.class}" @logger.warn "Backtrace:\n\t#{ex.backtrace.join("\n\t")}" end @logger.debug __FILE__ + (__LINE__).to_s + " [return]: isValue?(#{_locator}, #{regex}) : #{rc}" rc end |
#isVisible?(_locator, expected = true, _timeout = 30) ⇒ Boolean
1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 |
# File 'lib/browza/base/manager.rb', line 1252 def isVisible?(_locator, expected = true, _timeout = 30) obj = nil rc = nil begin @drv.switch_to.default_content if _locator.is_a?(Selenium::WebDriver::Element) obj = _locator rc = Selenium::WebDriver::Wait.new(timeout: _timeout).until { obj.displayed? } else rc = Selenium::WebDriver::Wait.new(timeout: _timeout).until { obj = findLocator(_locator, @drv) obj.is_a?(Selenium::WebDriver::Element) && obj.displayed? } end rescue Selenium::WebDriver::Error::TimeOutError rc = false end @logger.debug __FILE__ + (__LINE__).to_s + " isVisible?(#{_locator}) : #{rc}" rc == expected end |
#maximize ⇒ Object
203 204 205 |
# File 'lib/browza/base/manager.rb', line 203 def maximize() getDriver().manage.window.maximize end |
#navigate(*p) ⇒ Object
def navigate(url, id=nil)
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
# File 'lib/browza/base/manager.rb', line 475 def navigate(*p) rc=false if p.is_a?(Array) if p.length == 1 @logger.debug __FILE__ + (__LINE__).to_s + " navigate(#{p[0].to_s}" rc = goto(p[0].to_s) elsif p.length == 2 rc = goto(p[0], p[1]) end end rc end |
#press(*p) ⇒ Object
press(‘enter’) press(‘tab’, 5) press(‘page(main).get(button)’, ‘enter’)
1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 |
# File 'lib/browza/base/manager.rb', line 1408 def press(*p) rc = nil if p.length == 1 rc = pressKey(p[0], 1) elsif p.length == 2 if p[1].is_a?(Integer) || p[1].to_s.match(/^\s*\d+$/) rc = pressKey(p[0], p[1].to_i) else rc = type(p[0], p[1]) end else raise "BROWZA::Press::Unexpected" end rc end |
#pressKey(k, n = 1, _delay = 0.25) ⇒ Object
1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 |
# File 'lib/browza/base/manager.rb', line 1428 def pressKey(k, n = 1, _delay = 0.25) rc = 0 begin n.times { if k.match(/^\s*(tab|__tab__)\s*$/i) activeElt = @drv.switch_to.active_element n.times { activeElt.send_keys(:tab); rc+=1; } break; elsif k.match(/^\s*clear\s*$/) activeElt = @drv.switch_to.active_element activeElt.clear elsif k.match(/^\s*^enter\s*$/i) activeElt = @drv.switch_to.active_element activeElt.send_keys(:enter) elsif k.match(/^\s*(down|arrow_down|down_arrow|__down__)\s*/) n.times { activeElt = @drv.switch_to.active_element; activeElt.send_keys(:arrow_down); sleep _delay; rc+=1 } return rc; elsif k.match(/^\s*(space|__space__)\s*$/i) activeElt = @drv.switch_to.active_element n.times { activeElt.send_keys(:space); sleep _delay; rc+=1 } break elsif k.match(/^\s*(up|arrow_up|up_arrow|__up__)\s*$/) n.times { activeElt = @drv.switch_to.active_element; activeElt.send_keys(:arrow_up); sleep _delay; rc+=1 } return rc; elsif k.match(/^\s*escape\s*$/i) activeElt = @drv.switch_to.active_element activeElt.send_keys(:escape) elsif k.match(/^\s*page_down\s*/i) n.times { activeElt = @drv.switch_to.active_element; @drv.action.send_keys(:page_down).perform; sleep _delay; rc+=1 } break elsif k.match(/^\s*__SHIFT_TAB__\s*$/i) @drv.action.key_down(:shift).send_keys(:tab).perform @drv.action.key_up(:shift).perform else break end rc += 1 } rescue => ex ; end rc end |
#quit(id = nil) ⇒ Object
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 |
# File 'lib/browza/base/manager.rb', line 407 def quit(id=nil) if id.nil? @browserMgr.getBrowsers().each do |b| begin if b[:is_sauce] job_id = b[:drv].session_id if b.has_key?(:status) SauceWhisk::Jobs.change_status job_id, b[:status] end end @logger.debug __FILE__ + (__LINE__).to_s + " quit : #{b[:id]}" @logger.debug __FILE__ + (__LINE__).to_s + " b.methods => #{b[:drv].methods.sort}" b[:drv].quit rescue => ex @logger.fatal __FILE__ + (__LINE__).to_s + " #{ex.class} #{ex.}" @logger.warn "Backtrace:\n\t#{ex.backtrace.join("\n\t")}" end end @browserMgr.clear() @driverList=[] else @logger.debug __FILE__ + (__LINE__).to_s + " quit(#{id}" getDriver(id).quit deleteDriver(id) end end |
#scrollTo(_locator) ⇒ Object
895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 |
# File 'lib/browza/base/manager.rb', line 895 def scrollTo(_locator) drv = @driverList[0][:drv] obj = findLocator(_locator) if !obj.nil? scrollElementIntoMiddle = "var viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);" + "var elementTop = arguments[0].getBoundingClientRect().top;" + "window.scrollBy(0, elementTop-(viewPortHeight/2) + 150);"; drv.execute_script("arguments[0].scrollIntoView(true);", obj); # drv.action.move_to(obj).perform # drv.execute_script(scrollElementIntoMiddle, obj) end end |
#selected?(_locator, _drv = nil, _timeout = 30) ⇒ Boolean
1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 |
# File 'lib/browza/base/manager.rb', line 1476 def selected?(_locator, _drv=nil, _timeout=30) rc=false # obj=getElement(findLocator(_locator), _drv, _timeout) obj = findLocator(_locator) if !obj.nil? rc=obj.selected? end rc end |
#setDebug(b) ⇒ Object
33 34 35 |
# File 'lib/browza/base/manager.rb', line 33 def setDebug(b) @debug = b end |
#setDimension(width = 1035, height = 768) ⇒ Object
Set innerWidth and innerHeight Ref.: /selenium-webdriver/lib/selenium/webdriver/common/window.rb o resize_to(width, height)
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/browza/base/manager.rb', line 183 def setDimension(width = 1035, height = 768) @logger.debug __FILE__ + (__LINE__).to_s + " setDimension(#{width}, #{height}) count:#{@driverList.length}" if @debug begin i=0 @driverList.each do |b| target_size = Selenium::WebDriver::Dimension.new(width.to_i, height.to_i) if b[:drv] && (b[:drv].is_a?(Selenium::WebDriver) || b[:drv].is_a?(Selenium::WebDriver::Driver)) b[:drv].manage.window.size = target_size else @logger.warn __FILE__ + (__LINE__).to_s + " Attempt to access driver failed. (#{b})" end end rescue => ex @logger.warn __FILE__ + (__LINE__).to_s + " browser[#{i}]: #{ex.class}" @logger.warn __FILE__ + (__LINE__).to_s + " Error during processing: #{$!}" @logger.warn " Backtrace:\n\t#{ex.backtrace.join("\n\t")}" end end |
#setLogLevel(l) ⇒ Object
165 166 167 168 |
# File 'lib/browza/base/manager.rb', line 165 def setLogLevel(l) @logger.debug __FILE__ + (__LINE__).to_s + " setLogLevel(#{l})" @logger.level = l end |
#setSauceStatus(id, status) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/browza/base/manager.rb', line 58 def setSauceStatus(id, status) rc = false @logger.debug __FILE__ + (__LINE__).to_s + " setSauceStatus(#{id}, #{status})" if @debug if (ENV['SELENIUM_RUN'] && ENV['SELENIUM_RUN'].match(/local/i)) || (ENV['SELENIUM_PLATFORM'] && ENV['SELENIUM_PLATFORM'].match(/local/i)) @logger.debug __FILE__ + (__LINE__).to_s + " setSauceStatus() - ignored (running locally)" return nil end begin drv = @browserMgr.getDriver(id) unless drv.nil? job_id = drv.session_id SauceWhisk::Jobs.change_status job_id, status rc = true end rescue => ex @logger.fatal __FILE__ + (__LINE__).to_s + " #{ex.class}" @logger.fatal "Backtrace:\n\t#{ex.backtrace.join("\n\t")}" end rc end |
#setTimeout(s) ⇒ Object
170 171 172 |
# File 'lib/browza/base/manager.rb', line 170 def setTimeout(s) @defaultTimeout = s end |
#start(*p) ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/browza/base/manager.rb', line 224 def start(*p) if (ENV['SELENIUM_RUN'] && ENV['SELENIUM_RUN'].match(/local/i)) || ENV['SELENIUM_PLATFORM'].match(/local/i) return createBrowser(p) else @logger.debug __FILE__ + (__LINE__).to_s + " connectSauce() => #{p} #{p.class} #{p.size}" if @debug if p.size == 0 caps = {} caps['name'] = ENV['SELENIUM_NAME'] caps['platform'] = ENV['SELENIUM_PLATFORM'] caps['browserType'] = ENV['SELENIUM_BROWSER'] caps['screenResolution'] = ENV['SELENIUM_RESOLUTION'] caps['version'] = ENV['SELENIUM_VERSION'] ENV['SELENIUM_RUN']='sauce' if !ENV['SAUCE_TUNNEL_ID'].nil? caps['tunnel-identifier'] = ENV['SAUCE_TUNNEL_ID'].to_s end connectSauce(caps['name'], caps) end end end |
#switch_frame(e, drv = nil) ⇒ Object
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 |
# File 'lib/browza/base/manager.rb', line 686 def switch_frame(e, drv=nil) rc = true drv = @driverList[0][:drv] if drv.nil? @logger.debug __FILE__ + (__LINE__).to_s + "\n\n== self.switch_frame(#{e}) ==" frames=nil if e.is_a?(Hash) && e.has_key?('page') && e['page'].has_key?('frames') @logger.debug __FILE__ + (__LINE__).to_s + " frames => #{e['page']['frames']}"; frames=e['page']['frames'] elsif e.is_a?(String) frames=e end if !frames.nil? @logger.debug __FILE__ + (__LINE__).to_s + " [self.switch_frame]: frames => #{frames}"; # frame_list=frames.split(/(frame\(.*\))\.(?=[\w])/) frame_list=frames.split(/\.(?=frame)/) @logger.debug __FILE__+ (__LINE__).to_s + " [switch_frame]: default_content" drv.switch_to.default_content frame_list.each do |_f| @logger.debug __FILE__ + (__LINE__).to_s + " processing #{_f}" if !_f.empty? _id = _f.match(/frame\((.*)\)/)[1] @logger.debug __FILE__ + (__LINE__).to_s + " [self.switch_frame]: switch_to.frame #{_id}" # Swtich based on browser type if isChrome?(drv) || !@driverList[0][:is_sauce]# 5150|| isFirefox?(drv) if switch_into_frame(drv, _id).nil? @logger.debug __FILE__ + (__LINE__).to_s + " Frame with name/id #{_id} not found" rc = false break else @logger.debug __FILE__ + (__LINE__).to_s + " Sucessfully switched frame into #{_id}" end else @logger.debug __FILE__ + (__LINE__).to_s + " [firefox]: switch_to.frame #{_id}" drv.switch_to.frame _id end end end end rc end |
#switch_into_frame(drv, id) ⇒ Object
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 |
# File 'lib/browza/base/manager.rb', line 622 def switch_into_frame(drv, id) @logger.debug __FILE__ + (__LINE__).to_s + "[enter]: switch_into_frame(#{drv.class}, #{id})" _fcnId = '[switch_into_frame]' hit = nil # _addDriver( { :id => id, :drv => @drv, :is_sauce => true }) if isChrome?(drv) || !@driverList[0][:is_sauce] # 5150|| isFirefox?(drv) # drv.switch_to.default_content @logger.debug __FILE__ + (__LINE__).to_s + "#{_fcnId}: switch on Chrome browser" bframes = drv.find_elements(:xpath, '//iframe') @logger.debug __FILE__ + (__LINE__).to_s + "#{_fcnId}: //iframe : size #{bframes.size}" if bframes.size == 0 bframes = drv.find_elements(:xpath, '//frame') @logger.debug __FILE__ + (__LINE__).to_s + "#{_fcnId}: //frame : #{bframes.size}" end for i in 0 .. bframes.size - 1 begin _tag = bframes[i].attribute('name') if !_tag.nil? && _tag.empty? _tag = bframes[i].attribute('id') end @logger.debug __FILE__ + (__LINE__).to_s + "[switch_into_frame.chrome]: <tag, id> :: <#{_tag}, #{id} >" if !_tag.empty? && id==_tag hit = bframes[i] drv.switch_to.frame hit @logger.debug __FILE__ + (__LINE__).to_s + "#{_fcnId}: swtichframe to #{i} - #{_tag}" break end rescue => ex @logger.warn "Error during processing: #{$!}" @logger.warn "Backtrace:\n\t#{ex.backtrace.join("\n\t")}" end end else # Firefox, IE @logger.debug __FILE__ + (__LINE__).to_s + "[switch_into_frame]: drv.switch_to.frame(#{id.to_s}"; hit = drv.switch_to.frame(id.to_s.strip) @logger.debug __FILE__ + (__LINE__).to_s + " [switch_into_frame]: #{hit} - #{id}" end @logger.debug __FILE__ + (__LINE__).to_s + " switch_into_frame(#{id}) => #{hit}" hit end |
#tabUntil(opts) ⇒ Object
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 |
# File 'lib/browza/base/manager.rb', line 1037 def tabUntil( opts ) defaults = { :enableHighlight => false, :verbose => false, :max => 25 } opts = defaults.merge(opts) if opts[:verbose] puts "[tabUntil]: " + opts.to_s end # startObj = @drv.switch_to.active_element i = 0 while i < opts[:max].to_i do @drv.action.send_keys(:tab).perform obj = @drv.switch_to.active_element if obj.is_a?(Selenium::WebDriver::Element) && obj.displayed? puts "#{i}. " + obj.text.to_s + " : " + obj.attribute('value').to_s if opts[:verbose] i += 1 end if false && obj == startObj puts ".. wrapped" break end if opts[:enableHighlight] highlight(obj) end end puts "[tabUntil]: total: #{i.to_s}" end |
#text(_locator, _drv = nil, _timeout = 30) ⇒ Object
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 |
# File 'lib/browza/base/manager.rb', line 836 def text(_locator, _drv = nil, _timeout = 30) rc = nil 2.times { |i| @driverList.each do |b| begin drv = b[:drv] obj = nil drv.switch_to.default_content isDisplayed = Selenium::WebDriver::Wait.new(timeout: _timeout).until { obj = findLocator(_locator, drv) obj.is_a?(Selenium::WebDriver::Element) && obj.displayed? && obj.enabled? } if !obj.nil? && isDisplayed && obj.is_a?(Selenium::WebDriver::Element) @logger.debug __FILE__ + (__LINE__).to_s + " clicked #{_locator}" rc = obj.text end break rescue Selenium::WebDriver::Error::TimeOutError puts __FILE__ + (__LINE__).to_s + " retry: #{i} locator:#{_locator}" rescue => ex puts __FILE__ + (__LINE__).to_s + " #{ex.class}" puts "#{ex.class}" puts "Backtrace:\n\t#{ex.backtrace.join("\n\t")}" end end } rc end |
#title ⇒ Object
444 445 446 |
# File 'lib/browza/base/manager.rb', line 444 def title() getDriver().title.to_s end |
#type(_locator, _text, _timeout = 30) ⇒ Object
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 |
# File 'lib/browza/base/manager.rb', line 1075 def type(_locator, _text, _timeout=30) rc = false # obj = getElement(findLocator(_locator), _drv, _timeout) if _locator.match(/(active|focused)/i) obj = @drv.switch_to.active_element else obj = findLocator(_locator) end if !obj.nil? if _text.match(/\s*__CLEAR__\s*$/i) _text = :clear elsif _text.match(/\s*__DOWN__\s*$/i) _text = :arrow_down elsif _text.match(/\s*__ENTER__\s*$/i) _text = :enter elsif _text.match(/\s*__LEFT__\s*$/i) _text = :arrow_left elsif _text.match(/\s*__RIGHT__\s*$/i) _text = :arrow_right elsif _text.match(/\s*__UP__\s*$/i) _text = :arrow_up elsif _text.match(/\s*__TAB__\s*$/i) _text = :tab elsif _text.match(/\s*__SHIFT_TAB__\s*$/i) @drv.action.key_down(:shift).send_keys(:tab).perform @drv.action.key_up(:shift).perform rc = true end unless rc obj.send_keys(_text) rc=true end end rc end |
#type!(data) ⇒ Object
1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 |
# File 'lib/browza/base/manager.rb', line 1118 def type!(data) rc = { :length => nil, :comment => nil, :data => data } drv = Browza::Manager.instance.getDriver() if drv.is_a?(Selenium::WebDriver::Driver) obj = drv.switch_to.active_element if obj.is_a?(Selenium::WebDriver::Element) && Browza::Manager.instance.isVisible?(obj) Browza::Manager.instance.highlight(obj) begin jsCmd = "hlt = function(c) { arguments[0].value = '#{data}'; }; return hlt(arguments[0]);" jsCmd = "return arguments[0].value = '#{data}'" puts __FILE__ + (__LINE__).to_s + " Data.lines : #{data.lines.count}" if data.lines.count > 1 jsCmd = "return arguments[0].value = '#{data.gsub("\n", "\t")}'" end drv.execute_script(jsCmd, obj) rc[:length] = data.length rc[:comment] = 'JSDOM' rescue Selenium::WebDriver::Error::JavascriptError Browza::Manager.instance.type('focused', data) rc[:comment] = 'Typed:JavaScriptError' rc[:length] = data.length rescue Selenium::WebDriver::Error::UnknownError => ex puts "#{ex.class} : #{ex..to_s}" if ex..to_s.match(/SyntaxError: Invalid or unexpected token/) rc[:comment] = "execute_script::SyntaxError - unexpected token" puts __FILE__ + (__LINE__).to_s + " Invalid Cmd => #{jsCmd}" else rc[:comment] = ex.class.to_s puts "Backtrace:\n\t#{ex.backtrace.join("\n\t")}" puts "Data => #{data}"; end Browza::Manager.instance.type('focused', data) rc[:length] = data.length end end end @logger.debug __FILE__ + (__LINE__).to_s + " type!(#{data}) : rc:#{rc}" rc end |