scoutui 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,12 +7,16 @@ module Scoutui::Base
7
7
  attr_accessor :dut
8
8
  attr_accessor :accounts
9
9
 
10
- def initialize(f='/Users/pkim/working/nui-qa/apps/gat/data/accounts.yaml')
11
- @accounts = YAML.load_stream File.read(f)
10
+ def initialize(f)
11
+
12
+ if !f.nil?
13
+ @accounts = YAML.load_stream File.read(f)
14
+ end
15
+
12
16
  end
13
17
 
14
18
  def _find(id, attr)
15
- hit = accounts.find { |h| h['account']['loginid'] == id }
19
+ hit = @accounts.find { |h| h['account']['loginid'] == id }
16
20
  if !hit.nil?
17
21
  id=hit['account'][attr]
18
22
  end
@@ -32,7 +36,7 @@ module Scoutui::Base
32
36
 
33
37
  def getUserId(userid)
34
38
  id=nil
35
- hit = accounts.find { |h| h['account']['loginid'].to_s == userid.to_s }
39
+ hit = @accounts.find { |h| h['account']['loginid'].to_s == userid.to_s }
36
40
  if !hit.nil?
37
41
  id=hit['account']['loginid']
38
42
  end
@@ -25,14 +25,36 @@ module Scoutui::Base
25
25
  rc
26
26
  end
27
27
 
28
+ def self.getFirstObject(drv, xpath, _timeout=30)
29
+ rc=nil
30
+ begin
31
+ Selenium::WebDriver::Wait.new(timeout: _timeout).until { drv.find_elements(:xpath => xpath).size > 0 }
32
+ rc=drv.find_elements(:xpath => xpath)[0]
33
+ rescue => ex
34
+ ;
35
+ end
36
+ rc
37
+ end
38
+
28
39
  def self.getObject(drv, xpath, _timeout=30)
29
40
  rc=nil
30
41
  begin
42
+
43
+ if !xpath.match(/^page\([\w\d]+\)/).nil?
44
+
45
+ xpath = Scoutui::Utils::TestUtils.instance.getPageElement(xpath)
46
+ puts __FILE__ + (__LINE__).to_s + " Process page request #{xpath} => #{xpath}" if Scoutui::Utils::TestUtils.instance.isDebug?
47
+ end
48
+
49
+
31
50
  Selenium::WebDriver::Wait.new(timeout: _timeout).until { drv.find_element(:xpath => xpath).displayed? }
32
51
  rc=drv.find_element(:xpath => xpath)
33
52
  rescue => ex
34
53
  ;
35
54
  end
55
+
56
+ puts __FILE__ + (__LINE__).to_s + " getObject(#{xpath}) => #{rc.to_s}" if Scoutui::Utils::TestUtils.instance.isDebug?
57
+
36
58
  rc
37
59
  end
38
60
 
@@ -5,7 +5,7 @@ module Scoutui::Base
5
5
 
6
6
  class TestScout
7
7
  attr_reader :context
8
- attr_reader :test_settings # { host, localization, dut }
8
+ attr_reader :test_settings # { host, dut }
9
9
  attr_reader :userRecord
10
10
  attr_reader :eyesRecord # {'title' , 'app'}
11
11
  attr_reader :eyeScout
@@ -22,9 +22,6 @@ module Scoutui::Base
22
22
 
23
23
  @test_settings=Scoutui::Utils::TestUtils.instance.getTestSettings()
24
24
 
25
- accounts = Scoutui::Base::QAccounts.new()
26
- @userRecord = accounts.getUserRecord(@test_settings['user'])
27
-
28
25
  @eyesRecord = @test_settings['eyes']
29
26
  end
30
27
 
@@ -43,7 +40,7 @@ module Scoutui::Base
43
40
  end
44
41
 
45
42
  def report
46
-
43
+ @eyeScout.generateReport()
47
44
  end
48
45
 
49
46
  def hasSettings?
@@ -113,6 +110,7 @@ module Scoutui::Base
113
110
  ensure
