scoutui 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/examples/capabilities/win10.chrome46.json +6 -0
  3. data/examples/ex1/test-example.sh +4 -4
  4. data/examples/ex1/test.config.json +1 -1
  5. data/examples/ex2/appmodel/common.json +51 -0
  6. data/examples/ex2/appmodel/page_model.json +106 -0
  7. data/examples/ex2/appmodel/register.model.json +42 -0
  8. data/examples/ex2/commands/commands.basic.appmodel.yml +8 -0
  9. data/examples/ex2/commands/commands.yml +115 -0
  10. data/examples/ex2/commands/ex1.yml +7 -0
  11. data/examples/ex2/commands/ex1c.yml +8 -0
  12. data/examples/ex2/commands/ex1d.yml +22 -0
  13. data/examples/ex2/commands/ex2.hover.yml +43 -0
  14. data/examples/ex2/commands/ex2.yml +24 -0
  15. data/examples/ex2/data.json +6 -0
  16. data/examples/ex2/test-configs/test.config.basic.json +12 -0
  17. data/examples/ex2/{test.config.json → test-configs/test.config.json} +8 -2
  18. data/examples/ex2/tests/run-test.sh +125 -0
  19. data/examples/ex2/tests/test-basic-appmodel.sh +14 -0
  20. data/examples/ex2/{test-example.sh → tests/test-example.sh} +3 -3
  21. data/examples/ex2/tests/test-example1a.sh +16 -0
  22. data/examples/ex2/tests/test-example1b.sh +13 -0
  23. data/examples/ex2/tests/test-example1c.sh +15 -0
  24. data/examples/ex2/tests/test-example1d.sh +15 -0
  25. data/examples/ex2/tests/test-example2.forms.eyes.sh +40 -0
  26. data/examples/ex2/tests/test-example2.hover.eyes.sh +40 -0
  27. data/examples/ex2/tests/test-example2.hover.sh +26 -0
  28. data/examples/ex2/tests/test-example2.sh +43 -0
  29. data/examples/ex2/tests/test-example3.sauce.sh +77 -0
  30. data/examples/ex2/tests/test-example3.sh +41 -0
  31. data/lib/scoutui/appmodel/q_model.rb +105 -0
  32. data/lib/scoutui/base/assertions.rb +570 -10
  33. data/lib/scoutui/base/q_applitools.rb +2 -2
  34. data/lib/scoutui/base/q_browser.rb +38 -5
  35. data/lib/scoutui/base/q_form.rb +7 -7
  36. data/lib/scoutui/base/test_scout.rb +2 -1
  37. data/lib/scoutui/base/user_vars.rb +29 -2
  38. data/lib/scoutui/base/visual_test_framework.rb +308 -24
  39. data/lib/scoutui/commands/click_object.rb +86 -13
  40. data/lib/scoutui/commands/commands.rb +20 -7
  41. data/lib/scoutui/commands/jsalert/action_jsalert.rb +1 -1
  42. data/lib/scoutui/commands/mouse_over.rb +94 -8
  43. data/lib/scoutui/commands/select_object.rb +1 -1
  44. data/lib/scoutui/commands/select_window.rb +43 -0
  45. data/lib/scoutui/commands/strategy.rb +40 -3
  46. data/lib/scoutui/commands/type.rb +99 -11
  47. data/lib/scoutui/commands/update_url.rb +1 -1
  48. data/lib/scoutui/commands/utils.rb +43 -5
  49. data/lib/scoutui/commands/verify_element.rb +38 -7
  50. data/lib/scoutui/eyes/eye_factory.rb +7 -1
  51. data/lib/scoutui/eyes/eye_scout.rb +20 -7
  52. data/lib/scoutui/utils/utils.rb +59 -1
  53. data/lib/scoutui/version.rb +1 -1
  54. data/scoutui.gemspec +5 -4
  55. metadata +77 -39
  56. data/examples/ex2/commands.yml +0 -35
  57. data/examples/ex2/page_model.json +0 -28
