module Scoutui::Commands class SelectWindow < Command def execute(drv=nil) _rc=false _req = Scoutui::Utils::TestUtils.instance.getReq() _window_id=nil @drv=drv if !drv.nil? Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " SELECT WINDOW +++++++++++++++" begin _window_id = @cmd.match(/select_window\s*\((.*)\)/)[1].to_s.strip matchWith={ :by => nil, :value => nil } if _window_id.match(/^\d+$/) matchWith = { :by => :index, :value => _window_id.to_i } elsif _window_id.empty? matchWith = { :by => :switch_new_window } elsif _window_id.is_a?(String) matchWith = { :by => :regex, :value => Regexp.new(_window_id)} else Scoutui::Logger::LogMgr.instance.warn __FILE__ + (__LINE__).to_s + " Unknown arg #{_window_id}" end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " ==> WindowID : #{_window_id}" Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " ==> handles : #{@drv.window_handles.length.to_s}" i=1 current_window=@drv.window_handle @drv.window_handles.each do |_w| puts __FILE__ + (__LINE__).to_s + "#{i}. #{_w.class.to_s}" if matchWith[:by]==:index && i==matchWith[:value] Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " select_window : #{i}" _rc=true elsif matchWith[:by]==:switch_new_window && current_window!=_w _rc = true elsif matchWith[:by]==:regex @drv.switch_to.window(_w) if @drv.title.to_s.match(matchWith[:value]) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " matched by regex" _rc=true else @drv.switch_to.window(current_window) end end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Active Title : #{@drv.title.to_s}" if _rc @drv.switch_to.window(_w) if matchWith[:by]!=:regex puts __FILE__ + (__LINE__).to_s + " switched => #{@drv.title}" break end i+=1 end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " switched to i #{i} given windowID #{_window_id}"; rescue => ex Scoutui::Logger::LogMgr.instance.debug "Error during processing: #{$!}" Scoutui::Logger::LogMgr.instance.debug "Backtrace:\n\t#{ex.backtrace.join("\n\t")}" end Testmgr::TestReport.instance.getReq(_req).testcase('select_window').add(_rc, "Verify select_window #{_window_id} command passed #{_rc}") setResult(_rc) end end end