Class: Scoutui::Commands::SelectWindow

Inherits:
Command
  • Object
show all
Defined in:
lib/scoutui/commands/select_window.rb

Instance Attribute Summary

Attributes inherited from Command

#bm, #cmd, #description, #drv, #enableAssert, #executed, #executed_result, #locator, #rc, #stanza

Instance Method Summary collapse

Methods inherited from Command

#assert?, #disableAssert, #disableAsserts, #enableAsserts, #executedResult, #getLocator, #initialize, #passed?, #result, #run, #setBenchmark, #setLocator, #setResult, #wasExecuted?

Constructor Details

This class inherits a constructor from Scoutui::Commands::Command

Instance Method Details

#execute(drv = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/scoutui/commands/select_window.rb', line 6

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