gridium 1.1.34 → 1.1.35

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: 0af9abadc55783df998e594031676e250b651890
4
- data.tar.gz: be2b54eba7eff445fb35e9b0d3d3650623425714
3
+ metadata.gz: bc44fb52f1320ccaf47d6d2ba4632e29b2f642e0
4
+ data.tar.gz: ce69715beb35d69201f86c9266309afcf536ab42
5
5
  SHA512:
6
- metadata.gz: ef281775a428e8ad329bbd7c170c8ffada0604d2d6441380880843e662176186b0fe1860ec2dd3f78cf7be9ef82aad9982ef58b9bdbe7f4c7c0a63344d7bfa5b
7
- data.tar.gz: 7cc16663352d5f2ab96c7c892585c1ed667bda1bcd0028136a0b440f8909fb66e369a9dc005395778ab8b3b1590854764143da4745b9c4f3ef5b69088fce08a2
6
+ metadata.gz: 6bf31c51af9cf634972368b93d4aceb9423f238b6102015651d2ec96252f69eb932680e99327070ee65ecc165c226cca53c1dfa24d63538b1e471503ffc5c91e
7
+ data.tar.gz: 10c88c36c9c2a03a49604d0f4fc1d79a81e458bd21d798481b8c9d94167d6959e476e422411c7bf5d01f0efcc4209b912bbda6b9841b951a408adbb4645f187d
data/lib/element.rb CHANGED
@@ -5,6 +5,7 @@ require 'spec_data'
5
5
  class Element
6
6
  attr_reader :name, :by, :locator
7
7
 
8
+ class Gridium::InvalidTypeError < StandardError; end
8
9
 
9
10
  def initialize(name, by, locator, opts = {})
10
11
  @name = name
@@ -64,9 +65,9 @@ class Element
64
65
  rescue StandardError => error
65
66
  Log.debug("[GRIDIUM::Element] element.displayed_element rescued: #{error}")
66
67
  if found_element
67
- Log.warn("[GRIDIUM::Element] An element was found, but it was not displayed on the page. Gridium.config.visible_elements_only set to: #{Gridium.config.visible_elements_only} Element: #{self.to_s}")
68
+ Log.warn("[GRIDIUM::Element] An element was found, but it was not displayed on the page. Gridium.config.visible_elements_only set to: #{Gridium.config.visible_elements_only} Element: #{self}")
68
69
  else
69
- Log.warn("[GRIDIUM::Element] Could not find Element: #{self.to_s}")
70
+ Log.warn("[GRIDIUM::Element] Could not find Element: #{self}")
70
71
  end
71
72
  end
72
73
 
@@ -93,6 +94,17 @@ class Element
93
94
  element.attribute(name)
94
95
  end
95
96
 
97
+ # Requires element to have an ID value, to successfully use `document.getElementById`
98
+ def set_attribute(name, value)
99
+ id = self.attribute('id')
100
+ if id.nil? || id.empty?
101
+ Log.warn("[GRIDIUM::Element] #{self} does not have an 'id'. Consider adding one.")
102
+ else
103
+ Log.debug("[GRIDIUM::Element] setting element attribute '#{name}' to '#{value}'")
104
+ ElementExtensions.set_attribute(id, name, value)
105
+ end
106
+ end
107
+
96
108
  def css_value(name)
97
109
  element.css_value(name)
98
110
  end
@@ -204,7 +216,7 @@ class Element
204
216
  end
205
217
 
206
218
  def hover_over
207
- Log.debug("[GRIDIUM::Element] Hovering over element (#{self.to_s})...")
219
+ Log.debug("[GRIDIUM::Element] Hovering over element (#{self})...")
208
220
  # @driver.mouse.move_to(element) # Note: Doesn't work with Selenium 2.42 bindings for Firefox v31
209
221
  # @driver.action.move_to(element).perform
210
222
  # @driver.mouse_over(@locator)
@@ -217,7 +229,7 @@ class Element
217
229
  end
