appmodel 0.1.0.1.pre → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/appmodel.gemspec +1 -0
- data/lib/appmodel/model/model.rb +397 -0
- data/lib/appmodel/version.rb +1 -1
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41efe743b89aa154adcefdb0c23bd0363d488f2a
|
4
|
+
data.tar.gz: f01726521d2eb27b3a959369f9c87245f86ddc50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85a79431825b09e89f4ab2479d6773254982fd15a8edf97db08f19657f6ecf98089927ec96e8e6df513bebf66bc620c220414b523011a51630ec40ef4cc2b52c
|
7
|
+
data.tar.gz: d0e7e8a9385838606cee347a62ffcf3d64c4853a4ef1e264b31ec6376f9ba4951bed5ceb91a8983438d1ca88e0381d817de366ee8b2913371aeb653e17469fd7
|
data/appmodel.gemspec
CHANGED
@@ -0,0 +1,397 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'logging'
|
3
|
+
|
4
|
+
module Appmodel
|
5
|
+
|
6
|
+
class Model
|
7
|
+
attr_accessor :_file
|
8
|
+
attr_accessor :app_model
|
9
|
+
|
10
|
+
def initialize(f=nil)
|
11
|
+
|
12
|
+
@logger = Logging.logger(STDOUT)
|
13
|
+
@logger.level = :warn
|
14
|
+
|
15
|
+
unless f.nil?
|
16
|
+
@_file=f
|
17
|
+
loadPages(@_file)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.toBy(_target, appModel=nil)
|
22
|
+
_by=:xpath
|
23
|
+
_with = nil
|
24
|
+
_locator = !_target.nil? ? _target.clone : nil
|
25
|
+
|
26
|
+
if Appmodel::Model.isPageObject?(_locator) && !appModel.nil?
|
27
|
+
_pg = appModel.getPageElement(_locator)
|
28
|
+
if !_pg.nil?
|
29
|
+
_locator = _pg['locator']
|
30
|
+
else
|
31
|
+
_locator=nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
if _locator.is_a?(String)
|
36
|
+
if _locator.match(/^\s*css\s*=/)
|
37
|
+
_with = _locator.match(/^\s*css\s*=(.*)\s*$/)[1]
|
38
|
+
seleniumLocator = { :css => _with }
|
39
|
+
elsif _locator.match(/^\s*\//)
|
40
|
+
seleniumLocator = { :xpath => _locator }
|
41
|
+
elsif _locator.match(/^\s*\.\//)
|
42
|
+
seleniumLocator = { :xpath => _locator }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
seleniumLocator
|
47
|
+
end
|
48
|
+
|
49
|
+
# _a : frame(xyz).frame(123), <locator>
|
50
|
+
def self.parseLocator(_locator)
|
51
|
+
hit=nil
|
52
|
+
|
53
|
+
if _locator.is_a?(String)
|
54
|
+
|
55
|
+
rc=_locator.match(/^\s*([([fF]rame\([^\(]*?\)\.)]*)\.([lL]ocator\((.*)\))\s*$/)
|
56
|
+
|
57
|
+
if rc
|
58
|
+
hit = { 'frame' => rc[1], 'locator' => rc[3] }
|
59
|
+
elsif _locator.match(/^\s*[lL]ocator\((.*)\)\s*$/)
|
60
|
+
hit = { 'locator' => _locator.match(/^\s*[lL]ocator\((.*)\)\s*$/)[1] }
|
61
|
+
else
|
62
|
+
rc=_locator.match(/^\s*([([fF]rame\([^\(]*?\)\.)]*)\.([lL]ocator\((.*)\))\s*$/)
|
63
|
+
|
64
|
+
if rc
|
65
|
+
hit = { 'frame' => rc[1], 'locator' => rc[2]}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
elsif _locator.is_a?(Hash) && _locator.has_key?('locator')
|
70
|
+
hit = { 'locator' => _locator['locator']}
|
71
|
+
if _locator.has_key?('frame')
|
72
|
+
hit['frame'] = _locator['frame']
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
hit
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
def self.isPageObject?(_locator)
|
82
|
+
rc = false
|
83
|
+
if _locator.is_a?(String)
|
84
|
+
if _locator.match(/^\s*page\s*\(\s*[\w\d_\-]+\s*\)/i)
|
85
|
+
rc=true
|
86
|
+
elsif _locator.match(/^\s*frame\(.*\)\.locator\(.*\)\s*$/)
|
87
|
+
rc=true
|
88
|
+
end
|
89
|
+
|
90
|
+
elsif _locator.is_a?(Hash)
|
91
|
+
rc = _locator.has_key?('locator') || _locator.has_key?(:locator)
|
92
|
+
end
|
93
|
+
|
94
|
+
rc
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
def getAppModel()
|
100
|
+
@app_model
|
101
|
+
end
|
102
|
+
|
103
|
+
def loadPages(jlist)
|
104
|
+
|
105
|
+
json_list=[]
|
106
|
+
if jlist.kind_of?(String)
|
107
|
+
json_list << jlist
|
108
|
+
else
|
109
|
+
json_list=jlist
|
110
|
+
end
|
111
|
+
|
112
|
+
jsonData={}
|
113
|
+
json_list.each { |f|
|
114
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " JSON.parse(#{f})"
|
115
|
+
|
116
|
+
begin
|
117
|
+
data_hash = JSON.parse File.read(f)
|
118
|
+
jsonData.merge!(data_hash)
|
119
|
+
rescue JSON::ParserError
|
120
|
+
@logger.fatal "raise JSON::ParseError - #{f.to_s}"
|
121
|
+
raise "JSONLoadError"
|
122
|
+
end
|
123
|
+
|
124
|
+
}
|
125
|
+
@logger.debug "merged jsonData => " + jsonData.to_json
|
126
|
+
@app_model = jsonData
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
# getPageElement("page(login).get(login_form).get(button)")
|
131
|
+
def getPageElement(s)
|
132
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " getPageElement(#{s})"
|
133
|
+
|
134
|
+
if s.match(/^\s*\//) || s.match(/^\s*css\s*=/i) || s.match(/^\s*#/)
|
135
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " getPageElement(#{s} return nil"
|
136
|
+
return nil
|
137
|
+
end
|
138
|
+
|
139
|
+
hit = @app_model
|
140
|
+
|
141
|
+
nodes = s.split(/\./)
|
142
|
+
|
143
|
+
if nodes
|
144
|
+
nodes.each { |elt|
|
145
|
+
|
146
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " process #{elt}"
|
147
|
+
getter = elt.split(/\(/)[0]
|
148
|
+
_obj = elt.match(/\((.*)\)/)[1]
|
149
|
+
|
150
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " getter : #{getter} obj: #{_obj}"
|
151
|
+
|
152
|
+
if getter.downcase.match(/(page|pg)/)
|
153
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " -- process page --"
|
154
|
+
hit=@app_model[_obj]
|
155
|
+
elsif getter.downcase=='get'
|
156
|
+
|
157
|
+
if !hit.nil? && hit.has_key?(_obj)
|
158
|
+
hit=hit[_obj]
|
159
|
+
|
160
|
+
if hit.is_a?(String) && hit.match(/\s*(file)\((.*)\)/)
|
161
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " LOAD Sub pageObject: #{hit}"
|
162
|
+
end
|
163
|
+
|
164
|
+
else
|
165
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " Missing getter : #{_obj.to_s}"
|
166
|
+
return nil
|
167
|
+
end
|
168
|
+
|
169
|
+
else
|
170
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " getter : #{getter} is unknown."
|
171
|
+
return nil
|
172
|
+
end
|
173
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " HIT => #{hit}"
|
174
|
+
}
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
hit
|
179
|
+
|
180
|
+
end
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
# visible_when: hover(page(x).get(y).get(z))
|
185
|
+
def itemize(condition='visible_when', _action='hover', _pgObj=nil)
|
186
|
+
@results=hits(nil, @app_model, condition, _action, _pgObj)
|
187
|
+
@logger.debug "[itemize] => #{@results}"
|
188
|
+
@results
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
def hits(parent, h, condition, _action, pg)
|
193
|
+
# @logger.debug __FILE__ + (__LINE__).to_s + " collect_item_attributes(#{h})"
|
194
|
+
result = []
|
195
|
+
|
196
|
+
if h.is_a?(Hash)
|
197
|
+
|
198
|
+
h.each do |k, v|
|
199
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " Key: #{k} => #{v}"
|
200
|
+
if k == condition
|
201
|
+
# h[k].each {|k, v| result[k] = v } # <= tweak here
|
202
|
+
if !v.is_a?(Array) && v.match(/^\s*#{_action}\s*\((.*)\)\s*$/i)
|
203
|
+
|
204
|
+
pageObject=v.match(/^\s*#{_action}\s*\((.*)\)\s*$/i)[1]
|
205
|
+
|
206
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " <pg, pageObject> : <#{pg}, #{pageObject}>"
|
207
|
+
|
208
|
+
if pg.nil?
|
209
|
+
result << parent
|
210
|
+
elsif pg == pageObject
|
211
|
+
result << parent
|
212
|
+
end
|
213
|
+
|
214
|
+
elsif v.is_a?(Array)
|
215
|
+
|
216
|
+
v.each do |vh|
|
217
|
+
@logger.debug " =====> #{vh}"
|
218
|
+
|
219
|
+
if vh.is_a?(Hash) && vh.has_key?(condition) && vh[condition].match(/^\s*#{_action}\s*/i)
|
220
|
+
|
221
|
+
pageObject=vh[condition].match(/^\s*#{_action}\s*\((.*)\)\s*$/i)[1]
|
222
|
+
|
223
|
+
|
224
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " matched on #{_action}, pg:#{pg}, #{pageObject}"
|
225
|
+
|
226
|
+
if pg.nil?
|
227
|
+
result << parent
|
228
|
+
elsif pg == pageObject
|
229
|
+
result << parent
|
230
|
+
end
|
231
|
+
|
232
|
+
end
|
233
|
+
|
234
|
+
end
|
235
|
+
|
236
|
+
end
|
237
|
+
|
238
|
+
elsif v.is_a? Hash
|
239
|
+
if parent.nil?
|
240
|
+
_rc = hits("page(#{k})", h[k], condition, _action, pg)
|
241
|
+
else
|
242
|
+
_rc = hits("#{parent}.get(#{k})", h[k], condition, _action, pg)
|
243
|
+
end
|
244
|
+
|
245
|
+
|
246
|
+
if !(_rc.nil? || _rc.empty?)
|
247
|
+
result << _rc
|
248
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " ADDING #{k} : #{_rc}"
|
249
|
+
result.flatten!
|
250
|
+
end
|
251
|
+
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
end
|
256
|
+
|
257
|
+
result=nil if result.empty?
|
258
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " result : #{result}"
|
259
|
+
result
|
260
|
+
end
|
261
|
+
|
262
|
+
def flattenPageObject(h, path="")
|
263
|
+
rc=iterate(h, path)
|
264
|
+
if rc.is_a?(Array)
|
265
|
+
return rc[0]
|
266
|
+
end
|
267
|
+
|
268
|
+
nil
|
269
|
+
end
|
270
|
+
|
271
|
+
def iterate(h, path="")
|
272
|
+
rc=true
|
273
|
+
assertions=[]
|
274
|
+
|
275
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " ===== iterate(#{h}, #{path}) ====="
|
276
|
+
|
277
|
+
if h.is_a?(String)
|
278
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " => process #{h}"
|
279
|
+
if h.match(/^\s*(page)\s*\(.*\)\s*$/i)
|
280
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " => process Page #{h}"
|
281
|
+
page_elt = getPageElement(h)
|
282
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " => #{page_elt}"
|
283
|
+
assertions << iterate(page_elt, path)
|
284
|
+
else
|
285
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " UNKNOWN: #{h}"
|
286
|
+
assertions << "#{h} : unknown"
|
287
|
+
end
|
288
|
+
|
289
|
+
elsif h.is_a?(Hash) && h.has_key?('locator')
|
290
|
+
|
291
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " == add #{h} =="
|
292
|
+
assertions << { :path => path, :data => h }
|
293
|
+
|
294
|
+
elsif h.is_a?(Hash)
|
295
|
+
|
296
|
+
@logger.debug __FILE__ + (__LINE__).to_s + "Keys.size: #{h.keys[0]}"
|
297
|
+
|
298
|
+
if h.keys.size==1 && h[h.keys[0]].is_a?(Hash) && h[h.keys[0]].has_key?('locator')
|
299
|
+
|
300
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " add assertion #{h}"
|
301
|
+
assertions << { :path => path, :data => h }
|
302
|
+
|
303
|
+
elsif h.keys.size==1 && h[h.keys[0]].is_a?(Hash)
|
304
|
+
|
305
|
+
_id = h.keys[0]
|
306
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " LocatorID : #{_id}"
|
307
|
+
|
308
|
+
if true
|
309
|
+
h[_id].each_pair { |_k, _h|
|
310
|
+
|
311
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " | id(#{_id}) => #{_k}, #{_h}"
|
312
|
+
|
313
|
+
if _h.keys.size==1 && _h[_h.keys[0]].is_a?(Hash) && !_h[_h.keys[0]].has_key?('locator')
|
314
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " id(#{_id}) => #{_h}"
|
315
|
+
_a = iterate(_h, "#{path}.#{_id}")
|
316
|
+
_a.each do |_e|
|
317
|
+
assertions << _e
|
318
|
+
end
|
319
|
+
elsif _h.keys.size==1 && _h[_h.keys[0]].is_a?(Hash) && _h[_h.keys[0]].has_key?('locator')
|
320
|
+
assertions << { :path => "#{path}.#{_id}", :data => h[_h.keys[0]] }
|
321
|
+
elsif _h.is_a?(Hash) && _h.has_key?('locator')
|
322
|
+
assertions << { :path => "#{path}.#{_id}.#{_k}", :data => _h }
|
323
|
+
else
|
324
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " | id(#{path}.#{_id}.#{_k}) - #{_h}"
|
325
|
+
|
326
|
+
_h.each do |k, v|
|
327
|
+
# @logger.debug __FILE__ + (__LINE__).to_s + " processing #{_id}.#{k}, #{v}"
|
328
|
+
if v.is_a?(Hash) && v.has_key?('locator')
|
329
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " processing #{_id}.#{_k}.#{k}"
|
330
|
+
elsif v.is_a?(Hash) || v.is_a?(Array)
|
331
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " processing #{_id}.#{k} - #{v}"
|
332
|
+
_a = iterate(v, "#{path}.#{_id}.#{k}")
|
333
|
+
_a.each do |_e|
|
334
|
+
assertions << _e
|
335
|
+
end
|
336
|
+
else
|
337
|
+
puts("Assert => k is #{k}, value is #{v}")
|
338
|
+
# assertions << "#{k} #{v}"
|
339
|
+
rc=rc && true
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " adding assertions id(#{_id}.#{_k}) - #{_h}"
|
344
|
+
assertions << "id(#{_id}.#{_k}) - #{_h}"
|
345
|
+
end
|
346
|
+
|
347
|
+
}
|
348
|
+
end
|
349
|
+
|
350
|
+
else
|
351
|
+
|
352
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " ** process #{h} **"
|
353
|
+
_list=Array.new
|
354
|
+
h.each do |k, v|
|
355
|
+
if v.is_a?(Hash) && v.has_key?('locator')
|
356
|
+
|
357
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " add to assertion #{k} => #{v}"
|
358
|
+
_list.push({ :path => "#{path}.get(#{k})", :dat => v })
|
359
|
+
|
360
|
+
@logger.debug " _list ==> #{_list}"
|
361
|
+
elsif v.is_a?(Hash) || v.is_a?(Array)
|
362
|
+
|
363
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " >>>> #{k} => #{v} <<<<<"
|
364
|
+
|
365
|
+
_a = iterate(v, "#{path}.get(#{k})")
|
366
|
+
_a.each do |_e|
|
367
|
+
assertions << _e
|
368
|
+
end
|
369
|
+
else
|
370
|
+
@logger.debug(__FILE__ + (__LINE__).to_s + " k is #{k}, value is #{v}")
|
371
|
+
assertions << "#{k} #{v}"
|
372
|
+
end
|
373
|
+
end
|
374
|
+
|
375
|
+
# assertions << _list.flatten
|
376
|
+
if !_list.empty?
|
377
|
+
_list.each do |_e|
|
378
|
+
assertions << _e
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
382
|
+
end
|
383
|
+
|
384
|
+
else
|
385
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " Huh?"
|
386
|
+
assertions << nil
|
387
|
+
end
|
388
|
+
|
389
|
+
@logger.debug __FILE__ + (__LINE__).to_s + " assertions => #{assertions}"
|
390
|
+
assertions
|
391
|
+
|
392
|
+
end
|
393
|
+
|
394
|
+
end
|
395
|
+
|
396
|
+
end
|
397
|
+
|
data/lib/appmodel/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appmodel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- H20Dragon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: logging
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: Simple, scalable pageObject design and modeling.
|
56
70
|
email:
|
57
71
|
- h20dragon@outlook.com
|
@@ -71,6 +85,7 @@ files:
|
|
71
85
|
- bin/console
|
72
86
|
- bin/setup
|
73
87
|
- lib/appmodel.rb
|
88
|
+
- lib/appmodel/model/model.rb
|
74
89
|
- lib/appmodel/version.rb
|
75
90
|
homepage: http://github.com/h20dragon.
|
76
91
|
licenses:
|
@@ -87,9 +102,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
102
|
version: '0'
|
88
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
104
|
requirements:
|
90
|
-
- - "
|
105
|
+
- - ">="
|
91
106
|
- !ruby/object:Gem::Version
|
92
|
-
version:
|
107
|
+
version: '0'
|
93
108
|
requirements: []
|
94
109
|
rubyforge_project:
|
95
110
|
rubygems_version: 2.6.2
|