@@ -0,0 +1,77 @@
1
+ #/bin/bash
2
+ ##
3
+ # Description
4
+ # This test script overrides the provided title and appname (if provided in the test config. file)
5
+ #
6
+ # Set the APPLITOOLS_API_KEY environment variable with your key.
7
+ #
8
+ # export APPLITOOLS_API_KEY="__YOUR_KEY_HERE__"
9
+ ##
10
+ export SCOUTUI_BIN=../../../bin/scoutui_driver.rb
11
+ # Specify browser under test (chrome, firefox, ie, safari)
12
+ BUT=firefox
13
+
14
+ # Specify the title and appName needed by Applitools
15
+ ## NOTE: If the test configuration file specifies the title and app, it is superseded by the
16
+ ## command line options.
17
+ TITLE=Carmax_Ex3
18
+ APP=Oct2015
19
+
20
+ # Specify the test configuration file
21
+ TEST_CFG="../test-configs/test.config.json"
22
+
23
+ ##
24
+ # content
25
+ # strict
26
+ # exact
27
+ # layyout
28
+ ##
29
+ MATCH_TYPE="layout"
30
+
31
+
32
+
33
+ sauce_eyes() {
34
+
35
+
36
+
37
+
38
+ ./run-test.sh -b chrome -d ../commands/commands.yml \
39
+ -P ../appmodel/page_model.json \
40
+ -t ../test-configs/test.config.json \
41
+ -v \
42
+ -A STP_Example \
43
+ -T VH \
44
+ -O /tmp/vt \
45
+ -e \
46
+ -m content \
47
+ -s \
48
+ -S $TITLE \
49
+ -c ../../capabilities/win10.chrome46.json
50
+ }
51
+
52
+
53
+ sauce() {
54
+
55
+ ./run-test.sh -b chrome -d ../commands/commands.yml \
56
+ -P ../appmodel/page_model.json \
57
+ -t ../test-configs/test.config.json \
58
+ -v \
59
+ -s \
60
+ -w 5 \
61
+ -S $TITLE \
62
+ -c ../../capabilities/win10.chrome46.json
63
+ }
64
+
65
+
66
+ local() {
67
+
68
+ ./run-test.sh -b chrome -d ../commands/commands.yml \
69
+ -P ../appmodel/page_model.json \
70
+ -t ../test-configs/test.config.json \
71
+ -v \
72
+ -w 5 \
73
+ -c ../../capabilities/win10.chrome46.json
74
+
75
+ }
76
+
77
+ sauce
@@ -0,0 +1,41 @@
1
+ #/bin/bash
2
+ ##
3
+ # Description
4
+ # This test script overrides the provided title and appname (if provided in the test config. file)
5
+ #
6
+ # Set the APPLITOOLS_API_KEY environment variable with your key.
7
+ #
8
+ # export APPLITOOLS_API_KEY="__YOUR_KEY_HERE__"
9
+ ##
10
+ export SCOUTUI_BIN=../../../bin/scoutui_driver.rb
11
+ # Specify browser under test (chrome, firefox, ie, safari)
12
+ BUT=firefox
13
+
14
+ # Specify the title and appName needed by Applitools
15
+ ## NOTE: If the test configuration file specifies the title and app, it is superseded by the
16
+ ## command line options.
17
+ TITLE=DEMO-CarMax
18
+ APP=Oct2015
19
+
20
+ # Specify the test configuration file
21
+ TEST_CFG="../test-configs/test.config.json"
22
+
23
+ ##
24
+ # content
25
+ # strict
26
+ # exact
27
+ # layyout
28
+ ##
29
+ MATCH_TYPE="layout"
30
+
31
+ EYES=--eyes
32
+ EYES=
33
+
34
+
35
+ # The following command line parameters will override provided title and appName (if provided in test config file)
36
+ #$SCOUTUI_BIN --config $TEST_CFG --browser $BUT $EYES --app $APP --title $TITLE --match $MATCH_TYPE --pagemodel ../appmodel/page_model.json --debug
37
+
38
+ # The following
39
+ # $SCOUTUI_BIN --config $TEST_CFG --eyes --match $MATCH_TYPE --browser $BUT
40
+
41
+ ./run-test.sh -b chrome -d ../commands/commands.yml -P ../appmodel/page_model.json -t ../test-configs/test.config.json -w 5 -v
@@ -49,6 +49,11 @@ module Scoutui::ApplicationModel
49
49
  # getPageElement("page(login).get(login_form).get(button)")
50
50
  def getPageElement(s)
51
51
  Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " getPageElement(#{s})"
