Class: Scoutui::Commands::ThenClause

Inherits:
Object
  • Object
show all
Defined in:
lib/scoutui/commands/clauses/then_clause.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(driver) ⇒ ThenClause

Returns a new instance of ThenClause.



8
9
10
11
# File 'lib/scoutui/commands/clauses/then_clause.rb', line 8

def initialize(driver)
  @drv=driver
  @pageElt=nil
end

Instance Attribute Details

#drvObject

Returns the value of attribute drv.



6
7
8
# File 'lib/scoutui/commands/clauses/then_clause.rb', line 6

def drv
  @drv
end

Class Method Details

._execute(drv, thenList) ⇒ Object



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
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/scoutui/commands/clauses/then_clause.rb', line 13

def self._execute(drv, thenList)

  thenList.each do |_subcmd|

    if _subcmd.is_a?(String)

      Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " | then => #{_subcmd}"

      if _subcmd.match(/^\s*press\(__TAB__\)$/)
        drv.action.send_keys(:tab).perform

      elsif _subcmd.match(/^\s*press\((__ESC__|__ESCAPE__)\)$/)
        drv.action.send_keys(:escape).perform

      elsif _subcmd.match(/^\s*press\(__HOLD_SHIFT__\)\s*$/)
        drv.action.key_down(:shift).perform
        Scoutui::Base::TestContext.instance.set(:shift_down, true)

      elsif _subcmd.match(/^\s*press\(__RELEASE_SHIFT__\)\s*$/)
        drv.action.key_up(:shift).perform
        Scoutui::Base::TestContext.instance.set(:shift_down, false)

      elsif _subcmd.match(/^\s*press\(__HOLD_COMMAND__\)$/)
        drv.action.key_down(:command).perform
        Scoutui::Base::TestContext.instance.set(:command_down, true)

      elsif _subcmd.match(/^\s*press\(__RELEASE_COMMAND__\)$/)
        drv.action.key_up(:command).perform
        Scoutui::Base::TestContext.instance.set(:command_down, false)

      elsif _subcmd.match(/^\s*press\(__CONTROL__\)$/)

        drv.driver.action.key_down(:control).perform
        drv.action.key_up(:control).perform

        # Check for list of elements to click

      elsif _subcmd.match(/^\s*press\(__DOWN__\)$/)
        puts __FILE__ + (__LINE__).to_s + " Press down"
        drv.action.send_keys(:arrow_down).perform

      elsif _subcmd.match(/^\s*press\(__UP__\)$/)
        drv.action.send_keys(:arrow_up).perform

      elsif _subcmd.match(/^\s*press\(__ENTER__\)\s*$/)
        drv.action.send_keys(:enter).perform

      elsif _subcmd.match(/^\s*focused\.[Hh]ighlight\s*$/i)

        _activeElt = drv.switch_to.active_element
        if !_activeElt.nil?
          Scoutui::Base::QBrowser.highlight(drv, _activeElt)
        end

      elsif _subcmd.match(/^\s*click\((.*)\)\s*$/)
        # Click on the locator

        _c = Scoutui::Commands::ClickObject.new(_subcmd)
        _c.run(driver: drv)

      elsif  Scoutui::Commands::Utils.instance.isMouseOver?(_subcmd)
        _cmd='MouseOver'
        _c = Scoutui::Commands::MouseOver.new(_subcmd)
        _c.execute(drv)

      elsif Scoutui::Commands::Utils.instance.isPause?(_subcmd)
          _cmd='pause'
          _c = Scoutui::Commands::Pause.new(nil)
          _c.execute();


      elsif _subcmd.match(/^\s*press\((.*)\)\s*$/)
        _locator = _subcmd.match(/^\s*press\((.*)\)\s*$/)[1].to_s
        _locator = Scoutui::Base::UserVars.instance.normalize(_locator)
        obj = Scoutui::Base::QBrowser.getElement(drv, _locator, Scoutui::Commands::Utils.instance.getFrameSearch(),  Scoutui::Commands::Utils.instance.getTimeout)
        obj.click
      end

    end
  end

end

Instance Method Details

#execute(pageElt) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/scoutui/commands/clauses/then_clause.rb', line 97

def execute(pageElt)

  rc=true
  thenList=nil

  if !pageElt.nil? && pageElt.is_a?(Hash) && pageElt.has_key?('page') && pageElt['page'].has_key?('then')
    @pageElt=pageElt
    thenList=pageElt['page']['then']
  elsif pageElt.is_a?(Array)
    thenList=pageElt
  end

  rc=Scoutui::Commands::ThenClause._execute(@drv, pageElt['page']['then']) if thenList

  rc
end

#execute_until(pageElt) ⇒ Object



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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/scoutui/commands/clauses/then_clause.rb', line 116

def execute_until(pageElt)

  if !pageElt.nil? && pageElt['page'].has_key?('then') && pageElt['page'].has_key?('until')

    thenList=pageElt['page']['then']
    _loop=true
    _i=0
    _historyElts={}
    _bUntil=false

    while _loop && !_bUntil do

      if thenList.is_a?(Array)
        thenClause = Scoutui::Commands::ThenClause.new(@drv)
        thenClause.execute(pageElt)

        _activeElt = @drv.switch_to.active_element

        puts __FILE__ + (__LINE__).to_s + " ActiveElt => #{_activeElt.text}"

        if _historyElts.size > 0 && _historyElts.has_key?(_activeElt)
          puts __FILE__ + (__LINE__).to_s + "****** WRAPPED ******";  #STDIN.gets

          _loop=false
        else
          _historyElts[_activeElt]=true
        end

      end

      if _loop && !pageElt.nil? && pageElt['page'].has_key?('until')
        _expected=Scoutui::Base::VisualTestFramework::processAsserts(@drv, pageElt['page']['until'], false)
        puts __FILE__ + (__LINE__).to_s + " ==> until : #{_expected}"

        _loop=!_expected

        if _expected
          _bUntil=true
        end

      elsif !pageElt['page'].has_key?('until')
        _loop=false
        _bUntil=true
      end

      _i+=1

      if !_bUntil && _i > 75
        _loop=false
        puts __FILE__ + (__LINE__).to_s + " ** BREAK OUT **"; #STDIN.gets
      end

    end  # while()

    _rc=_bUntil


  elsif !pageElt.nil? && pageElt['page'].has_key?('then')
    _rc=execute(pageElt)
  else
    _rc=true
  end

  _rc
end