114
111
  puts __FILE__ + (__LINE__ ).to_s + " Close Eyes" if Scoutui::Utils::TestUtils.instance.isDebug?
115
112
  @eyeScout.closeOut()
113
+
116
114
  end
117
115
 
118
116
  end
@@ -11,7 +11,6 @@ module Scoutui::Base
11
11
  attr_accessor :user
12
12
  attr_accessor :eyesReport
13
13
  attr_accessor :url
14
- attr_accessor :localization
15
14
 
16
15
 
17
16
  def initialize(opts)
@@ -23,16 +22,13 @@ module Scoutui::Base
23
22
  @eyesReport=opts[:eyesReport] || nil
24
23
  @url=opts[:url]||nil
25
24
 
26
- @localization_test_data='/Users/pkim/working/nui-qa/apps/gat/tests/localization.json'
27
- @localization_json = File.read(@localization_test_data)
28
- @localizationObj = JSON.parse(@localization_json)
29
25
  end
30
26
 
31
27
  def setConfig(c)
32
28
  if c.instance_of?(Hash)
33
29
  @testConfig=c
34
30
  else
35
- # a JSON file was passed
31
+ # a JSON file was passed (ERROR handling needed)
36
32
  jFile = File.read(c)
37
33
  @testConfig=JSON.parse(jFile)
38
34
  end
@@ -49,12 +45,6 @@ module Scoutui::Base
49
45
  @lang=lang
50
46
  end
51
47
 
52
-
53
- def getLocalization()
54
- # @testConfig["language-mapping"][@lang]
55
- @localizationObj["language-mapping"][@lang]
56
- end
57
-
58
48
  def getUrl()
59
49
  @url
60
50
  end
@@ -9,6 +9,7 @@ module Scoutui::Base
9
9
 
10
10
  def initialize
11
11
  @globals={
12
+ :accounts => '/tmp/qa/accounts.yaml',
12
13
  :browser => 'chrome',
13
14
  :userid => nil,
14
15
  :password => nil,
@@ -17,6 +18,21 @@ module Scoutui::Base
17
18
  }
18
19
  end
19
20
 
21
+ def dump()
22
+ @globals.each_pair do |k, v|
23
+ puts __FILE__ + (__LINE__).to_s + " #{k} => #{v}"
24
+ end
25
+ end
26
+
27
+ def getViewPort()
28
+ arr=Scoutui::Base::UserVars.instance.getVar('eyes.viewport').match(/(\d+)\s*x\s*(\d+)$/i)
29
+ if arr.size==3
30
+ _sz = {:width => arr[1].to_i, :height => arr[2].to_i }
31
+ end
32
+
33
+ _sz
34
+ end
35
+
20
36
  def getBrowserType()
21
37
  @globals[:browser].to_sym
22
38
  end
@@ -26,19 +42,44 @@ module Scoutui::Base
26
42
  end
27
43
 
28
44
  def get(k)
45
+ foundKey=true
46
+
29
47
  v=k
30
48
 
49
+ _rc = k.match(/\$\{(.*)\}$/)
50
+
51
+ # Needs refactoring!
31
52
  if k=='${userid}'
32
53
  k=:userid
33
54
  elsif k=='${password}'
34
55
  k=:password
35
56
  elsif k=='${host}'
36
57
  k=:host
58
+ elsif k.is_a?(Symbol)
59
+ foundKey=true
60
+ elsif !_rc.nil?
61
+ k=_rc[1].to_s
62
+ puts __FILE__ + (__LINE__).to_s + " User Var found => #{k}" if Scoutui::Utils::TestUtils.instance.isDebug?
63
+ if Scoutui::Utils::TestUtils.instance.getTestConfig().has_key?("user_vars")
64
+
65
+ if Scoutui::Utils::TestUtils.instance.getTestConfig()["user_vars"].has_key?(k)
66
+ v=Scoutui::Utils::TestUtils.instance.getTestConfig()["user_vars"][k].to_s
67
+ end
68
+
69
+ end
70
+
71
+ else
72
+ foundKey=false
37
73
  end