52
+
53
+ if s.match(/^\s*\//) || s.match(/^\s*css\s*=/i)
54
+ return nil
55
+ end
56
+
52
57
  hit=@app_model
53
58
 
54
59
  nodes = s.split(/\./)
@@ -75,6 +80,106 @@ module Scoutui::ApplicationModel
75
80
 
76
81
  end
77
82
 
83
+
84
+
85
+ # visible_when: hover(page(x).get(y).get(z))
86
+ def itemize(condition='visible_when', _action='hover', _pgObj=nil)
87
+ @results=hits(nil, @app_model, condition, _action, _pgObj)
88
+
89
+ puts "[itemize] => #{@results}"
90
+
91
+ @results
92
+ end
93
+
94
+
95
+ def hits(parent, h, condition, _action, pg)
96
+ # puts __FILE__ + (__LINE__).to_s + " collect_item_attributes(#{h})"
97
+ result = []
98
+
99
+
100
+ if h.is_a?(Hash)
101
+
102
+ h.each do |k, v|
103
+ puts __FILE__ + (__LINE__).to_s + " Key: #{k} => #{v}"
104
+ if k == condition
105
+ # h[k].each {|k, v| result[k] = v } # <= tweak here
106
+ if !v.is_a?(Array) && v.match(/^\s*#{_action}\s*\((.*)\)\s*$/i)
107
+
108
+ pageObject=v.match(/^\s*#{_action}\s*\((.*)\)\s*$/i)[1]
109
+
110
+ puts __FILE__ + (__LINE__).to_s + " <pg, pageObject> : <#{pg}, #{pageObject}>"
111
+ # result[k] = v
112
+
113
+ # puts '*******************'
114
+ # puts __FILE__ + (__LINE__).to_s + " HIT : #{h[k]}"
115
+ # result << { h[k] => v }
116
+
117
+ if pg.nil?
118
+ result << parent
119
+ elsif pg == pageObject
120
+ result << parent
121
+
122
+ end
123
+
124
+ elsif v.is_a?(Array)
125
+
126
+ v.each do |vh|
127
+ puts " =====> #{vh}"
128
+
129
+ if vh.is_a?(Hash) && vh.has_key?(condition) && vh[condition].match(/^\s*#{_action}\s*/i)
130
+
131
+ pageObject=vh[condition].match(/^\s*#{_action}\s*\((.*)\)\s*$/i)[1]
132
+
133
+
134
+ puts __FILE__ + (__LINE__).to_s + " matched on #{_action}, pg:#{pg}, #{pageObject}"
135
+
136
+ if pg.nil?
137
+ result << parent
138
+ elsif pg == pageObject
139
+ result << parent
140
+ end
141
+
142
+ end
143
+
144
+ end
145
+
146
+ end
147
+
148
+ elsif v.is_a? Hash
149
+ if parent.nil?
150
+ _rc = hits("page(#{k})", h[k], condition, _action, pg)
151
+ else
152
+ _rc = hits("#{parent}.get(#{k})", h[k], condition, _action, pg)
153
+ end
154
+
155
+
156
+ if !(_rc.nil? || _rc.empty?)
157
+
158
+
159
+ result << _rc
160
+
161
+ puts __FILE__ + (__LINE__).to_s + " ADDING #{k} : #{_rc}"
162
+ # puts "====> #{k} : #{_rc.class} : #{_rc.length}"
163
+
164
+
165
+ result.flatten!
166
+ end
167
+
168
+
169
+ end
170
+ end
171
+
172
+ end
173
+
174
+
175
+
176
+ result=nil if result.empty?
177
+ puts __FILE__ + (__LINE__).to_s + " result : #{result}"
178
+ result
179
+ end
180
+
181
+
182
+
78
183
  end
79
184
 
80
185
 
@@ -15,44 +15,604 @@ module Scoutui::Base
15
15
  @drv=_drv
16
16
  end
17
17
 
18
+
19
+ def assertPage(my_driver, _pg, _req=nil)
20
+ if _req.nil?
21
+ _req = Scoutui::Utils::TestUtils.instance.getReq()
22
+ end
23
+
24
+ if !_pg.match(/^page\([\w\d]+\)/).nil?
25
+
26
+
27
+ # Check if this is a form
28
+
29
+ page_elt = Scoutui::Utils::TestUtils.instance.getPageElement(_pg)
30
+ Scoutui::Logger::LogMgr.instance.info __FILE__ + (__LINE__).to_s + " Process page request #{page_elt} => #{page_elt.class.to_s}" if Scoutui::Utils::TestUtils.instance.isDebug?
31
+
32
+ sub_elts=0
33
+ if page_elt.is_a?(Hash)
34
+ sub_elts = page_elt.select { |_s| page_elt[_s].has_key?("locator") if page_elt[_s].is_a?(Hash) && !page_elt[_s].nil? }.size
35
+ else
36
+ Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Process an element (#{page_elt})"
37
+ end
38
+
39
+ Scoutui::Logger::LogMgr.instance.info __FILE__ + (__LINE__).to_s + " SubElts => #{sub_elts}" if Scoutui::Utils::TestUtils.instance.isDebug?
40
+
41
+ ##
42
+ # Check if this is a single element.
43
+ ##
44
+ if page_elt.is_a?(Hash) && page_elt.has_key?('locator')
45
+
46
+ ##
47
+ # expected:
48
+ # wait: page(abc).get(def) where this page_elt has "locator"
49
+
50
+ xpath = page_elt['locator'].to_s
51
+ Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Verify #{page_elt['locator']}"
52
+
53
+ elsif sub_elts > 0
54
+ ##
55
+ # This pageobject consists of multiple pageobjects.
56
+ ##
57
+ Scoutui::Utils::TestUtils.instance.addPageCoverage(_pg)
58
+
59
+ Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Validate form"
60
+
61
+ page_elt.each_pair do |_k, _v|
62
+
63
+ begin
64
+
65
+ Scoutui::Logger::LogMgr.instance.info __FILE__ + (__LINE__).to_s + " k,v :: #{_k.to_s}, #{_v.to_s} (#{_v.class.to_s})" if Scoutui::Utils::TestUtils.instance.isDebug?
66
+
67
+ _obj=nil
68
+
69
+
70
+ if _v.is_a?(String)
71
+ puts __FILE__ + (__LINE__).to_s + " #{_v} is a string - next"
72
+ puts __FILE__ + (__LINE__).to_S + " Pause", gets
73
+ next
74
+ end
75
+
76
+ if _v.has_key?('assert_when') && _v['assert_when'].match(/role\s*\=/i)
77
+ _role = _v['assert_when'].match(/role\s*\=(.*)/i)[1].to_s
78
+ _expected_role = Scoutui::Utils::TestUtils.instance.getRole()
79
+
80
+ Scoutui::Logger::LogMgr.instance.info __FILE__ + (__LINE__).to_s + " Trigger: expected : #{_expected_role.to_s}, actual: #{_role.to_s}" if Scoutui::Utils::TestUtils.instance.isDebug?
81
+
82
+ if !_expected_role.nil? && !_role.match(/#{_expected_role}/i)
83
+ Scoutui::Logger::LogMgr.instance.info __FILE__ + (__LINE__).to_s + " Skip assertion since conditional assertion #{_v['assert_when']} not met" if Scoutui::Utils::TestUtils.instance.isDebug?
84
+ next
85
+ elsif _expected_role.nil?
86
+ Scoutui::Logger::LogMgr.instance.info __FILE__ + (__LINE__).to_s + " Skip role based assertion since role was not provided" if Scoutui::Utils::TestUtils.instance.isDebug?
87
+ next
88
+ end
89
+ Scoutui::Logger::LogMgr.instance.info __FILE__ + (__LINE__).to_s + " Verify object exists since the role #{_role} matches expected role #{_expected_role.to_s}" if Scoutui::Utils::TestUtils.instance.isDebug?
90
+ end
91
+
92
+
93
+ if Scoutui::Base::Assertions.instance.visible_when_skip(_k, _v)
94
+ Scoutui::Logger::LogMgr.instance.info __FILE__ + (__LINE__).to_s + " SKIP #{_k.to_s} - #{_v.to_s}" if Scoutui::Utils::TestUtils.instance.isDebug?
95
+ next
96
+ end
97
+
98
+ if _v.has_key?('locator')
99
+ _locator = _v['locator'].to_s
100
+ Scoutui::Logger::LogMgr.instance.info __FILE__ + (__LINE__).to_s + " " + _k.to_s + " => " + _locator
101
+
102
+ # _locator = Scoutui::Utils::TestUtils.instance.getPageElement(_v['locator'])
103
+
104
+ _obj = Scoutui::Base::QBrowser.getFirstObject(my_driver, _locator, Scoutui::Commands::Utils.instance.getTimeout())
105
+
106
+ Scoutui::Logger::LogMgr.instance.info __FILE__ + (__LINE__).to_s + " HIT #{_locator} => #{!_obj.nil?}"
107
+ end
108
+
109
+ if Scoutui::Base::Assertions.instance.visible_when_always(_k, _v, _obj, _req)
110
+ next
111
+ elsif _v.has_key?('visible_when')
112
+
113
+ if _v['visible_when'].match(/always/i)
114
+ Scoutui::Logger::LogMgr.instance.asserts.info __FILE__ + (__LINE__).to_s + " Verify #{_k} - #{_locator} visible - #{!_obj.nil?.to_s}"
115
+
116
+ if Scoutui::Utils::TestUtils.instance.assertExpected?
117
+ Testmgr::TestReport.instance.getReq(_req).get_child('visible_when').add(!_obj.nil?, "Verify #{_k} - #{_locator} visible")
118
+ end
119
+
120
+
121
+
122
+ elsif assertPageElement(_k, _v, _obj, my_driver, _req)
123
+ puts __FILE__ + (__LINE__).to_s + " Processed assertPageElement(#{_k}, #{_v})"; # gets
124
+ ;
125
+ # elsif visible_when_title(_k, _v, _obj, my_driver, _req)
126
+ # ;
127
+
128
+ # elsif _v['visible_when'].match(/never/i)
129
+ # Scoutui::Logger::LogMgr.instance.asserts.info "Verify #{_k} #{_locator} never visible - #{obj.nil?.to_s}"
130
+ # Testmgr::TestReport.instance.getReq(_req).get_child('visible_when').add(obj.nil?, "Verify #{_k} #{_locator} not visible")
131
+
132
+ elsif _v['visible_when'].match(/role\=/i)
133
+ _role = _v['visible_when'].match(/role\=(.*)/i)[1].to_s
134
+ _expected_role = Scoutui::Utils::TestUtils.instance.getRole()
135
+
136
+ Scoutui::Logger::LogMgr.instance.info __FILE__ + (__LINE__).to_s + " Verify object exists if the role #{_role} matches expected role #{_expected_role.to_s}" if Scoutui::Utils::TestUtils.instance.isDebug?
137
+
138
+ if _role==_expected_role.to_s
139
+ Scoutui::Logger::LogMgr.instance.asserts.info "Verify #{_k} #{_locator} visible when role #{_role} - #{!_obj.nil?.to_s}"
140
+
141
+ if Scoutui::Utils::TestUtils.instance.assertExpected?
142
+ Testmgr::TestReport.instance.getReq(_req).get_child('visible_when').add(!_obj.nil?, "Verify #{_k} #{_locator} visible when role #{_role}")
143
+ end
144
+
145
+ end
146
+
147
+ end
148
+ end
149
+
150
+
151
+ rescue => ex
152
+ Scoutui::Logger::LogMgr.instance.info __FILE__ + (__LINE__).to_s + " Invalid file: #{datafile} - abort processing."
153
+ puts __FILE__ + (__LINE__).to_s + "Backtrace:\n\t#{ex.backtrace.join("\n\t")}"
154
+ end
155
+
156
+
157
+ end
158
+
159
+ return
160
+
161
+
162
+ elsif xpath.is_a?(Hash)
163
+ xpath.each_pair do |_k, _v|
164
+
165
+ Scoutui::Logger::LogMgr.instance.info __FILE__ + (__LINE__).to_s + " k,v :: #{_k.to_s}, #{_v.to_s}"
166
+
167
+ if _v.has_key?('locator')
168
+ _locator = _v['locator'].to_s
169
+ Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " " + _k.to_s + " => " + _locator
170
+
171
+ # _locator = Scoutui::Utils::TestUtils.instance.getPageElement(_v['locator'])
172
+
173
+ _obj = Scoutui::Base::QBrowser.getFirstObject(my_driver, _locator, Scoutui::Commands::Utils.instance.getTimeout())
174
+
175
+ Scoutui::Logger::LogMgr.instance.info __FILE__ + (__LINE__).to_s + " HIT #{_locator} => #{!_obj.nil?}"
176
+ end
177
+
178
+ end
179
+
180
+ # next
181
+ end
182
+
183
+
184
+ end
185
+
186
+ puts __FILE__ + (__LINE__).to_s + " Pause debug"; gets
187
+ end
188
+
189
+ #
190
+ # { reqid : <pageElt> }
191
+ def isVisible(my_driver, page_elt, _req=nil, _immediate=false)
192
+ if _req.nil?
193
+ _req = Scoutui::Utils::TestUtils.instance.getReq()
194
+ end
195
+
196
+ puts __FILE__ + (__LINE__).to_s + " [isVisible]: #{page_elt}, req:#{_req}"
197
+
198
+ rc=false
199
+ cmd='visible'
200
+ _processed=false
201
+
202
+
203
+
204
+ pageObject=page_elt
205
+
206
+ if page_elt.is_a?(String) && page_elt.match(/^\s*(text|value)\s*\(/)
207
+ #
208
+ # text(page(home).get(elt))
209
+ # value(page(home).get(elt))
210
+ #
211
+ _processed=true
212
+ condition = page_elt.match(/(value|text)\((.*)\)/)[1].to_s
213
+ tmpObj = page_elt.match(/(value|text)\((.*)\)/)[2].to_s
214
+ expectedVal = page_elt.match(/(value|text)\s*\(.*\)\s*\=\s*(.*)/)[2].to_s
215
+
216
+ xpath = Scoutui::Base::UserVars.instance.get(tmpObj)
217
+
218
+ Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " locator : #{xpath}"; #gets
219
+
220
+ obj = Scoutui::Base::QBrowser.getObject(my_driver, xpath, Scoutui::Commands::Utils.instance.getTimeout)
221
+
222
+ puts __FILE__ + (__LINE__).to_s + " #{condition} : #{obj}"
223
+
224
+ if condition.match(/^text/)
225
+ _txt = obj.text
226
+
227
+ expected_regex = Regexp.new(expectedVal)
228
+ rc = _!txt.to_s.match(expected_regex).nil?
229
+ return rc
230
+ end
231
+
232
+
233
+ elsif page_elt.is_a?(String) && page_elt.match(/^\s*(url)\s*\((.*)\)/)
234
+
235
+ current_url = my_driver.current_url.to_s
236
+ expected_url = page_elt.match(/^\s*(url)\s*\((.*)\)/)[2].to_s
237
+
238
+
239
+ puts __FILE__ + (__LINE__).to_s + " verify is URL matches #{current_url} with expected #{expected_url}"
240
+
241
+ expected_regex = Regexp.new(expected_url)
242
+ rc=!current_url.match(expected_regex).nil?
243
+
244
+ Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " verify current url #{current_url} matches #{rc}"
245
+
246
+ return rc
247
+
248
+ elsif page_elt.is_a?(String) && page_elt.match(/^\s*(visible)\((.*)\)/)
249
+ #
250
+ # visible(page(home).get(elt))
251
+ #
252
+ _processed=true
253
+ cmd = page_elt.match(/(visible)\((.*)\)/)[1].to_s
254
+ page_elt = page_elt.match(/(visible)\((.*)\)/)[2].to_s
255
+
256
+ if !page_elt.match(/\$\{.*\}/).nil?
257
+ page_elt = Scoutui::Base::UserVars.instance.normalize(page_elt)
258
+ end
259
+ end
260
+
261
+ if cmd=='visible' && page_elt.is_a?(String) && page_elt.match(/^\s*page\s*\(/)
262
+
263
+ Scoutui::Logger::LogMgr.instance.info __FILE__ + (__LINE__).to_s + " Process PageElement #{page_elt}"
264
+ pageObject = Scoutui::Utils::TestUtils.instance.getPageElement(page_elt)
265
+
266
+ elsif !Scoutui::Commands::Utils.instance.isCSS(page_elt).nil?
267
+ pageObject={ 'locator' => Scoutui::Commands::Utils.instance.isCSS(page_elt) }
268
+ elsif cmd=='visible' && page_elt.is_a?(String) && page_elt.match(/^\s*\//)
269
+ pageObject={ 'locator' => page_elt }
270
+ else
271
+ Scoutui::Logger::LogMgr.instance.warn __FILE__ + (__LINE__).to_s + " [isVisible]:unknown command"
272
+ end
273
+
274
+ if cmd=='visible' && pageObject.is_a?(Hash) && pageObject.has_key?('locator')
275
+
276
+ _processed=true
277
+ ##
278
+ # expected:
279
+ # wait: page(abc).get(def) where this page_elt has "locator"
280
+
281
+ locator = pageObject['locator'].to_s
282
+
283
+ _obj = Scoutui::Base::QBrowser.getFirstObject(my_driver, locator, Scoutui::Commands::Utils.instance.getTimeout)
284
+
285
+ if cmd=='visible'
286
+ if !_obj.nil?
287
+ rc=_obj.displayed?
288
+ end
289
+
290
+ if _immediate
291
+
292
+ Scoutui::Logger::LogMgr.instance.debug " return immediate (#{rc})"
293
+ return rc
294
+ end
295
+
296
+ Scoutui::Logger::LogMgr.instance.asserts.info "Verify #{page_elt} is visible - #{rc}"
297
+ Testmgr::TestReport.instance.getReq(_req).get_child('visible').add(rc, "Verify #{page_elt} is visible")
298
+ end
299
+
300
+ ## TITLE
301
+ elsif page_elt.is_a?(String) && page_elt.match(/\s*(title)\s*\(\s*(.*)\s*\)/)
302
+ _processed=true
303
+ current_title = my_driver.title.strip
304
+
305
+ _t = page_elt.match(/\s*title\s*\(\s*(.*)\s*\)/)[1].to_s
306
+
307
+ expected_title = Regexp.new(_t)
308
+ rc=!current_title.match(expected_title).nil?
309
+
310
+ Scoutui::Logger::LogMgr.instance.asserts.info "Verify current title, #{current_title}, matches #{expected_title})"
311
+ Testmgr::TestReport.instance.getReq(_req).get_child('title').add(rc, "Verify current title, #{current_title}, matches #{expected_title}")
312
+
313
+ elsif pageObject.is_a?(Hash)
314
+ Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " == Verify Page page_elt:#{page_elt} pageObject:#{pageObject} req:#{_req} =="
315
+ assertPage(my_driver, page_elt, _req)
316
+ end
317
+
318
+ rc
319
+
320
+ end
321
+
18
322
  # { "visible_when" => "always" }
19
- def visible_when_always(_k, _v, _obj=nil)
323
+ def visible_when_always(_k, _v, _obj=nil, _req='UI')
324
+
325
+ if _v.is_a?(Hash) && _v.has_key?('reqid')
326
+ _req = _v['reqid']
327
+ end
20
328
 
329
+ Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " visible_when_always(#{_k}, #{_v}, #{_obj}, #{_req})"
21
330
  _locator=nil
22
331
  rc=false
23
- if _v.has_key?('locator')
332
+
333
+ if _v.is_a?(Hash) && _v.has_key?('visible_when') && _v['visible_when'].is_a?(Array)
334
+ Scoutui::Logger::LogMgr.instance.info __FILE__ + (__LINE__).to_s + " visible_when_always (array) - TBD"
335
+ return rc
336
+ end
337
+
338
+ if _v.is_a?(Hash) && _v.has_key?('locator')
24
339
  _locator = _v['locator'].to_s
25
340
  end
26
341
 
342
+ if _v.is_a?(Hash) && _v.has_key?('reqid')
343
+ _req = _v['reqid']
344
+ end
345
+
27
346
  if !_locator.nil? && _v.has_key?('visible_when') && _v['visible_when'].match(/always/i)
28
- Scoutui::Logger::LogMgr.instance.info "Verify #{_k} - #{_locator} always visible - #{!_obj.nil?.to_s}"
29
- Testmgr::TestReport.instance.getReq('UI').get_child('visible_when').add(!_obj.nil?, "Verify #{_k} - #{_locator} always visible")
347
+ Scoutui::Logger::LogMgr.instance.asserts.info "Verify #{_k} - #{_locator} always visible - #{(!_obj.nil?).to_s}"
348
+ Testmgr::TestReport.instance.getReq(_req).get_child('visible_when').add(!_obj.nil?, "Verify #{_k} - #{_locator} always visible")
349
+ rc=true
350
+ end
351
+ rc
352
+ end
353
+
354
+ def visible_when_title(_k, page_elt, _obj, my_driver, _req='UI')
355
+ _processed=false
356
+
357
+ if page_elt.is_a?(Hash) && page_elt.has_key?('reqid')
358
+ _req = page_elt['reqid']
359
+ end
360
+
361
+ Scoutui::Logger::LogMgr.instance.info __FILE__ + (__LINE__).to_s + " visible_when_title(#{_k}, #{page_elt}, #{_obj}, #{_req})"
362
+ _req='UI' if _req.nil? || _req.empty?
363
+
364
+ if page_elt.is_a?(Hash) && page_elt.has_key?('visible_when') && !page_elt['visible_when'].is_a?(Array) && page_elt['visible_when'].match(/title\(/i)
365
+ _processed=true
366
+
367
+ current_title = my_driver.title.strip
368
+
369
+ _t = page_elt['visible_when'].match(/title\((.*)\)/)[1].to_s
370
+
371
+ expected_title = Regexp.new(_t)
372
+ rc=!current_title.match(expected_title).nil?
373
+
374
+
375
+ Scoutui::Logger::LogMgr.instance.asserts.info "Verify #{_k} - object exists when expected title, #{expected_title}, matches actual title(#{current_title})"
376
+ Testmgr::TestReport.instance.getReq(_req).get_child('visible_when').add(!_obj.nil? == rc, "Verify #{_k} - object exists when expected title, #{expected_title}, matches actual title(#{current_title}) - #{rc}")
377
+
378
+
379
+ end
380
+
381
+ _processed
382
+ end
383
+
384
+ def visible_when_never(_k, _v, _obj=nil, _req='UI')
385
+ if _v.is_a?(Hash) && _v.has_key?('reqid')
386
+ _req = _v['reqid']
387
+ end
388
+ Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " visible_when_never(#{_k}, #{_v}, #{_obj}, #{_req})"
389
+ _locator=nil
390
+ rc=false
391
+
392
+ if _v.has_key?('locator')
393
+ _locator=_v['locator']
394
+ end
395
+
396
+ if !_locator.nil? && _v.has_key?('visible_when')
397
+
398
+ if _v['visible_when'].is_a?(Array)
399
+ Scoutui::Logger::LogMgr.instance.info __FILE__ + (__LINE__).to_s + " visible_when_never (array) - TBD"
400
+
401
+ elsif _v['visible_when'].match(/never/i)
402
+ Scoutui::Logger::LogMgr.instance.asserts.info "Verify #{_k} #{_locator} never visible - #{_obj.nil?.to_s}"
403
+ Testmgr::TestReport.instance.getReq(_req).get_child('visible_when').add(_obj.nil?, "Verify #{_k} #{_locator} never visible")
30
404
  rc=true
405
+ end
406
+
31
407
  end
408
+
32
409
  rc
33
410
  end
34
411
 
412
+
35
413
  # { "visible_when" => true }
36
414
  def visible_when_skip(_k, _v)
37
415
 
38
- Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " visible_when_visible : #{_v.to_s}" if Scoutui::Utils::TestUtils.instance.isDebug?
416
+ Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " visible_when_skip : #{_v.to_s}" if Scoutui::Utils::TestUtils.instance.isDebug?
39
417
  rc=false
40
418
 
41
- if _v.is_a?(Hash) && _v.has_key?('visible_when') && _v['visible_when'].match(/skip/i)
42
- rc=true
419
+ if _v.is_a?(Hash) && _v.has_key?('visible_when')
420
+
421
+ if _v['visible_when'].is_a?(Array)
422
+ Scoutui::Logger::LogMgr.instance.info __FILE__ + (__LINE__).to_s + " visible_when_skip (array) - TBD"
423
+
424
+ elsif _v['visible_when'].match(/skip/i)
425
+ rc=true
426
+
427
+ Scoutui::Logger::LogMgr.instance.asserts.info "Skip verify #{_k.to_s} - skipped"
428
+ Testmgr::TestReport.instance.getReq('UI').get_child('visible_when').add(nil, "Skip verify #{_k.to_s}")
429
+ end
43
430
 
44
- Scoutui::Logger::LogMgr.instance.asserts.info "Skip verify #{_k.to_s} - skipped"
45
- Testmgr::TestReport.instance.getReq('UI').get_child('visible_when').add(nil, "Skip verify #{_k.to_s}")
46
431
  end
47
432
 
48
433
  rc
49
434
  end
50
435
 
436
+
437
+
438
+ def visible_when_value(_k, page_elt, my_driver, _req='UI')
439
+ if page_elt.is_a?(Hash) && page_elt.has_key?('reqid')
440
+ _req = page_elt['reqid']
441
+ end
442
+ Scoutui::Logger::LogMgr.instance.info __FILE__ + (__LINE__).to_s + " visible_when_value(#{_k}, #{page_elt}, #{_req})"
443
+
444
+ _processed=false
445
+
446
+
447
+
448
+ if page_elt.is_a?(Hash) && page_elt.has_key?('visible_when') && !page_elt['visible_when'].is_a?(Array) && page_elt['visible_when'].match(/^\s*(text|value)\s*\(/)
449
+
450
+ begin
451
+ puts __FILE__ + (__LINE__).to_s + " ==> #{page_elt['visible_when'].match(/^\s*(text|value)\s*\(/)[1]}"
452
+
453
+ _processed=true
454
+ rc=nil
455
+
456
+ condition = page_elt['visible_when'].match(/(value|text)\((.*)\)/)[1].to_s
457
+ tmpObj = page_elt['visible_when'].match(/(value|text)\((.*)\)/)[2].to_s
458
+ expectedVal = page_elt['visible_when'].match(/(value|text)\s*\(.*\)\s*\=\s*(.*)/)[2].to_s
459
+
460
+
461
+
462
+ Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " #{condition} => #{tmpObj} with expected value #{expectedVal}"
463
+
464
+ xpath = Scoutui::Base::UserVars.instance.get(tmpObj)
465
+
466
+ obj = Scoutui::Base::QBrowser.getObject(my_driver, xpath, Scoutui::Commands::Utils.instance.getTimeout)
467
+
468
+ if !obj.nil?
469
+ # Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " value : #{obj.value.to_s}"
470
+ Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " text : #{obj.text.to_s}"
471
+
472
+ if obj.tag_name.downcase.match(/(select)/)
473
+ _opt = Selenium::WebDriver::Support::Select.new(obj)
474
+ opts = _opt.selected_options
475
+ Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " selected => #{opts.to_s}"
476
+
477
+
478
+
479
+ opts.each do |o|
480
+ Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + "| <v, t>::<#{o.attribute('value').to_s}, #{o.text.to_s}>"
481
+
482
+ desc=nil
483
+
484
+
485
+ if condition=='text' && o.text==expectedVal
486
+ desc=" Verify #{_k}, #{locator}, is visible since condition (#{condition} #{xpath} is met."
487
+ elsif condition=='value' && o.attribute('value').to_s==expectedVal
488
+ desc=" Verify #{_k}, #{locator}, is visible since #{condition} of #{xpath} is #{expectedVal}"
489
+ end
490
+
491
+ if !desc.nil?
492
+ locatorObj = Scoutui::Base::QBrowser.getObject(my_driver, locator, Scoutui::Commands::Utils.instance.getTimeout)
493
+
494
+ Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " LocatorObj : #{locatorObj} : #{!locatorObj.nil? && locatorObj.displayed?}"
495
+
496
+
497
+ Testmgr::TestReport.instance.getReq('UI').tc('visible_when').add(!locatorObj.nil? && locatorObj.displayed?, desc)
498
+ end
499
+
500
+ end
501
+
502
+ else
503
+
504
+ desc=nil
505
+
506
+ locator = page_elt['locator']
507
+
508
+ _rc=false
509
+
510
+ if condition=='text'
511
+ _rc=obj.text==expectedVal
512
+ desc=" Verify #{_k}, #{locator}, is visible since condition '#{condition}' of #{xpath} is #{expectedVal}."
513
+ elsif condition=='value'
514
+ _rc=o.attribute('value').to_s==expectedVal
515
+ desc=" Verify #{_k}, #{locator}, is visible since condition '#{condition}' of #{xpath} is #{expectedVal}"
516
+ end
517
+
518
+ if !desc.nil?
519
+ locatorObj = Scoutui::Base::QBrowser.getObject(my_driver, locator, Scoutui::Commands::Utils.instance.getTimeout)
520
+
521
+ Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + "#{desc} : #{locatorObj} : #{!locatorObj.nil? && locatorObj.displayed? && _rc}"
522
+
523
+
524
+ Testmgr::TestReport.instance.getReq(_req).get_child('visible_when').add(!locatorObj.nil? && locatorObj.displayed? && _rc, desc)
525
+ end
526
+
527
+
528
+ end
529
+
530
+ Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " value : #{obj.attribute('value').to_s}"
531
+ end
532
+
533
+
534
+ rescue => ex
535
+ Scoutui::Logger::LogMgr.instance.warn __FILE__ + (__LINE__).to_s + " Error during processing: #{ex}"
536
+ puts __FILE__ + (__LINE__).to_s + "Backtrace:\n\t#{ex.backtrace.join("\n\t")}"
537
+
538
+ end
539
+
540
+
541
+ # elsif page_elt.has_key?('visible_when') && page_elt['visible_when'].match(/\s*(text|value)\s*\(/)
542
+ # Scoutui::Logger::LogMgr.instance.info __FILE__ + (__LINE__).to_s + " Unknown => #{page_elt}"
543
+
544
+ end
545
+
546
+ _processed
547
+
548
+ end
549
+
550
+
551
+
552
+ def assertPageElement(_k, _v, _obj, my_driver, _req)
553
+
554
+ _processed = true
555
+
556
+ if Scoutui::Base::Assertions.instance.visible_when_always(_k, _v, _obj, _req)
557
+ ;
558
+ elsif Scoutui::Base::Assertions.instance.visible_when_never(_k, _v, _obj, _req)
559
+ ;
560
+ elsif Scoutui::Base::Assertions.instance.visible_when_title(_k, _v, _obj, my_driver, _req)
561
+ ;
562
+ elsif Scoutui::Base::Assertions.instance.visible_when_value(_k, _v, my_driver, _req)
563
+ ;
564
+ elsif Scoutui::Base::Assertions.instance.visible_when_visible(_k, _v, _obj, my_driver, _req)
565
+ ;
566
+ else
567
+ _processed = false
568
+ end
569
+
570
+ _processed
571
+
572
+ end
573
+
574
+
51
575
  # _a : Hash
52
576
  # o locator => String
53
577
  # o visible_when => Hash
54
- def visible_when_visible(_a)
578
+ def visible_when_visible(_k, page_elt, _obj, my_driver, _req='UI')
579
+
580
+ Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " visible_when_visible(#{_k}, #{page_elt}, #{_obj}, mydriver, #{_req}"
581
+
582
+ _processed = false
583
+ if page_elt.has_key?('visible_when') && !page_elt['visible_when'].is_a?(Array) && page_elt['visible_when'].match(/\s*visible\s*\(/)
584
+ _processed = true
585
+
586
+ condition = page_elt['visible_when'].match(/(visible)\((.*)\)/)[1].to_s
587
+ tmpObj = page_elt['visible_when'].match(/(visible)\((.*)\)/)[2].to_s
588
+ expectedVal = page_elt['visible_when'].match(/(visible)\s*\(.*\)\s*\=\s*(.*)/)[2].to_s
589
+
590
+ _locator = Scoutui::Base::UserVars.instance.get(tmpObj)
591
+ depObj = Scoutui::Base::QBrowser.getObject(my_driver, _locator, Scoutui::Commands::Utils.instance.getTimeout)
592
+
593
+ Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + "condition (#{condition}), tmpObj (#{tmpObj}) (#{depObj}), expectedVal (#{expectedVal}) : _obj : #{_obj.displayed?}"
594
+
595
+
596
+ expectedRc = !expectedVal.match(/^\s*true\s*$/i).nil?
597
+
598
+
599
+ _desc=" Verify #{_k} is "
600
+ if expectedRc == !depObj.nil?
601
+ _desc+="visible when visible(#{tmpObj}) is #{expectedRc}"
602
+
603
+ Scoutui::Logger::LogMgr.instance.asserts.info __FILE__ + (__LINE__).to_s + _desc + " - #{!_obj.nil?}"
604
+ Testmgr::TestReport.instance.getReq(_req).get_child('visible_when_visible').add(!_obj.nil?, __FILE__ + (__LINE__).to_s + _desc)
605
+
606
+ else
607
+ _desc+="not visible when visible(#{tmpObj}) is #{!depObj.nil?} (expected:#{expectedRc})"
608
+
609
+ Scoutui::Logger::LogMgr.instance.asserts.info __FILE__ + (__LINE__).to_s + _desc + " - #{_obj.nil?}"
610
+ Testmgr::TestReport.instance.getReq(_req).get_child('visible_when_visible').add(_obj.nil?, __FILE__ + (__LINE__).to_s + _desc)
611
+ end
612
+
613
+ end
55
614
 
615
+ _processed
56
616
  end
57
617
 
58
618
  end