browza 0.0.1 → 0.0.2.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a59afa3f589a1e3ae62e4382e47ad927303406e2
4
- data.tar.gz: 766ea1a959259523a64282d24886ae9b57fe8774
3
+ metadata.gz: 46ab3b79c7bdaa2d454b94768594d7c02ddd5f7a
4
+ data.tar.gz: a6a1c728eb52d6aece54f428a99d82f242bac1df
5
5
  SHA512:
6
- metadata.gz: 9e67e334582c6717ae08dfb179d64471a0f95cd74ce9e4311d98b34b11a6733f1780e650b87656567033c170fcf3fe45dc4d3fa1273f97fdba8959c8c4132bb9
7
- data.tar.gz: afca6f6ee25601abd9ab7a85b3f6e4baf1cf70dca60f56b4c417c8a66355116d4b810de1e95b4924586ab75e42a14deaf110617318be0eb140454c3e359dc858
6
+ metadata.gz: 4a7342c4068a943d2d9994b92a96427672858165dc3bbdd5f2d21320c5bce750a5348613405f7e4d0524c9440bf9df3a5fa69d7b194e0ee592fc574d97131369
7
+ data.tar.gz: f7d17f6a11aad99be4a76f7ccdf9080bf796eaa5755b986fd8789b78dad207861907978482a8c107ca0ead18dc5797e710635d82981afb4dc95685066fae079d
data/browza.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "bundler", "~> 1.11"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency "rspec", "~> 3.0"
25
- spec.add_development_dependency "appmodel"
25
+ spec.add_development_dependency "appmodel", "~> 0.1.2"
26
26
  spec.add_development_dependency "selenium-webdriver"
27
- spec.add_development_dependency "logging"
27
+ spec.add_development_dependency "logging", "~> 2.2"
28
28
  end
@@ -1,6 +1,7 @@
1
1
  require 'selenium-webdriver'
2
2
  require 'singleton'
3
3
  require 'appmodel'
4
+ require 'logging'
4
5
 
5
6
  module Browza
6
7
 
@@ -12,12 +13,14 @@ class Manager
12
13
  attr_accessor :appModels
13
14
  attr_accessor :browserType
14
15
 
15
- def initialize
16
+ def initialize(logLevel = :warn)
17
+ @logger = Logging.logger(STDOUT)
18
+ @logger.level = logLevel
16
19
  @appModels=[]
17
20
  end
18
21
 
19
22
  def addModel(_a)
20
- puts __FILE__ + (__LINE__).to_s + " [addModel]: #{_a}"
23
+ @logger.debug __FILE__ + (__LINE__).to_s + " [addModel]: #{_a}"
21
24
  @appModels << Appmodel::Model.new(_a)
22
25
  end
23
26
 
@@ -66,7 +69,6 @@ class Manager
66
69
  def _parseLocator(_locator)
67
70
 
68
71
  locator = _locator
69
- _by = :xpath
70
72
 
71
73
  if _locator.is_a?(String)
72
74
 
@@ -104,11 +106,11 @@ class Manager
104
106
  }
105
107
 
106
108
  rescue Selenium::WebDriver::Error::NoSuchElementError
107
- puts __FILE__ + (__LINE__).to_s + " NoSuchElementError : #{_locator}"
109
+ @logger.info __FILE__ + (__LINE__).to_s + " NoSuchElementError : #{_locator}"
108
110
 
109
111
  rescue => ex
110
- puts "Error during processing: #{$!}"
111
- puts "Backtrace:\n\t#{ex.backtrace.join("\n\t")}"
112
+ @logger.warn "Error during processing: #{$!}"
113
+ @logger.warn "Backtrace:\n\t#{ex.backtrace.join("\n\t")}"
112
114
  end
113
115
 
114
116
  rc
@@ -118,7 +120,7 @@ class Manager
118
120
 
119
121
  def getElement(_locator, drv=nil, _timeout=30)
120
122
 
121
- puts __FILE__ + (__LINE__).to_s + " getElement(#{_locator})"
123
+ @logger.debug __FILE__ + (__LINE__).to_s + " getElement(#{_locator})"
122
124
  rc=nil