218
230
 
219
231
  def hover_away
220
- Log.debug("[GRIDIUM::Element] Hovering away from element (#{self.to_s})...")
232
+ Log.debug("[GRIDIUM::Element] Hovering away from element (#{self})...")
221
233
  if element.enabled?
222
234
  $verification_passes += 1
223
235
  ElementExtensions.hover_away(self) # Javascript workaround to above issue
@@ -228,7 +240,7 @@ class Element
228
240
 
229
241
  # Raw webdriver mouse over
230
242
  def mouse_over(x: 1, y: 1)
231
- Log.debug("[GRIDIUM::Element] Triggering mouse over for (#{self.to_s})...")
243
+ Log.debug("[GRIDIUM::Element] Triggering mouse over for (#{self})...")
232
244
  if element.enabled?
233
245
  $verification_passes += 1
234
246
  ElementExtensions.mouse_over(self, x: x, y: y)
@@ -237,6 +249,16 @@ class Element
237
249
  end
238
250
  end
239
251
 
252
+ # HTML5 Drag n drop
253
+ # @param [Element] target element to drag to
254
+ def drag_to(target)
255
+ raise Gridium::InvalidTypeError, "source element selector must be ':css'" unless self.by == :css
256
+ raise Gridium::InvalidTypeError, "target element selector must be ':css'" unless target.by == :css
257
+
258
+ Log.debug("[GRIDIUM::Element] Dragging (#{self}) to (#{target})")
259
+ ElementExtensions.drag_to(self, target)
260
+ end
261
+
240
262
  def scroll_into_view
241
263
  if element.enabled?
242
264
  $verification_passes += 1
@@ -247,7 +269,7 @@ class Element
247
269
  end
248
270
 
249
271
  def trigger_onblur
250
- Log.debug("[GRIDIUM::Element] Triggering onblur for (#{self.to_s})...")
272
+ Log.debug("[GRIDIUM::Element] Triggering onblur for (#{self})...")
251
273
  if element.enabled?
252
274
  $verification_passes += 1
253
275
  ElementExtensions.trigger_onblur(self)
@@ -257,7 +279,7 @@ class Element
257
279
  end
258
280
 
259
281
  def jquery_click
260
- Log.debug("[GRIDIUM::Element] JQuery clickin (#{self.to_s})...")
282
+ Log.debug("[GRIDIUM::Element] JQuery clickin (#{self})...")
261
283
  if element.enabled?
262
284
  $verification_passes += 1
263
285
  ElementExtensions.jquery_click(self)
@@ -328,7 +350,7 @@ class Element
328
350
  element_height = self.size.height
329
351
 
330
352
  # ChunkyPNG commands tap into oily_png (performance-enhanced version of chunky_png)
331
- image = ChunkyPNG::Image.from_file(screenshot_path.to_s)
353
+ image = ChunkyPNG::Image.from_file(screenshot_path)
332
354
  image1 = image.crop(location_x, location_y, element_width, element_height)
333
355
  image2 = image1.to_image
334
356
  element_screenshot_path = File.join($current_run_dir, "#{name}__#{timestamp}.png")
@@ -372,7 +394,7 @@ class Element
372
394
  return true
373
395
  end
374
396
  rescue StandardError => e
375
- Log.error("There was a problem comparing element images. #{e.to_s}")
397
+ Log.error("There was a problem comparing element images. #{e.message}")
376
398
  end
377
399
  end
378
400
 
@@ -392,7 +414,7 @@ class Element
392
414
  @element.displayed?
393
415
  rescue StandardError => error
394
416
  Log.debug("[GRIDIUM::Element] element.stale? is true because this error was rescued: #{error}")
395
- Log.warn("[GRIDIUM::Element] Stale element detected.... #{self.to_s}")
417
+ Log.warn("[GRIDIUM::Element] Stale element detected.... #{self}")
396
418
  return true
397
419
  end
398
420
 
