class Scoutui::Base::QBrowser
Attributes
driver[RW]
Public Class Methods
click(element)
click to toggle source
# File lib/scoutui/base/q_browser.rb, line 920 def self.click(element) rc=false Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " click(#{element})" if element.is_a?(Selenium::WebDriver::Element) begin element.click rc=true rescue => ex Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Error during processing: #{$!}" Scoutui::Logger::LogMgr.instance.debug "Backtrace:\n\t#{ex.backtrace.join("\n\t")}" end end rc end
existsAlert?(drv)
click to toggle source
# File lib/scoutui/base/q_browser.rb, line 94 def self.existsAlert?(drv) rc=false begin alert=drv.switch_to.alert if alert.is_a?(Selenium::WebDriver::Alert) rc=true end rescue Selenium::WebDriver::Error::NoSuchAlertError ; rescue Selenium::WebDriver::Error::WebDriverError # Support for phantomjs/ghostdriver per switch_to.alert() ; end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " existsAlert?() => #{rc}" rc end
findElement(drv, _locator, _frames, _timeout=nil)
click to toggle source
# File lib/scoutui/base/q_browser.rb, line 664 def self.findElement(drv, _locator, _frames, _timeout=nil) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " findElement(#{_locator}, #{Scoutui::Commands::Utils.instance.getFrameSearch})" if Scoutui::Commands::Utils.instance.isSwitchFrame?() Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " FrameSwitch" e={ 'page' => { 'frames' => Scoutui::Commands::Utils.instance.getFrameSearch() } } switch_frame(drv, e) obj = Scoutui::Base::QBrowser.getObject(drv, _locator, _timeout) elsif Scoutui::Commands::Utils.instance.isFrameSearch? Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " isFrameSearch" hits = Scoutui::Base::QBrowser.frame_getObject(drv, _locator, _timeout) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " hits => #{hits.class} : #{hits}" if hits.is_a?(Array) && !hits.empty? obj=hits[0] elsif hits.is_a?(Selenium::WebDriver::Element) obj=hits end else Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Analyze locator : #{_locator}" _parsed = Scoutui::Base::QBrowser.parseLocator(_locator) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " _parsed(#{_locator}) => #{_parsed}" if _parsed.has_key?('frame') && _parsed.has_key?('locator') obj = Scoutui::Base::QBrowser.findElementwithinFrame(drv, _parsed['locator'], _parsed['frame'], _timeout) else obj = Scoutui::Base::QBrowser.getObject(drv, _locator, _timeout) end end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " findElement(#{_frames}, #{_locator}) => #{obj}" obj end
findElements(opts)
click to toggle source
5150
# File lib/scoutui/base/q_browser.rb, line 446 def self.findElements(opts) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " findElements(#{opts})" driver=opts[:driver] locator=opts[:locator] locateBy=:xpath hits=nil locator = Scoutui::Base::UserVars.instance.normalize(locator) _parsed = Scoutui::Base::QBrowser.parseLocator(locator) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " #{locator} ==> #{_parsed}" if locator.match(/^\s*css\s*\=\s*/i) locateBy = :css locator = locator.match(/css\s*\=\s*(.*)/i)[1].to_s elsif locator.match(/^#/i) locateBy = :css end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " driver : #{driver.class}" Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " locator : #{locator}" begin _timeout=Scoutui::Commands::Utils.instance.getTimeout Selenium::WebDriver::Wait.new(timeout: _timeout).until { hits=driver.find_elements( locateBy => locator) } rescue => ex Scoutui::Logger::LogMgr.instance.warn __FILE__ + (__LINE__).to_s + " #{ex.class}" Scoutui::Logger::LogMgr.instance.warn ex.backtrace end hits end
findElementwithinFrame(drv, _locator, _frames, _timeout=nil)
click to toggle source
# File lib/scoutui/base/q_browser.rb, line 566 def self.findElementwithinFrame(drv, _locator, _frames, _timeout=nil) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " frameElementWithinFrame(#{_locator}, #{_frames}" # 5150 obj=nil if _frames.nil? obj=findElement(drv, _locator, _frames, _timeout) else # Switch to default window drv.switch_to.default_content if switch_frame(drv, _frames) (0..3).each do |_i| obj = Scoutui::Base::QBrowser.getObject(drv, _locator, _timeout) if !obj.nil? break end end end end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " [return]:frameElementsWithinFrame(#{_locator}, #{_frames}) => #{obj.class}" obj end
frame_getObject(drv, _locator, _timeout=nil)
click to toggle source
# File lib/scoutui/base/q_browser.rb, line 708 def self.frame_getObject(drv, _locator, _timeout=nil) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " [enter]:frame_getObject : #{_locator}" rc = Array.new() frames = drv.find_elements(:xpath, '//iframe') if frames.size == 0 frames = drv.find_elements(:xpath, '//frame') end if frames.size > 0 rc.concat frames end _obj = getObject(drv, _locator, _timeout) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " frames => #{frames} : #{_obj}" if _obj.nil? || (_obj.is_a?(Array) && _obj.empty?) for i in 0 .. (frames.size - 1) _madeSwitch=false begin _tag = frames[i].attribute('name') if _tag.empty? _tag = frames[i].attribute('id') end if _tag.empty? _tag = i end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Process frame[#{i}] : #{_tag}" # https://bugs.chromium.org/p/chromedriver/issues/detail?id=107 if drv.browser.to_s.match(/chrome/) drv.switch_to.frame frames[i] else Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " switch_to.frame #{_tag}" drv.switch_to.frame _tag end _madeSwitch=true # Recurse into sub-frames _hits = frame_getObject(drv, _locator, 3) rescue => ex Scoutui::Logger::LogMgr.instance.debug "Error during processing: #{$!}" Scoutui::Logger::LogMgr.instance.debug "Backtrace:\n\t#{ex.backtrace.join("\n\t")}" end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " hits => #{_hits}" if _hits.is_a?(Array) && _hits.size > 0 _obj=_hits[0] break elsif _hits.is_a?(Selenium::WebDriver::Element) _obj = _hits break end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " switch_to.parent_frame()" drv.switch_to.parent_frame if _madeSwitch end end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " _obj => #{_obj}" _obj end
getElement(drv, _locator, _frames, _timeout=nil)
click to toggle source
# File lib/scoutui/base/q_browser.rb, line 381 def self.getElement(drv, _locator, _frames, _timeout=nil) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + "== getElement(#{_locator}) ==" _isntStale=true obj = Scoutui::Base::QBrowser.findElement(drv, _locator, _frames, _timeout) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " | locator : #{_locator}" Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " | obj : #{obj}" Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " | stale : " + Scoutui::Base::QBrowser.isStale?(obj).to_s if obj.is_a?(Selenium::WebDriver::Element) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " | displayed : " + obj.displayed?.to_s Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " | enabled : " + obj.enabled?.to_s end cnt=0 if obj.is_a?(Selenium::WebDriver::Element) && Scoutui::Base::QBrowser.isStale?(obj) && !_locator.nil? _isntStale=false (0..7).each do |i| cnt+=1 begin wait = Selenium::WebDriver::Wait.new(:timeout => Scoutui::Commands::Utils.instance.getTimeout) _isntStale = wait.until { _rc=Scoutui::Base::QBrowser.isStale?(obj) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " stale(#{_locator}) : #{_rc}" if _rc obj = Scoutui::Base::QBrowser.findElement(drv, _locator, _frames, _timeout) end !_rc } rescue Selenium::WebDriver::Error::TimeOutError ; end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " #{i} ==> stale(#{_locator}) : #{_isntStale}" if !_isntStale Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " #{i} => obj is STALE : #{_locator}" obj = Scoutui::Base::QBrowser.findElement(drv, _locator, _frames, _timeout) else break end end end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " getElement(#{_locator}) : #{obj}, cnt:#{cnt}, isntStale:#{_isntStale}" obj end
getFirstObject(drv, _locator, _timeout=nil)
click to toggle source
# File lib/scoutui/base/q_browser.rb, line 116 def self.getFirstObject(drv, _locator, _timeout=nil) if existsAlert?(drv) Scoutui::Logger::LogMgr.instance.info __FILE__ + (__LINE__).to_s + " ALERT currently exists!"; # STDIN.gets() return nil end if _timeout.nil? _timeout = Scoutui::Utils::TestUtils.instance.getDefaultWait end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " getFirstObject(#{_locator}, #{_timeout})" if _timeout > 30 Scoutui::Logger::LogMgr.instance.warn __FILE__ + (__LINE__).to_s + " A #{_timeout} second timeout is set high, may slow down tests" end rc=nil locator=_locator begin locateBy=:xpath if _locator.match(/^css\=/i) locateBy = :css locator = _locator.match(/css\=(.*)/i)[1].to_s elsif _locator.match(/^#/i) locateBy = :css end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " locator => #{locator.to_s}" if Scoutui::Utils::TestUtils.instance.isDebug? Selenium::WebDriver::Wait.new(timeout: _timeout).until { drv.find_elements(locateBy => locator).size > 0 } rc=drv.find_elements(locateBy => locator)[0] rescue => ex Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " #{$!} - #{ex.message} getFirstObject.Exception: #{locator.to_s} - #{ex}" ; end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " #{_locator} => #{rc}" rc end
getObject(drv, obj, _timeout=nil)
click to toggle source
# File lib/scoutui/base/q_browser.rb, line 793 def self.getObject(drv, obj, _timeout=nil) if obj.nil? Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " getObject() - null obj passed." return nil end if _timeout.nil? _timeout = Scoutui::Utils::TestUtils.instance.getDefaultWait end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " getObject(#{obj}) class:#{obj.class.to_s} hash : #{obj.is_a?(Hash)}" if Scoutui::Utils::TestUtils.instance.isDebug? rc=nil visible_when=nil locator=obj locateBy=:xpath locator=nil _frame=nil begin if obj.is_a?(Hash) if obj.has_key?('visible_when') visible_when=!obj['visible_when'].match(/always/i).nil? end locator = obj['locator'].to_s elsif !obj.match(/^page\([\w\d]+\)/).nil? elt = Scoutui::Utils::TestUtils.instance.getPageElement(obj) if elt.is_a?(Hash) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " JSON or Hash => #{elt}" if Scoutui::Utils::TestUtils.instance.isDebug? locator = elt['locator'].to_s _frame = elt['frame'] if elt.has_key?('frame') else locator=elt.to_s end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Process page request #{obj} => #{locator}" if Scoutui::Utils::TestUtils.instance.isDebug? else locator=obj.to_s end if !locator.match(/\$\{.*\}/).nil? _x = Scoutui::Base::UserVars.instance.get(locator) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " User specified user var : #{locator} ==> #{_x}" if !_x.nil? if !_x.match(/^page\([\w\d]+\)/).nil? elt = Scoutui::Utils::TestUtils.instance.getPageElement(_x) if elt.is_a?(Hash) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " JSON or Hash => #{elt}" if Scoutui::Utils::TestUtils.instance.isDebug? locator = elt['locator'].to_s else locator=elt.to_s end else # Update locator to the defined user var. locator = _x end end end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " locator : #{locator}" if Scoutui::Utils::TestUtils.instance.isDebug? if locator.match(/^\s*css\s*\=\s*/i) locateBy = :css locator = locator.match(/css\s*\=\s*(.*)/i)[1].to_s elsif locator.match(/^#/i) locateBy = :css # locator = locator.match(/\#(.*)/)[1].to_s end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " By => #{locateBy.to_s}" Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Frame => #{_frame.to_s}" Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Locator => #{locator}" Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Visible_When => #{visible_when}" Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Timeout => #{_timeout}" current_window=drv.window_handle if !_frame.nil? switch_frame(drv, _frame) end Selenium::WebDriver::Wait.new(timeout: _timeout).until { rc=drv.find_element( locateBy => locator) } ## The following line would render the found element as Stale (TBD). ## The caller is responsible to switching (back) to the target window. if false && !_frame.nil? drv.switch_to.window(current_window) end rescue Selenium::WebDriver::Error::TimeOutError Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " TimeoutError: #{locator} time out." rc=nil rescue Selenium::WebDriver::Error::NoSuchElementError Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " NoSuchElementError: #{locator} not found." rc=nil rescue => ex Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Error during processing: #{$!}" Scoutui::Logger::LogMgr.instance.debug "Backtrace:\n\t#{ex.backtrace.join("\n\t")}" end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " getObject(#{locator}) => #{rc.to_s}" if Scoutui::Utils::TestUtils.instance.isDebug? rc end
hasParent?(element, parent_xpath)
click to toggle source
# File lib/scoutui/base/q_browser.rb, line 481 def self.hasParent?(element, parent_xpath) parent=nil if element.is_a?(Selenium::WebDriver::Element) begin parent = element.find_element(:xpath, parent_xpath) rescue Selenium::WebDriver::Error::NoSuchElementError ; end end parent end
highlight(drv, locator, style={"color" => 'rgb(255, 16, 16)', "border" => 2}, fAncestors=true)
click to toggle source
# File lib/scoutui/base/q_browser.rb, line 940 def self.highlight(drv, locator, style={"color" => 'rgb(255, 16, 16)', "border" => 2}, fAncestors=true) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " highLight(#{locator} with style #{style})" rc=false # element = find_element(method, locator) if locator.is_a?(Selenium::WebDriver::Element) element = locator else element = getObject(drv, locator) end if element.nil? return rc end if style.has_key?("color") color=style.has_key?("color")? style["color"] : 'rgb(255, 16, 16)' _c = style["color"] # TODO: refactor with command 'highlight.rb' if _c.match(/\s*blue/i) color='rgb(0, 0, 255)' elsif _c.match(/\s*red/i) color='rgb(255, 0, 0)' elsif _c.match(/\s*yellow/i) color='rgb(255, 255, 0)' elsif _c.match(/\s*green/i) color='rgb(0, 255, 0)' elsif _c.match(/\s*gray/i) color='rgb(128, 128, 128)' end end border=style.has_key?("border")? style["border"] : 1 _js = "hlt = function(c) { c.style.border='solid #{border}px rgb(#{color}, 16, 16)'; }; return hlt(arguments[0]);" # drv.execute_script("hlt = function(c) { c.style.border='solid #{border}px rgb(#{color}, 16, 16)'; }; return hlt(arguments[0]);", element) drv.execute_script("hlt = function(c) { c.style.border='solid #{border}px #{color}'; }; return hlt(arguments[0]);", element) parents = "" if fAncestors ancestors=style.has_key?("ancestors")? style["ancestors"] : 0 ancestors.times do parents << ".parentNode" color -= (12*8 / ancestors) drv.execute_script("hlt = function(c) { c#{parents}.style.border='solid 1px rgb(#{color}, 0, 0)'; }; return hlt(arguments[0]);", element) end else Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " SKIP ANCES" end # Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " PAUSE on highlight"; gets element end
isAccessible(opts)
click to toggle source
5150 stackoverflow.com/questions/14288917/selenium-webdriver-get-attributes-after-finding-an-element
# File lib/scoutui/base/q_browser.rb, line 498 def self.isAccessible(opts) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " == isAccessible(#{opts}) ==" hits = Scoutui::Base::QBrowser.findElements(opts) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " HITS => #{hits.length}" i=0 begin hits.each do | obj | if obj.displayed? Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " #{i}. #{obj.tag_name}" tagName=obj.tag_name.to_s.strip ## Verify labels are present for user input elements if tagName.match(/(textarea|input)/) && obj.attribute('id') id=obj['id'].to_s # parent_li = obj.find_element(:xpath, './../label') parent_li = Scoutui::Base::QBrowser.hasParent?(obj, "./../label[@for='#{id}']") Testmgr::TestReport.instance.getReq('WCAG').testcase(tagName).add(!parent_li.nil?, "Verify matching label (id=#{id.to_s}) exists for #{tagName}.") if parent_li forId = parent_li['for'] Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " parent: #{parent_li.tag_name}" Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " assert <id, for>: #{id}, #{forId}" Testmgr::TestReport.instance.getReq('WCAG').testcase(tagName).add(id==forId, "Verify matching label for #{tagName} has same id (#{id}) and for (#{forId}) values") else Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " => Missing associated label for #{tagName}" end #---------------------------------------------------# elsif tagName.match(/(img)/) src=obj.attribute('src') alt=obj.attribute('alt') longdesc=obj.attribute('longdesc') Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " ** #{i}. process #{tagName} <alt, longdesc>::<#{alt.nil?}, #{longdesc.nil?}, #{src}> **" Testmgr::TestReport.instance.getReq('WCAG').testcase(tagName).add(!(alt.nil? && longdesc.nil?), "Verify alt/longdesc (#{alt.to_s} exists for img[#{i}] (#{src})") else Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " == #{tagName} out of scope for Acccessibility" end i+=1 end end rescue => ex Scoutui::Logger::LogMgr.instance.warn __FILE__ + (__LINE__).to_s + " #{ex.class}" Scoutui::Logger::LogMgr.instance.warn ex.backtrace end end
isChrome?(drv)
click to toggle source
# File lib/scoutui/base/q_browser.rb, line 12 def self.isChrome?(drv) drv.browser.to_s.match(/chrome/i) end
isDisplayed?(_obj, _timeout=Scoutui::Commands::Utils.instance.getTimeout)
click to toggle source
Check if the object (not a String) is an Element that is displayed.
# File lib/scoutui/base/q_browser.rb, line 53 def self.isDisplayed?(_obj, _timeout=Scoutui::Commands::Utils.instance.getTimeout) rc=false if !_obj.nil? && _obj.is_a?(Selenium::WebDriver::Element) begin wait = Selenium::WebDriver::Wait.new(:timeout => _timeout) rc = wait.until { _obj.displayed? } rescue Selenium::WebDriver::Error::TimeOutError ; end end rc end
isEnabled?(_obj, my_driver=nil, _locator=nil)
click to toggle source
# File lib/scoutui/base/q_browser.rb, line 321 def self.isEnabled?(_obj, my_driver=nil, _locator=nil) rc=false Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " isEnabled?(#{_obj})" begin if _obj.is_a?(Selenium::WebDriver::Element) (0..2).each do |i| _isStale = Scoutui::Base::QBrowser.isStale?(_obj) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " #{i} => isStale?(#{_obj}, #{_locator}), isStale: #{_isStale}" if _isStale && !_locator.nil? wait = Selenium::WebDriver::Wait.new(:timeout => Scoutui::Commands::Utils.instance.getTimeout) isDisplayed = wait.until { if Scoutui::Base::QBrowser.isStale?(_obj) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " ** refetch #{_locator} **" _obj=Scoutui::Base::QBrowser.findElement(my_driver, Scoutui::Base::UserVars.instance.normalize(_locator), Scoutui::Commands::Utils.instance.getFrameSearch(), Scoutui::Commands::Utils.instance.getTimeout) end true if _obj.enabled? } end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " enabled => #{_obj.enabled?}" if _obj.enabled? _disabled=_obj.attribute("disabled") _rdonly = _obj.attribute("readonly") Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " disabled: #{_disabled} nil: #{_disabled.nil?}" Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " readonly: #{_rdonly} nil: #{_rdonly.nil?}" Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " enabled: #{_obj.enabled?}" rc = _obj.enabled? && !(_obj.attribute("disabled") || _obj.attribute("readonly") ) rc = _obj.enabled? && (_disabled.nil? || !_disabled) rc=false if rc.nil? next end end else Scoutui::Logger::LogMgr.instance.warn __FILE__ + (__LINE__).to_s + " isEnabled?(not Element)" end rescue => ex Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " #{ex}" Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + ex.backtrace end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " isEnabled?(#{_obj}) : #{rc}" rc end
isFileType?(obj)
click to toggle source
# File lib/scoutui/base/q_browser.rb, line 81 def self.isFileType?(obj) rc=false begin if obj.is_a?(Selenium::WebDriver::Element) rc=!obj.attribute('type').match(/file/i).nil? end rescue => ex ; end rc end
isStale?(_obj)
click to toggle source
# File lib/scoutui/base/q_browser.rb, line 288 def self.isStale?(_obj) _noSuch=false _isStale=false Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " isStale?(#{_obj})" begin if _obj.is_a?(Selenium::WebDriver::Element) _obj.enabled? _obj.tag_name _obj.attribute('type') else Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " | isStale? => nil" return nil end rescue Selenium::WebDriver::Error::NoSuchElementError _noSuch=true rescue Selenium::WebDriver::Error::StaleElementReferenceError _isStale=true rescue => ex Scoutui::Logger::LogMgr.instance.warn __FILE__ + (__LINE__).to_s + " #{ex}" Scoutui::Logger::LogMgr.instance.warn ex.backtrace end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " | isStale?(#{_obj}) : nosuch=#{_noSuch}, stale=#{_isStale}" return (_noSuch || _isStale) end
new()
click to toggle source
# File lib/scoutui/base/q_browser.rb, line 9 def initialize() end
parseLocator(_locator)
click to toggle source
# File lib/scoutui/base/q_browser.rb, line 596 def self.parseLocator(_locator) # TODO: If its a pageObject reference (page(one).get().get()), then retrieve it. Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " parseLocator(#{_locator}" if _locator.is_a?(Hash) if _locator.has_key?('frame') && _locator.has_key?('locator') _locator="#{_locator['frame']}.locator(#{_locator['locator']})" elsif _locator.has_key?('locator') _locator = _locator['locator'] end end return _locator if !_locator.is_a?(String) locator=_locator if Scoutui::ApplicationModel::QModel.isPageObject?(_locator) # _locator.match(/^page\([\w\d]+\)/) pg = Scoutui::Utils::TestUtils.instance.getPageElement(_locator) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " [parseLocator]: pageObject(#{_locator}) => #{pg}" if pg.is_a?(Hash) if pg.has_key?('frame') && pg.has_key?('locator') locator="#{pg['frame']}.locator(#{pg['locator']})" elsif pg.has_key?('locator') if pg['locator'].match((/^\s*([(frame\([^\(]*?\)\.)]*)\.(locator\((.*)\))\s*$/)) locator=pg['locator'] else locator="locator(#{pg['locator']})" end end end end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " | locator => #{locator}" rc=locator.match(/^\s*([(frame\([^\(]*?\)\.)]*)\.(locator\((.*)\))\s*$/) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " parseIt: #{locator} => #{rc}"; if rc Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + "o rc[1] : #{rc[1].to_s}" Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + "o rc[2] : #{rc[2]}" Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + "o rc[3] : #{rc[3]}" return { 'frame' => rc[1], 'locator' => rc[3] } end rc=locator.match(/^\s*(locator\((.*)\))\s*$/) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " parseIt2: #{locator} => #{rc}" if rc Scoutui::Logger::LogMgr.instance.debug "o rc[1] : #{rc[1]}" Scoutui::Logger::LogMgr.instance.debug "o rc[2] : #{rc[2]}" return { 'locator' => rc[2] } end return { 'locator' => locator } end
saveScreenShot(drv, fullPath)
click to toggle source
# File lib/scoutui/base/q_browser.rb, line 16 def self.saveScreenShot(drv, fullPath) rc=false begin drv.save_screenshot(fullPath) rc=true rescue => ex ; end rc end
switch_into_frame(drv, id)
click to toggle source
# File lib/scoutui/base/q_browser.rb, line 159 def self.switch_into_frame(drv, id) _fcnId=" [switch_into_frame]" Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + "#{_fcnId}: (#{id})" hit=nil if isChrome?(drv) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + "#{_fcnId}: switch on Chrome browser" bframes = drv.find_elements(:xpath, '//iframe') Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + "#{_fcnId}: //iframe : size #{bframes.size}" if bframes.size == 0 bframes = drv.find_elements(:xpath, '//frame') Scoutui::Logger::LogMgr.instance.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 Scoutui::Logger::LogMgr.instance.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 Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + "#{_fcnId}: swtichframe to #{i} - #{_tag}" break end rescue => ex Scoutui::Logger::LogMgr.instance.debug "Error during processing: #{$!}" Scoutui::Logger::LogMgr.instance.debug "Backtrace:\n\t#{ex.backtrace.join("\n\t")}" end end else # Firefox, IE Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + "#{_fcnId}: drv.switch_to.frame(#{id.to_s}"; hit = drv.switch_to.frame(id.to_s.strip) end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " switch_into_frame(#{id}) => #{hit}" hit end
wait_for_displayed(drv, locator, _timeout=30)
click to toggle source
# File lib/scoutui/base/q_browser.rb, line 41 def self.wait_for_displayed(drv, locator, _timeout=30) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " wait_for_displayed(#{locator}" rc=nil begin Selenium::WebDriver::Wait.new(timeout: _timeout).until { rc=drv.find_element(:xpath => locator).displayed? } rescue => ex ; end rc end
wait_for_exist(drv, xpath, _timeout=30)
click to toggle source
# File lib/scoutui/base/q_browser.rb, line 69 def self.wait_for_exist(drv, xpath, _timeout=30) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " wait_for_exist(#{xpath}" rc=nil begin Selenium::WebDriver::Wait.new(timeout: _timeout).until { drv.find_element(:xpath => xpath) } rc=drv.find_element(:xpath => xpath) rescue => ex ; end rc end
wait_for_not_displayed(drv, locator, _timeout=30)
click to toggle source
# File lib/scoutui/base/q_browser.rb, line 27 def self.wait_for_not_displayed(drv, locator, _timeout=30) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " wait_for_not_displayed(#{locator}" rc=nil begin Selenium::WebDriver::Wait.new(timeout: _timeout).until { rc=drv.find_element(:xpath => locator).displayed? obj=getObject(drv, obj, _timeout=nil) } rescue => ex ; end rc end
Public Instance Methods
wait_for(seconds) { || ... }
click to toggle source
# File lib/scoutui/base/q_browser.rb, line 916 def wait_for(seconds) Selenium::WebDriver::Wait.new(timeout: seconds).until { yield } end