123
125
  begin
124
126
  locator = _parseLocator(_locator)
@@ -128,6 +130,8 @@ class Manager
128
130
  drv=getDriver()
129
131
  end
130
132
 
133
+ @logger.debug __FILE__ + (__LINE__).to_s + " getElement() => #{locator}"
134
+
131
135
  Selenium::WebDriver::Wait.new(timeout: _timeout).until {
132
136
  _obj = drv.find_element(locator)
133
137
  if _obj.displayed?
@@ -138,11 +142,11 @@ class Manager
138
142
  }
139
143
 
140
144
  rescue Selenium::WebDriver::Error::NoSuchElementError
141
- puts __FILE__ + (__LINE__).to_s + " NoSuchElementError : #{locator}"
145
+ @logger.warn __FILE__ + (__LINE__).to_s + " NoSuchElementError : #{locator}"
142
146
 
143
147
  rescue => ex
144
- puts "Error during processing: #{$!}"
145
- puts "Backtrace:\n\t#{ex.backtrace.join("\n\t")}"
148
+ @logger.warn "Error during processing: #{$!}"
149
+ @logger.warn "Backtrace:\n\t#{ex.backtrace.join("\n\t")}"
146
150
  end
147
151
 
148
152
  rc
@@ -158,23 +162,23 @@ class Manager
158
162
 
159
163
  def switch_into_frame(id)
160
164
  drv = @drv
161
- puts __FILE__ + (__LINE__).to_s + "== switch_into_frame(#{id})"
165
+ @logger.debug __FILE__ + (__LINE__).to_s + "== switch_into_frame(#{id})"
162
166
  _fcnId=" [switch_into_frame]"
163
- puts __FILE__ + (__LINE__).to_s + "#{_fcnId}: (#{id})"
167
+ @logger.debug __FILE__ + (__LINE__).to_s + "#{_fcnId}: (#{id})"
164
168
 
165
169
  hit=nil
166
170
 
167
- if TestUtils.instance.isChrome?(drv)
171
+ if isChrome?(drv)
168
172
 
169
- puts __FILE__ + (__LINE__).to_s + "#{_fcnId}: switch on Chrome browser"
173
+ @logger.debug __FILE__ + (__LINE__).to_s + "#{_fcnId}: switch on Chrome browser"
170
174
  bframes = drv.find_elements(:xpath, '//iframe')
171
175
 
172
- puts __FILE__ + (__LINE__).to_s + "#{_fcnId}: //iframe : size #{bframes.size}"
176
+ @logger.debug __FILE__ + (__LINE__).to_s + "#{_fcnId}: //iframe : size #{bframes.size}"
173
177
 
174
178
  if bframes.size == 0
175
179
  bframes = drv.find_elements(:xpath, '//frame')
176
180
 
177
- puts __FILE__ + (__LINE__).to_s + "#{_fcnId}: //frame : #{bframes.size}"
181
+ @logger.debug __FILE__ + (__LINE__).to_s + "#{_fcnId}: //frame : #{bframes.size}"
178
182
  end
179
183
 
180
184
  for i in 0 .. bframes.size - 1
@@ -187,32 +191,32 @@ class Manager
187
191
  end
188
192
 
189
193
 
190
- puts __FILE__ + (__LINE__).to_s + "[switch_into_frame.chrome]: <tag, id> :: <#{_tag}, #{id} >"
194
+ @logger.debug __FILE__ + (__LINE__).to_s + "[switch_into_frame.chrome]: <tag, id> :: <#{_tag}, #{id} >"
191
195
 
192
196
  if !_tag.empty? && id==_tag
193
197
 
194
198
  hit = bframes[i]
195
199
  drv.switch_to.frame hit
196
200
 
197
- puts __FILE__ + (__LINE__).to_s + "#{_fcnId}: swtichframe to #{i} - #{_tag}"
201
+ @logger.debug __FILE__ + (__LINE__).to_s + "#{_fcnId}: swtichframe to #{i} - #{_tag}"
198
202
  break
