Class: Scoutui::Commands::VerifyElement

Inherits:
Command
  • Object
show all
Defined in:
lib/scoutui/commands/verify_element.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) ⇒ Object



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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/scoutui/commands/verify_element.rb', line 108

def _execute(drv)
  @drv=drv if !drv.nil?
  _e=getLocator()

  if _e.nil?
    _e = @cmd.match(/(verifyelt|verifyelement)\s*\((.*)\)/)[2].to_s.strip
  end

  Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " verifyElement => #{_e}"  if Scoutui::Utils::TestUtils.instance.isDebug?

  _xpath = Scoutui::Base::UserVars.instance.get(_e)

  Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " | translate : #{_xpath}" if Scoutui::Utils::TestUtils.instance.isDebug?


  page_elt = Scoutui::Utils::TestUtils.instance.getPageElement(_xpath)

  Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Process page request #{page_elt} => #{page_elt.class.to_s}" if Scoutui::Utils::TestUtils.instance.isDebug?

  xpath=nil

  if page_elt.is_a?(Hash) && page_elt.has_key?('locator')

    locator = Scoutui::Base::UserVars.instance.get(page_elt['locator'].to_s)


    if page_elt.has_key?('visible_when') && page_elt['visible_when'].match(/title\(/)
      current_title = @drv.title
      expected_title = Regexp.new(page_elt['visible_when'].match(/title\((.*)\)/)[1].to_s)
      rc=!expected_title.match(current_title).nil?



      Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Verify expected title (#{current_title}) matches (#{expected_title}) => " + rc.to_s

#          Testmgr::TestReport.instance.getReq('UI').tc('visible_when').add(expected_title==current_title, "Verify title matches #{expected_title}")
    end


    if page_elt.has_key?('visible_when') && page_elt['visible_when'].match(/(text|value)\s*\(/)

      rc=nil


      condition = page_elt['visible_when'].match(/(value|text)\((.*)\)/)[1].to_s
      tmpObj = page_elt['visible_when'].match(/(value|text)\((.*)\)/)[2].to_s
      expectedVal = page_elt['visible_when'].match(/(value|text)\s*\(.*\)\s*\=\s*(.*)/)[2].to_s
      Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " tmpObj => #{tmpObj} with expected value #{expectedVal}"

      xpath = Scoutui::Base::UserVars.instance.get(tmpObj)

      obj = Scoutui::Base::QBrowser.getObject(@drv, xpath, Scoutui::Commands::Utils.instance.getTimeout)

      if !obj.nil?
      #  Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " value : #{obj.value.to_s}"
        Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " text  : #{obj.text.to_s}"

        if obj.tag_name.downcase.match(/(select)/)
          _opt = Selenium::WebDriver::Support::Select.new(obj)
          opts = _opt.selected_options
          Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " selected => #{opts.to_s}"



          opts.each do |o|
            Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + "| <v, t>::<#{o.attribute('value').to_s},  #{o.text.to_s}>"

            desc=nil


            if condition=='text' && o.text==expectedVal
              desc=" Verify #{locator} is visible since condition (#{condition} #{xpath} is met."
            elsif condition=='value' && o.attribute('value').to_s==expectedVal
              desc=" Verify #{locator} is visible since #{condition} of #{xpath} is #{expectedVal}"
            end

            if !desc.nil?
              locatorObj = Scoutui::Base::QBrowser.getObject(@drv, locator, Scoutui::Commands::Utils.instance.getTimeout)

              Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " LocatorObj : #{locatorObj} : #{!locatorObj.nil? && locatorObj.displayed?}"


              Testmgr::TestReport.instance.getReq('UI').tc('visible_when').add(!locatorObj.nil? && locatorObj.displayed?, desc)
            end

          end



        end

        Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " value : #{obj.attribute('value').to_s}"
      end

    end

  elsif page_elt.is_a?(Hash)

    page_elt.each do |elt|

      puts __FILE__ + (__LINE__).to_s + " ELT => #{elt} : #{elt.to_s}"
      puts __FILE__ + (__LINE__).to_s + "     ELT[0] : #{elt[0]}"
      puts __FILE__ + (__LINE__).to_s + "     ELT[1] : #{elt[1]}"

      if elt.is_a?(Array)
        _h={ elt[0] => elt[1] }

        _verify(_h)
      end

    end


  end

  Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " xpath : #{xpath}"


end

#_verify(elt) ⇒ Object



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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/scoutui/commands/verify_element.rb', line 7

def _verify(elt)
  begin

    Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " VerifyElement._verify(#{elt})"

    _k = elt.keys[0].to_s
    a = elt[_k]

    Scoutui::Logger::LogMgr.instance.info __FILE__ + (__LINE__).to_s + " Assert => #{_k} :  #{a.to_s}"

    #    _k = 'generic-assertion'
    _v={}

    if a.is_a?(Hash)
      _v=a


      if _v.has_key?('reqid')
        _req=_v['reqid'].to_s
      else
        _req = Scoutui::Utils::TestUtils.instance.getReq()
      end


      if _v.has_key?('locator')
        _locator = _v['locator'].to_s
        Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " " + _k.to_s + " => " + _locator

        #  _locator = Scoutui::Utils::TestUtils.instance.getPageElement(_v['locator'])

        _obj = Scoutui::Base::QBrowser.getFirstObject(@drv, _locator, Scoutui::Commands::Utils.instance.getTimeout())

        Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " HIT #{_locator} => #{!_obj.nil?}"
      end

      if _v.has_key?('visible_when')


        if _v['visible_when'].match(/^\s*(text|value)\s*\(/)

          _elt = _v['visible_when']

          Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " verify text";
          condition = _elt.match(/(value|text)\((.*)\)/)[1].to_s
          tmpObj = _elt.match(/(value|text)\((.*)\)/)[2].to_s
          expectedVal = _elt.match(/(value|text)\s*\(.*\)\s*\=\s*(.*)/)[2].to_s

          _xpath = Scoutui::Base::UserVars.instance.get(tmpObj)

          Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " locator : #{_xpath}"; #gets

          obj = Scoutui::Base::QBrowser.getObject(@drv, _xpath, Scoutui::Commands::Utils.instance.getTimeout)

          Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " text : #{obj.text} vs #{expectedVal}"

          expected_regex = Regexp.new(expectedVal)
          rc =  !obj.text.to_s.match(expected_regex).nil?


          Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " req: #{_req}  obj : #{obj}, rc:#{rc}"; #gets
          if rc
            Testmgr::TestReport.instance.getReq(_req).get_child('visible_when').add(!obj.nil?, "Verify element exists when #{condition} match #{expectedVal}")
          end


        elsif _v['visible_when'].match(/always/i)
          Scoutui::Logger::LogMgr.instance.asserts.info __FILE__ + (__LINE__).to_s + " Verify assertion #{_k} - #{_locator} visible - #{!_obj.nil?.to_s}"
          Testmgr::TestReport.instance.getReq(_req).get_child('visible_when').add(!_obj.nil?, "Verify assertion #{_k} - #{_locator} visible")
        elsif _v['visible_when'].match(/never/i)
          Scoutui::Logger::LogMgr.instance.asserts.info "Verify assertion #{_k} #{_locator} not visible - #{obj.nil?.to_s}"
          Testmgr::TestReport.instance.getReq(_req).get_child('visible_when').add(obj.nil?, "Verify assertion #{_k} #{_locator} not visible")
        elsif _v['visible_when'].match(/role\=/i)
          _role = _v['visible_when'].match(/role\=(.*)/i)[1].to_s
          _expected_role = Scoutui::Utils::TestUtils.instance.getRole()

          Scoutui::Logger::LogMgr.instance.info __FILE__ + (__LINE__).to_s + " Verify assertion object exists if the role #{_role} matches expected role #{_expected_role.to_s}"

          if _role==_expected_role.to_s
            Scoutui::Logger::LogMgr.instance.asserts.info "Verify assertion #{_k} #{_locator}  visible when role #{_role} - #{!_obj.nil?.to_s}"
            Testmgr::TestReport.instance.getReq(_req).get_child('visible_when').add(!_obj.nil?, "Verify assertion #{_k} #{_locator}  visible when role #{_role}")
          end

        end
      end


    end

  rescue => ex

    Scoutui::Logger::LogMgr.instance.info __FILE__ + (__LINE__).to_s + " abort processing."
    Scoutui::Logger::LogMgr.instance.debug "Error during processing: #{ex}"
    puts __FILE__ + (__LINE__).to_s +  "\nBacktrace:\n\t#{ex.backtrace.join("\n\t")}"
  end

end

#execute(_drv, e = nil) ⇒ Object



104
105
106
# File 'lib/scoutui/commands/verify_element.rb', line 104

def execute(_drv, e=nil)
  _execute(drv)
end