sparkling_watir 0.0.9 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 745cf8cf8519ffaa825bf1f3cce1406947e01728984d1e16d25c91760cbf7252
4
- data.tar.gz: 1b0582fa83851aa78db87b418f784fae19f8b56ceb34fe667e8c3212890ad300
3
+ metadata.gz: 6d1718777f4727027f7138b2693954512a8f9ec34947923c544f04e4223dc9bc
4
+ data.tar.gz: c63f086a9ea7a9730c04a5339f6a4344748bcde91a3e51331bb071a629556b10
5
5
  SHA512:
6
- metadata.gz: 27a94eb8cdffcd2053207e161cb3ddf373a4d248b5bf9643cf63089a492136680714b8b02e7ae87ae17d52e2b867d5116b9b9ed3251a74160b324b728c496d6f
7
- data.tar.gz: 2f45fedf202e66d39f2bd9469dcf6c1040893fdc87171d8c8fbd15e82dee20b3742427f93e704002768ac0260c1aaf3460dea32b23bf6814b2b5d9716f27e646
6
+ metadata.gz: e84c10cf081151adcd7578d5de4133acf80366f96ee0b3b1b55f94691e94a990d2039b0c3d022c9e0e68c20de1cdafff1f71fc69b0c69292fca90685178ec211
7
+ data.tar.gz: 5199b89a3ad87ee8aeb84064f0ec1ae31f645818b19828d97fea5727e81dd2cd42959db657b20abda386319f4e9af9e5a82b9c467d37bc4bcdf6ee9d3cca152a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sparkling_watir (0.0.9)
4
+ sparkling_watir (0.1.1)
5
5
  appium_lib_core (~> 7.0.0)
6
6
  watir (~> 7.1.0)
7
7
 
data/README.md CHANGED
@@ -72,9 +72,11 @@ app.long_press on: button
72
72
  app.swipe to: button, direction: :up
73
73
  ```
74
74
 
75
- **Scroll:** Scrolls until it finds an element, you need to pass a scrollable view to scroll into, there are 4 direction available: :up, :down, :left, :right
75
+ **Scroll:** Scrolls until it finds an element, you need to pass a scrollable view to scroll into, there are 4 direction available: :up, :down, :left, :right.
76
+ The default duration is 30 seconds.
77
+
76
78
  ```ruby
77
- app.scroll into: scrollable_view, for: element, direction: :down
79
+ app.scroll into: scrollable_view, for: element, direction: :down, duration: 40
78
80
  ```
79
81
 
80
82
 
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'gestures'
4
3
  require_relative 'wait'
5
4
 
6
5
  module SparklingWatir
@@ -8,17 +7,19 @@ module SparklingWatir
8
7
  # This is a element in the native app context
9
8
  #
10
9
  class Element
11
- attr_reader :driver
10
+ attr_reader :driver, :selector
11
+ attr_accessor :element
12
12
 
13
13
  include Waitable
14
14
 
15
- def initialize(driver, selector)
15
+ def initialize(driver = nil, selector = nil, element = nil)
16
16
  @driver = driver
17
17
  @selector = selector
18
+ @element = element
18
19
  end
19
20
 
20
21
  def wd
21
- @element || locate
22
+ element || locate
22
23
  end
23
24
 
24
25
  def exists?
@@ -32,7 +33,7 @@ module SparklingWatir
32
33
 
33
34
  def present?
34
35
  assert_exists
35
- @element.displayed?
36
+ element&.displayed?
36
37
  rescue Watir::Exception::UnknownObjectException
37
38
  false
38
39
  end
@@ -41,21 +42,21 @@ module SparklingWatir
41
42
 
42
43
  def enabled?
43
44
  assert_exists
44
- @element.enabled?
45
+ element&.enabled?
45
46
  rescue Watir::Exception::UnknownObjectException
46
47
  false
47
48
  end
48
49
 
49
50
  def coordinates
50
51
  assert_exists
51
- @element.location
52
+ element&.location
52
53
  end
53
54
 
54
55
  alias location coordinates
55
56
 
56
57
  def size
57
58
  assert_exists
58
- @element.size
59
+ element&.size
59
60
  end
60
61
 
61
62
  def bounds
@@ -84,16 +85,15 @@ module SparklingWatir
84
85
  private
85
86
 
86
87
  def locate
87
- @element = @driver.find_element(@selector.keys.first, @selector.values.first)
88
+ @element ||= driver&.find_element(selector)
88
89
  rescue Selenium::WebDriver::Error::NoSuchElementError
89
90
  nil
90
91
  end
91
92
 
92
93
  def assert_exists
93
- locate unless @element
94
- return if @element
94
+ locate unless element
95
95
 
96
- raise Watir::Exception::UnknownObjectException
96
+ raise Watir::Exception::UnknownObjectException unless element
97
97
  end
98
98
  end
99
99
  end
@@ -0,0 +1,57 @@
1
+ require_relative 'element'
2
+
3
+ module SparklingWatir
4
+ class ElementCollection
5
+ include Enumerable
6
+
7
+ attr_reader :driver, :selector
8
+
9
+ def initialize(driver, selector)
10
+ @driver = driver
11
+ @selector = selector
12
+ @collection = create_collection
13
+ end
14
+
15
+ def add(element)
16
+ @collection << element
17
+ end
18
+
19
+ def each
20
+ @collection.each do |element|
21
+ yield element
22
+ end
23
+ end
24
+
25
+ alias length count
26
+ alias size count
27
+
28
+ alias empty? none?
29
+
30
+ alias exist? any?
31
+ alias exists? any?
32
+
33
+ def to_a
34
+ @collection
35
+ end
36
+
37
+ def [](value)
38
+ @collection[value]
39
+ end
40
+
41
+ def first
42
+ @collection.first
43
+ end
44
+
45
+ def last
46
+ @collection.last
47
+ end
48
+
49
+ private
50
+
51
+ def create_collection
52
+ elements = driver.find_elements selector
53
+
54
+ elements.map { |element| Element.new(driver, nil, element) }
55
+ end
56
+ end
57
+ end
@@ -52,7 +52,8 @@ module SparklingWatir
52
52
  end
53
53
 
54
54
  def scroll(opts = {})
55
- timeout = Time.now + 30
55
+ duration = opts[:duration] || 30
56
+ timeout = Time.now + duration
56
57
  while Time.now < timeout
57
58
  swipe to: opts[:into], direction: opts[:direction], scrollable: true
58
59
  break if opts[:for].present?
@@ -30,6 +30,10 @@ module SparklingWatir
30
30
  Element.new(driver, selector)
31
31
  end
32
32
 
33
+ def elements(selector)
34
+ ElementCollection.new(driver, selector)
35
+ end
36
+
33
37
  def screenshot
34
38
  Screenshot.new driver
35
39
  end
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'sparkling_watir'
8
- spec.version = '0.0.9'
8
+ spec.version = '0.1.1'
9
9
  spec.authors = ['Agustin Pequeno']
10
10
  spec.email = ['agustin.pe94@gmail.com']
11
11
  spec.homepage = 'https://github.com/aguspe/sparkling_watir'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sparkling_watir
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Agustin Pequeno
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-20 00:00:00.000000000 Z
11
+ date: 2023-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -138,6 +138,7 @@ files:
138
138
  - Rakefile
139
139
  - lib/sparkling_watir.rb
140
140
  - lib/sparkling_watir/element.rb
141
+ - lib/sparkling_watir/element_collection.rb
141
142
  - lib/sparkling_watir/gestures.rb
142
143
  - lib/sparkling_watir/logger.rb
143
144
  - lib/sparkling_watir/screenshot.rb