199
203
  end
200
204
 
201
205
  rescue => ex
202
- puts "Error during processing: #{$!}"
203
- puts "Backtrace:\n\t#{ex.backtrace.join("\n\t")}"
206
+ @logger.warn "Error during processing: #{$!}"
207
+ @logger.warn "Backtrace:\n\t#{ex.backtrace.join("\n\t")}"
204
208
  end
205
209
 
206
210
  end
207
211
 
208
212
  else
209
213
  # Firefox, IE
210
- puts __FILE__ + (__LINE__).to_s + "#{_fcnId}: drv.switch_to.frame(#{id.to_s}";
214
+ @logger.debug __FILE__ + (__LINE__).to_s + "#{_fcnId}: drv.switch_to.frame(#{id.to_s}";
211
215
 
212
216
  hit = drv.switch_to.frame(id.to_s.strip)
213
217
  end
214
218
 
215
- puts __FILE__ + (__LINE__).to_s + " switch_into_frame(#{id}) => #{hit}"
219
+ @logger.debug __FILE__ + (__LINE__).to_s + " switch_into_frame(#{id}) => #{hit}"
216
220
  hit
217
221
  end
218
222
 
@@ -220,10 +224,10 @@ class Manager
220
224
  def switch_frame(e)
221
225
 
222
226
  drv = @drv
223
- puts __FILE__ + (__LINE__).to_s + "\n\n== self.switch_frame(#{e}) =="
227
+ @logger.debug __FILE__ + (__LINE__).to_s + "\n\n== self.switch_frame(#{e}) =="
224
228
  frames=nil
225
229
  if e.is_a?(Hash) && e.has_key?('page') && e['page'].has_key?('frames')
226
- puts __FILE__ + (__LINE__).to_s + " frames => #{e['page']['frames']}";
230
+ @logger.debug __FILE__ + (__LINE__).to_s + " frames => #{e['page']['frames']}";
227
231
 
228
232
  frames=e['page']['frames']
229
233
  elsif e.is_a?(String)
@@ -232,7 +236,7 @@ class Manager
232
236
 
233
237
 
234
238
  if !frames.nil?
235
- puts __FILE__ + (__LINE__).to_s + " [self.switch_frame]: frames => #{frames}";
239
+ @logger.debug __FILE__ + (__LINE__).to_s + " [self.switch_frame]: frames => #{frames}";
236
240
 
237
241
  # frame_list=frames.split(/(frame\(.*\))\.(?=[\w])/)
238
242
  frame_list=frames.split(/\.(?=frame)/)
@@ -240,39 +244,39 @@ class Manager
240
244
  drv.switch_to.default_content
241
245
 
242
246
  frame_list.each do |_f|
243
- puts __FILE__ + (__LINE__).to_s + " processing #{_f}"
247
+ @logger.debug __FILE__ + (__LINE__).to_s + " processing #{_f}"
244
248
 
245
249
  if !_f.empty?
246
250
  _id = _f.match(/frame\((.*)\)/)[1]
247
251
 
248
- puts __FILE__ + (__LINE__).to_s + " [self.switch_frame]: switch_to.frame #{_id}"
252
+ @logger.debug __FILE__ + (__LINE__).to_s + " [self.switch_frame]: switch_to.frame #{_id}"
249
253
 
250
254
  # Swtich based on browser type
251
255
 
252
- if TestUtils.instance.isChrome?(drv)
256
+ if isChrome?(drv)
253
257
  if switch_into_frame(_id).nil?
254
- puts __FILE__ + (__LINE__).to_s + " Frame with name/id #{_id} not found"
258
+ @logger.debug __FILE__ + (__LINE__).to_s + " Frame with name/id #{_id} not found"
255
259
  break
256
260
  else
257
- puts __FILE__ + (__LINE__).to_s + " Sucessfully switched frame into #{_id}"
261
+ @logger.debug __FILE__ + (__LINE__).to_s + " Sucessfully switched frame into #{_id}"
258
262
  end