@@ -45,5 +45,26 @@ class Gridium::ElementExtensions
45
45
  def jquery_click(element)
46
46
  Driver.execute_script("arguments[0].click().change();", element.element)
47
47
  end
48
+
49
+ #
50
+ # Javascript HTML5 Drag n drop
51
+ # @param [Element] source element (css locator required)
52
+ # @param [Element] target element (css locator required)
53
+ #
54
+ def drag_to(source, target)
55
+ dnd_js = File.read(File.join(File.dirname(__FILE__), "./js/dnd.js"))
56
+ Log.debug("[GRIDIUM::ElementExtensions] dragging '#{source}' to '#{target}'")
57
+ Driver.execute_script_driver(dnd_js + "$('#{source.locator}').simulateDragDrop({ dropTarget: '#{target.locator}'});")
58
+ end
59
+
60
+ #
61
+ # Use Javascript to set element attribute value from :id
62
+ # @param [String] id
63
+ # @param [String] Attribute
64
+ # @param [String] value
65
+ #
66
+ def set_attribute(id, attr, val)
67
+ Driver.execute_script_driver("document.getElementById('#{id}').setAttribute('#{attr}', '#{val}')");
68
+ end
48
69
  end
49
70
  end
data/lib/js/dnd.js ADDED
@@ -0,0 +1,58 @@
1
+ //
2
+ // dnd.js
3
+ // HTML5 Javascript Drag_n_drop helper
4
+ // Selenium will not support this natively
5
+ //
6
+ (function( $ ) {
7
+ $.fn.simulateDragDrop = function(options) {
8
+ return this.each(function() {
9
+ new $.simulateDragDrop(this, options);
10
+ });
11
+ };
12
+ $.simulateDragDrop = function(elem, options) {
13
+ this.options = options;
14
+ this.simulateEvent(elem, options);
15
+ };
16
+ $.extend($.simulateDragDrop.prototype, {
17
+ simulateEvent: function(elem, options) {
18
+ /*Simulating drag start*/
19
+ var type = 'dragstart';
20
+ var event = this.createEvent(type);
21
+ this.dispatchEvent(elem, type, event);
22
+
23
+ /*Simulating drop*/
24
+ type = 'drop';
25
+ var dropEvent = this.createEvent(type, {});
26
+ dropEvent.dataTransfer = event.dataTransfer;
27
+ this.dispatchEvent($(options.dropTarget)[0], type, dropEvent);
28
+
29
+ /*Simulating drag end*/
30
+ type = 'dragend';
31
+ var dragEndEvent = this.createEvent(type, {});
32
+ dragEndEvent.dataTransfer = event.dataTransfer;
33
+ this.dispatchEvent(elem, type, dragEndEvent);
34
+ },
35
+ createEvent: function(type) {
36
+ var event = document.createEvent("CustomEvent");
37
+ event.initCustomEvent(type, true, true, null);
38
+ event.dataTransfer = {
39
+ data: {
40
+ },
41
+ setData: function(type, val){
42
+ this.data[type] = val;
43
+ },
44
+ getData: function(type){
45
+ return this.data[type];
46
+ }
47
+ };
48
+ return event;
49
+ },
50
+ dispatchEvent: function(elem, type, event) {
51
+ if(elem.dispatchEvent) {
52
+ elem.dispatchEvent(event);
53
+ }else if( elem.fireEvent ) {
54
+ elem.fireEvent("on"+type, event);
55
+ }
56
+ }
57
+ });
58
+ })(jQuery);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gridium
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.34
4
+ version: 1.1.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Urban
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-20 00:00:00.000000000 Z
11
+ date: 2017-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -155,6 +155,7 @@ files:
155
155
  - lib/element_verification.rb
156
156
  - lib/gridium.rb
157
157
  - lib/gridium/version.rb
158
+ - lib/js/dnd.js
158
159
  - lib/log.rb
159
160
  - lib/page.rb
160
161
  - lib/s3.rb