38
74
 
39
- if @globals.has_key?(k)
75
+ puts __FILE__ + (__LINE__).to_s + " get(#{k} => #{@globals.has_key?(k)}" if Scoutui::Utils::TestUtils.instance.isDebug?
76
+
77
+ if @globals.has_key?(k) && foundKey
40
78
  v=@globals[k]
41
79
  end
80
+
81
+ puts __FILE__ + (__LINE__).to_s + " get(#{k} => #{@globals.has_key?(k)} ==> #{v.to_s}" if Scoutui::Utils::TestUtils.instance.isDebug?
82
+
42
83
  v
43
84
  end
44
85
 
@@ -9,40 +9,35 @@ module Scoutui::Base
9
9
  end
10
10
 
11
11
 
12
- def self.processExpected(my_driver, e)
13
- puts "\to Expected: #{e['page']['expected'].class.to_s}" if Scoutui::Utils::TestUtils.instance.isDebug?
14
-
15
- if e['page'].has_key?('expected')
16
- expected_list=e['page']['expected']
17
-
18
- expected_list.each_pair do |link_name, xpath|
19
- puts "\t\t#{link_name} => #{xpath}" if Scoutui::Utils::TestUtils.instance.isDebug?
20
-
21
- obj = Scoutui::Base::QBrowser.getObject(my_driver, xpath)
22
-
23
- if obj.nil?
24
- puts " NOT FOUND : #{link_name} with xpath #{xpath}"
25
- else
26
- puts " link object(#{link_name} with xpath #{xpath}=> #{obj.displayed?}"
27
- end
12
+ def self.isClick?(_action)
13
+ !_action.match(/click\(/).nil?
14
+ end
28
15
 
29
- end
30
- end
16
+ def self.isMouseOver(_action)
17
+ !_action.match(/mouseover\(/).nil?
31
18
  end
32
19
 
33
20
 
34
21
  def self.processCommand(_action, e, my_driver)
35
22
  puts __FILE__ + (__LINE__).to_s + " Process ACTION : #{_action}" if Scoutui::Utils::TestUtils.instance.isDebug?
36
23
 
37
- if !_action.match(/type\(/).nil?
24
+ if !_action.match(/pause/).nil?
25
+
26
+ puts " PAUSE";
27
+ gets();
28
+
29
+ elsif !_action.match(/type\(/).nil?
38
30
  _xpath = _action.match(/type\((.*),\s*/)[1].to_s
39
31
  _val = _action.match(/type\(.*,\s*(.*)\)/)[1].to_s
40
32
 
41
33
  puts __FILE__ + (__LINE__).to_s + "Process TYPE #{_val} into #{_xpath}" if Scoutui::Utils::TestUtils.instance.isDebug?
42
34
 
43
35
  obj = Scoutui::Base::QBrowser.getObject(my_driver, _xpath)
36
+
44
37
  if !obj.nil? && !obj.attribute('type').downcase.match(/(text|password)/).nil?
45
38
  obj.send_keys(Scoutui::Base::UserVars.instance.get(_val))
39
+ else
40
+ puts __FILE__ + (__LINE__).to_s + " Unable to process command TYPE => #{obj.to_s}"
46
41
  end
47
42
 
48
43
  end
@@ -50,14 +45,64 @@ module Scoutui::Base
50
45
  if !_action.match(/click\(/).nil?
51
46
  _xpath = _action.match(/click\s*\((.*)\)/)[1].to_s.strip
52
47
  puts __FILE__ + (__LINE__).to_s + " click => #{_xpath}" if Scoutui::Utils::TestUtils.instance.isDebug?
48
+
49
+ _xpath = Scoutui::Base::UserVars.instance.get(_xpath)
50
+
51
+ puts __FILE__ + (__LINE__).to_s + " | translate : #{_xpath}" if Scoutui::Utils::TestUtils.instance.isDebug?
52
+
53
53
  obj = Scoutui::Base::QBrowser.getObject(my_driver, _xpath)
54
- obj.click
54
+ obj.click if obj
55
+ elsif isMouseOver(_action)
56
+ _xpath = _action.match(/mouseover\s*\((.*)\)/)[1].to_s.strip
57
+ obj = Scoutui::Base::QBrowser.getObject(my_driver, _xpath)
58
+ my_driver.action.move_to(obj).perform
55
59
 
56
- processExpected(my_driver, e)
57
60
  end
58
61
 
59
62
  end
60
63
 
64
+ def self.isRun(e)
65
+ _run=nil
66
+ if e["page"].has_key?("run")
67
+ _run = e["page"].has_key?("run").to_s
68
+ end
69
+ _run
70
+ end
71
+
72
+ def self.isSnapIt(e)
73
+ _snapit=false
74
+
75
+ if e["page"].has_key?("snapit")
76
+ _snapit = !(e["page"]["snapit"].to_s.match(/true/i).nil?)
77
+ end
78
+ _snapit
79
+ end
80
+
81
+ def self.processExpected(my_driver, e)
82
+ puts __FILE__ + (__LINE__).to_s + "\to Expected: #{e['page']['expected'].class.to_s}" if Scoutui::Utils::TestUtils.instance.isDebug?
83
+
84
+ if e['page'].has_key?('expected')
85
+ expected_list=e['page']['expected']
86
+
87
+ expected_list.each_pair do |link_name, xpath|
88
+ puts "\t\t#{link_name} => #{xpath}" if Scoutui::Utils::TestUtils.instance.isDebug?
89
+ if !xpath.match(/^page\([\w\d]+\)/).nil?
90
+
91
+ xpath = Scoutui::Utils::TestUtils.instance.getPageElement(xpath)
92
+ puts __FILE__ + (__LINE__).to_s + " Process page request #{xpath} => #{xpath}" if Scoutui::Utils::TestUtils.instance.isDebug?
93
+ end
94
+
95
+ obj = Scoutui::Base::QBrowser.getFirstObject(my_driver, xpath)
96
+
97
+ if obj.nil?
98
+ puts " NOT FOUND : #{link_name} with xpath #{xpath}"
99
+ else
100
+ puts " link object(#{link_name} with xpath #{xpath}=> #{obj.displayed?}" if Scoutui::Utils::TestUtils.instance.isDebug?
101
+ end
102
+
103
+ end
104
+ end
105
+ end
61
106
 
62
107
  # Scoutui::Base::VisualTestFramework.processFile(@drv, @eyes, @test_settings['host'], @test_settings['dut'])
63
108
  def self.processFile(eyeScout, test_settings)
@@ -69,8 +114,18 @@ module Scoutui::Base
69
114
 
70
115
  puts __FILE__ + (__LINE__).to_s + " processFile(#{eyeScout}, #{baseUrl}, #{datafile})" if Scoutui::Utils::TestUtils.instance.isDebug?
71
116
 
117
+ valid_file=false
72
118
  i=0
73
- dut_dupes = YAML.load_stream File.read(datafile)
119
+ begin
120
+ dut_dupes = YAML.load_stream File.read(datafile)
121
+ valid_file=true
122
+ rescue => ex
123
+ puts __FILE__ + (__LINE__).to_s + " Invalid file: #{datafile} - abort processing."
124
+ puts ex.backtrace
125
+ end
126
+
127
+ return if !valid_file
128
+
74
129
  dut_dupes.each do |e|
75
130
  puts '-' * 72 if Scoutui::Utils::TestUtils.instance.isDebug?
76
131
  puts "#{i.to_s}. Processing #{e.inspect}" if Scoutui::Utils::TestUtils.instance.isDebug?
@@ -80,12 +135,15 @@ module Scoutui::Base
80
135
  _name = e["page"]["name"]
81
136
  _url = e["page"]["url"]
82
137
  _skip = e["page"]["skip"]
138
+ _region = e["page"]["region"]
139
+
83
140
 
84
141
  if Scoutui::Utils::TestUtils.instance.isDebug?
85
142
  puts __FILE__ + (__LINE__).to_s + " action: #{_action}"
86
143
  puts __FILE__ + (__LINE__).to_s + " name: #{_name}"
87
144
  puts __FILE__ + (__LINE__).to_s + " url : #{_url}"
88
145
  puts __FILE__ + (__LINE__).to_s + " skip: #{_skip}"
146
+ puts __FILE__ + (__LINE__).to_s + " region: #{_region}"
89
147
  end
90
148
 
91
149
  skipIt = (!_skip.nil?) && (_skip.to_s.strip.downcase=='true')
@@ -96,8 +154,31 @@ module Scoutui::Base
96
154
  next
97
155
  end
98
156
 
157
+
158
+ if !isRun(e).nil?
159
+
160
+ tmpSettings=test_settings.dup
161
+ tmpSettings["dut"]=e["page"]["run"].to_s
162
+
163
+ processFile(eyeScout, tmpSettings)
164
+ puts __FILE__ + (__LINE__).to_s + " Completed execution of subfile" if Scoutui::Utils::TestUtils.instance.isDebug?
165
+ next
166
+ end
167
+
99
168
  if !(_action.nil? || _action.empty?)
100
169
  processCommand(_action, e, my_driver)
170
+ processExpected(my_driver, e)
171
+
172
+ if isSnapIt(e)
173
+ if !_region.nil?
174
+ eyeScout.check_window(_name, _region)
175
+ else
176
+ eyeScout.check_window(_name)
177
+ end
178
+
179
+ # processExpected(my_driver, e)
180
+ end
181
+
101
182
  next
102
183
  end
103
184
 
@@ -116,12 +197,25 @@ module Scoutui::Base
116
197
 
117
198
  puts "\to Expected: #{e['page']['expected'].class.to_s}" if Scoutui::Utils::TestUtils.instance.isDebug?
118
199
 
200
+ processExpected(my_driver, e)
201
+
202
+ if false
203
+
119
204
  if e['page'].has_key?('expected')
120
205
  expected_list=e['page']['expected']
121
206
 
122
207
  expected_list.each_pair do |link_name, xpath|
123
208
  puts "\t\t#{link_name} => #{xpath}" if Scoutui::Utils::TestUtils.instance.isDebug?
124
209
 
210
+ if !xpath.match(/^page\([\w\d]+\)/).nil?
211
+
212
+
213
+ xpath = Scoutui::Utils::TestUtils.instance.getPageElement(xpath)
214
+
215
+ puts __FILE__ + (__LINE__).to_s + " Process page request #{xpath} => #{xpath}"
216
+
217
+ end
218
+
125
219
  obj = Scoutui::Base::QBrowser.getObject(my_driver, xpath)
126
220
 
127
221
  if obj.nil?
@@ -133,7 +227,15 @@ module Scoutui::Base
133
227
  end
134
228
  end
135
229
 
136
- eyeScout.check_window(name)
230
+
231
+ end
232
+
233
+
234
+ if !_region.nil?
235
+ eyeScount.check_window(_name, _region)
236
+ else
237
+ eyeScout.check_window(name)
238
+ end
137
239
 
138
240
  puts "\to links : #{e['page']['links'].class.to_s}" if Scoutui::Utils::TestUtils.instance.isDebug?
139
241
 
@@ -148,7 +250,12 @@ module Scoutui::Base
148
250
  puts __FILE__ + (__LINE__).to_s + " [click]: link object => #{obj.to_s}" if Scoutui::Utils::TestUtils.instance.isDebug?
149
251
  obj.click
150
252
 
151
- eyeScout.check_window(link_name)
253
+ if !_region.nil?
254
+ eyeScount.check_window(_name, _region)
255
+ else
256
+ eyeScout.check_window(link_name)
257
+ end
258
+
152
259
  end
153
260
  end
154
261