259
263
  else
260
- puts __FILE__ + (__LINE__).to_s + " [firefox]: switch_to.frame #{_id}"
264
+ @logger.debug __FILE__ + (__LINE__).to_s + " [firefox]: switch_to.frame #{_id}"
261
265
  drv.switch_to.frame _id
262
266
  end
263
267
 
264
268
  if false
265
269
 
266
270
  if drv.browser.to_s.match(/firefox/i)
267
- puts __FILE__ + (__LINE__).to_s + " [firefox]: switch_to.frame #{_id}"
271
+ @logger.debug __FILE__ + (__LINE__).to_s + " [firefox]: switch_to.frame #{_id}"
268
272
  drv.switch_to.frame _id
269
273
  else
270
274
 
271
275
  if switch_into_frame(_id).nil?
272
- puts __FILE__ + (__LINE__).to_s + " Frame with name/id #{_id} not found"
276
+ @logger.debug __FILE__ + (__LINE__).to_s + " Frame with name/id #{_id} not found"
273
277
  break
274
278
  else
275
- puts __FILE__ + (__LINE__).to_s + " Sucessfully switched frame into #{_id}"
279
+ @logger.debug __FILE__ + (__LINE__).to_s + " Sucessfully switched frame into #{_id}"
276
280
  end
277
281
  end
278
282
 
@@ -287,21 +291,21 @@ class Manager
287
291
  end
288
292
 
289
293
  def findLocator(_locator)
290
- puts __FILE__ + (__LINE__).to_s + " [findLocator]: #{_locator} sz: #{@appModels.length}"
294
+ @logger.debug __FILE__ + (__LINE__).to_s + " [findLocator]: #{_locator} sz: #{@appModels.length}"
291
295
  obj = nil
292
296
  _hit = nil
293
297
  if Appmodel::Model.isPageObject?(_locator) && @appModels.length > 0
294
298
 
295
299
  i=0
296
300
  @appModels.each do |m|
297
- puts __FILE__ + (__LINE__).to_s + " >> #{i}. #{m.class} => #{_locator}"
301
+ @logger.debug __FILE__ + (__LINE__).to_s + " >> #{i}. #{m.class} => #{_locator}"
298
302
  begin
299
303
  ##
300
304
  # FRAMES
301
305
  ##
302
306
  pageObject = m.getPageElement(_locator)
303
307
 
304
- puts __FILE__ + (__LINE__).to_s + " pageObject => #{pageObject}"
308
+ @logger.debug __FILE__ + (__LINE__).to_s + " pageObject => #{pageObject}"
305
309
 
306
310
  unless pageObject.nil?
307
311
  _hit = {}
@@ -317,15 +321,26 @@ class Manager
317
321
  end
318
322
 
319
323
  rescue => ex
320
- puts "Error during processing: #{$!}"
321
- puts "Backtrace:\n\t#{ex.backtrace.join("\n\t")}"
324
+ @logger.warn "Error during processing: #{$!}"
325
+ @logger.warn "Backtrace:\n\t#{ex.backtrace.join("\n\t")}"
322
326
  end
323
327
  end
328
+
329
+ elsif _locator.is_a?(String)
330
+ _hit = Appmodel::Model.parseLocator(_locator)
331
+ elsif _locator.is_a?(Hash)
332
+ _hit = { 'locator' => _locator[:css] } if _locator.has_key?(:css)
333
+ _hit = { 'locator' => _locator['css'] } if _locator.has_key?('css')
334
+ _hit = { 'locator' => _locator[:xpath] } if _locator.has_key?(:xpath)
335
+ _hit = { 'locator' => _locator[:xpath] } if _locator.has_key?('xpath')
336
+
337
+ _hit['frame'] = _locator[:frame] if _locator.has_key?(:frame)
338
+ _hit['frame'] = _locator['frame'] if _locator.has_key?('frame')
324
339
  end
325
340
 
326
341
  if _hit.is_a?(Hash)
327
342
  if _hit.has_key?('frame')
328
- puts __FILE__ + (__LINE__).to_s + "swtich_to_frame : #{_hit['frame']}"
343
+ @logger.debug __FILE__ + (__LINE__).to_s + "swtich_to_frame : #{_hit['frame']}"
329
344
  switch_frame(_hit['frame'])
330
345
  end
331
346
 
@@ -337,7 +352,7 @@ class Manager
337
352
  obj = getElement(Appmodel::Model.toBy(_locator), @drv, 30)
338
353
  end
339
354
 
340
- puts __FILE__ + (__LINE__).to_s + " [return findLocator(#{_locator})] : #{_hit}"
355
+ @logger.debug __FILE__ + (__LINE__).to_s + " [return findLocator(#{_locator})] : #{_hit}"
341
356
  _hit.nil? ? _locator : _hit
342
357
 
343
358
  obj
@@ -345,12 +360,13 @@ class Manager
345
360
 
346
361
 
347
362
  ##
348
- # TestUtils.instance.click('page(sideNav).get(desktop)')
363
+ # Browza.instance.click('page(sideNav).get(desktop)')
349
364
  ##
350
365
  def click(_locator, _drv=nil, _timeout=30)
351
366
  rc = false
352
367
 
353
368
  # obj = getElement(findLocator(_locator), _drv, _timeout)
369
+ @drv.switch_to.default_content
354
370
  obj = findLocator(_locator)
355
371
  if !obj.nil?
356
372
  obj.click
@@ -360,6 +376,48 @@ class Manager
360
376
  rc
361
377
  end
362
378
 
379
+ def highlight(_locator, _drv=nil, _timeout=30)
380
+ rc = false
381
+ style={"color" => 'rgb(255, 16, 16)'}
382
+ color="rgb(255, 0, 0)"
383
+
384
+ obj = findLocator(_locator)
385
+ if !obj.nil?
386
+
387
+
388
+ if style.has_key?("color")
389
+
390
+ color=style.has_key?("color")? style["color"] : 'rgb(255, 16, 16)'
391
+
392
+ _c = style["color"]
393
+
394
+ # TODO: refactor with command 'highlight.rb'
395
+
396
+ if _c.match(/\s*blue/i)
397
+ color='rgb(0, 0, 255)'
398
+ elsif _c.match(/\s*red/i)
399
+ color='rgb(255, 0, 0)'
400
+ elsif _c.match(/\s*yellow/i)
401
+ color='rgb(255, 255, 0)'
402
+ elsif _c.match(/\s*green/i)
403
+ color='rgb(0, 255, 0)'
404
+ elsif _c.match(/\s*gray/i)
405
+ color='rgb(128, 128, 128)'
406
+ end
407
+
408
+ end
409
+
410
+ border=style.has_key?("border")? style["border"] : 1
411
+
412
+ parents = ""
413
+
414
+ @drv.execute_script("hlt = function(c) { c.style.border='solid #{border}px #{color}'; }; return hlt(arguments[0]);", obj)
415
+ rc=true
416
+ end
417
+
418
+ obj.is_a?(Selenium::WebDriver::Element) && rc
419
+ end
420
+
363
421
  def type(_locator, _text, _timeout=30)
364
422
  rc = false
365
423
 
@@ -1,3 +1,3 @@
1
1
  module Browza
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2.beta1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browza
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2.beta1
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-10 00:00:00.000000000 Z
11
+ date: 2017-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: appmodel
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 0.1.2
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 0.1.2
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: selenium-webdriver
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -84,16 +84,16 @@ dependencies:
84
84
  name: logging
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '2.2'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '2.2'
97
97
  description: Lightweight Selenium Automation Framework.
98
98
  email:
99
99
  - h20dragon@outlook.com
@@ -123,9 +123,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
123
  version: '0'
124
124
  required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  requirements:
126
- - - ">="
126
+ - - ">"
127
127
  - !ruby/object:Gem::Version
128
- version: '0'
128
+ version: 1.3.1
129
129
  requirements: []
130
130
  rubyforge_project:
131
131
  rubygems_version: 2.6.2