sparkling_watir 0.0.8 → 0.0.9

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: a1fb79506e6d1a4f5fac02234aa27b306dc4257b9ad233b431791f201161e2df
4
- data.tar.gz: ab09ba90d145c958825ef0defe79f277d53cccf32fd9709e3ef89a90d14ef1ad
3
+ metadata.gz: 745cf8cf8519ffaa825bf1f3cce1406947e01728984d1e16d25c91760cbf7252
4
+ data.tar.gz: 1b0582fa83851aa78db87b418f784fae19f8b56ceb34fe667e8c3212890ad300
5
5
  SHA512:
6
- metadata.gz: 48911c738df981dcf3637f4699f9b6754a1708836bf4de69644bed5978fa95f62862d09bc4d6a3cc2c5c1966ae16862fadf90c844d52c4004b24b9b534e5baca
7
- data.tar.gz: 9cd71b1a686cb352805548dec1fa3fdeadd7d5d127d892ea952208f118beee85739a3d98ad77cb7c461d21b8babe739503283b054e04f6759923fcd6078448d7
6
+ metadata.gz: 27a94eb8cdffcd2053207e161cb3ddf373a4d248b5bf9643cf63089a492136680714b8b02e7ae87ae17d52e2b867d5116b9b9ed3251a74160b324b728c496d6f
7
+ data.tar.gz: 2f45fedf202e66d39f2bd9469dcf6c1040893fdc87171d8c8fbd15e82dee20b3742427f93e704002768ac0260c1aaf3460dea32b23bf6814b2b5d9716f27e646
data/Gemfile.lock ADDED
@@ -0,0 +1,90 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sparkling_watir (0.0.9)
5
+ appium_lib_core (~> 7.0.0)
6
+ watir (~> 7.1.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ appium_lib_core (7.0.0)
12
+ faye-websocket (~> 0.11.0)
13
+ selenium-webdriver (~> 4.2, < 4.11)
14
+ ast (2.4.2)
15
+ diff-lcs (1.5.0)
16
+ eventmachine (1.2.7)
17
+ faye-websocket (0.11.2)
18
+ eventmachine (>= 0.12.0)
19
+ websocket-driver (>= 0.5.1)
20
+ json (2.6.3)
21
+ language_server-protocol (3.17.0.3)
22
+ parallel (1.23.0)
23
+ parser (3.2.2.3)
24
+ ast (~> 2.4.1)
25
+ racc
26
+ racc (1.7.1)
27
+ rainbow (3.1.1)
28
+ rake (13.0.6)
29
+ regexp_parser (2.8.1)
30
+ rexml (3.2.5)
31
+ rspec (3.11.0)
32
+ rspec-core (~> 3.11.0)
33
+ rspec-expectations (~> 3.11.0)
34
+ rspec-mocks (~> 3.11.0)
35
+ rspec-core (3.11.0)
36
+ rspec-support (~> 3.11.0)
37
+ rspec-expectations (3.11.1)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.11.0)
40
+ rspec-mocks (3.11.2)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.11.0)
43
+ rspec-support (3.11.1)
44
+ rubocop (1.54.2)
45
+ json (~> 2.3)
46
+ language_server-protocol (>= 3.17.0)
47
+ parallel (~> 1.10)
48
+ parser (>= 3.2.2.3)
49
+ rainbow (>= 2.2.2, < 4.0)
50
+ regexp_parser (>= 1.8, < 3.0)
51
+ rexml (>= 3.2.5, < 4.0)
52
+ rubocop-ast (>= 1.28.0, < 2.0)
53
+ ruby-progressbar (~> 1.7)
54
+ unicode-display_width (>= 2.4.0, < 3.0)
55
+ rubocop-ast (1.29.0)
56
+ parser (>= 3.2.1.0)
57
+ rubocop-performance (1.15.2)
58
+ rubocop (>= 1.7.0, < 2.0)
59
+ rubocop-ast (>= 0.4.0)
60
+ rubocop-rspec (2.9.0)
61
+ rubocop (~> 1.19)
62
+ ruby-progressbar (1.13.0)
63
+ rubyzip (2.3.2)
64
+ selenium-webdriver (4.10.0)
65
+ rexml (~> 3.2, >= 3.2.5)
66
+ rubyzip (>= 1.2.2, < 3.0)
67
+ websocket (~> 1.0)
68
+ unicode-display_width (2.4.2)
69
+ watir (7.1.0)
70
+ regexp_parser (>= 1.2, < 3)
71
+ selenium-webdriver (~> 4.0)
72
+ websocket (1.2.9)
73
+ websocket-driver (0.7.5)
74
+ websocket-extensions (>= 0.1.0)
75
+ websocket-extensions (0.1.5)
76
+
77
+ PLATFORMS
78
+ x86_64-darwin-21
79
+
80
+ DEPENDENCIES
81
+ bundler (~> 2.4.14)
82
+ rake (~> 13.0.6)
83
+ rspec (~> 3.11.0)
84
+ rubocop (~> 1.27)
85
+ rubocop-performance (~> 1.15.0)
86
+ rubocop-rspec (~> 2.9.0)
87
+ sparkling_watir!
88
+
89
+ BUNDLED WITH
90
+ 2.4.17
data/README.md CHANGED
@@ -27,7 +27,7 @@ Or install it yourself as:
27
27
  $ gem install sparkling_watir
28
28
 
29
29
  If you want to run the tests on iOS just create a simulator that is an iPhone 8 with os 15.5 or you can change
30
- the capabilities in spec/config/caps and you can download the testing app [here](https://github.com/cloudgrey-io/the-app/releases/tag/v1.10.0)
30
+ the capabilities in spec/config/caps, and you can download the testing app [here](https://github.com/cloudgrey-io/the-app/releases/tag/v1.10.0)
31
31
 
32
32
  All the credit for the testing app goes to Jonathan Lipps.
33
33
 
@@ -35,6 +35,153 @@ If you want to switch between android and iOS capabilties just run:
35
35
 
36
36
  $ rake platform[android] or rake platform[ios]
37
37
 
38
+ ## Initialize driver
39
+
40
+ You can initialize the driver with the following code:
41
+
42
+ ```ruby
43
+ app = SparklingWatir::App.new(caps: opts)
44
+ ```
45
+ The capabilities should include the server url
46
+
47
+ ## Gestures
48
+
49
+ You can use the following gestures:
50
+
51
+ **Tap:** Tap on an element
52
+
53
+ ```ruby
54
+ app.tap on: button
55
+ ```
56
+
57
+ **Double tap:** Double tap on an element
58
+
59
+ ```ruby
60
+ app.double_tap on: button
61
+ ```
62
+
63
+ **Long press:** Press for a minimum of 0.5 seconds on an element
64
+
65
+ ```ruby
66
+ app.long_press on: button
67
+ ```
68
+
69
+ **Swipe:** Swipes to an element, there are 4 direction available: :up, :down, :left, :right
70
+
71
+ ```ruby
72
+ app.swipe to: button, direction: :up
73
+ ```
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
76
+ ```ruby
77
+ app.scroll into: scrollable_view, for: element, direction: :down
78
+ ```
79
+
80
+
81
+ **More gestures coming soon**
82
+
83
+ ## Element
84
+
85
+ You can use the following methods on an element:
86
+
87
+ **wd:** Get the driver from the element
88
+
89
+ ```ruby
90
+ element.wd
91
+ ```
92
+
93
+ **exists?:** Returns true if element exists, else false
94
+
95
+ ```ruby
96
+ element.exists?
97
+ ```
98
+
99
+ **present?:** Returns true if element is present, else false
100
+
101
+ ```ruby
102
+ element.present?
103
+ ```
104
+
105
+ **enabled?:** Returns true if element is enabled, else false
106
+
107
+ ```ruby
108
+ element.enabled?
109
+ ```
110
+
111
+ **coordinates:** Returns a hash with x and y coordinates
112
+
113
+ ```ruby
114
+ element.coordinates
115
+ ```
116
+
117
+ **size:** Returns a hash with width and height values
118
+
119
+ ```ruby
120
+ element.size
121
+ ```
122
+
123
+ **bounds:** Returns a hash with x and y values representing bounds
124
+
125
+ ```ruby
126
+ element.bounds
127
+ ```
128
+
129
+ **center:** Returns a hash with x and y values representing center
130
+
131
+ ```ruby
132
+ element.center
133
+ ```
134
+
135
+ **attribute(attribute_name):** Returns the attribute value
136
+
137
+ ```ruby
138
+ element.attribute('className')
139
+ ```
140
+
141
+ **text:** Returns the text of the element
142
+
143
+ ```ruby
144
+ element.text
145
+ ```
146
+
147
+ ## Waits
148
+
149
+ You can use the following waits:
150
+
151
+ **wait_until:** Waits until a condition is true
152
+
153
+ ```ruby
154
+ element.wait_until(&:present?)
155
+ ```
156
+
157
+ **wait_while:** Waits while a condition is true
158
+
159
+ ```ruby
160
+ element.wait_while(&:present?)
161
+ ```
162
+
163
+ ## Screenshot
164
+
165
+ You can use the following screenshot methods:
166
+
167
+ **save:** Saves a screenshot at the given path
168
+
169
+ ```ruby
170
+ app.screenshot.save("screenshot.png")
171
+ ```
172
+
173
+ **png:** This method represents the screenshot as a PNG image string.
174
+
175
+ ```ruby
176
+ app.screenshot.png
177
+ ```
178
+
179
+ **base64:** Returns a string representing the screenshot as a Base64 encoded string
180
+
181
+ ```ruby
182
+ app-screenshot.base64
183
+ ```
184
+
38
185
 
39
186
  ## License
40
187
 
@@ -47,10 +47,18 @@ module SparklingWatir
47
47
  end
48
48
 
49
49
  def swipe(opts = {})
50
- coordinates = select_direction(opts[:to], opts[:direction])
50
+ coordinates = select_direction(opts[:to], opts[:direction], opts[:scrollable])
51
51
  execute_swipe(coordinates)
52
52
  end
53
53
 
54
+ def scroll(opts = {})
55
+ timeout = Time.now + 30
56
+ while Time.now < timeout
57
+ swipe to: opts[:into], direction: opts[:direction], scrollable: true
58
+ break if opts[:for].present?
59
+ end
60
+ end
61
+
54
62
  private
55
63
 
56
64
  def execute_swipe(coordinates)
@@ -69,34 +77,49 @@ module SparklingWatir
69
77
  perform finger
70
78
  end
71
79
 
72
- def select_direction(element, direction)
73
- case direction
74
- when :down
75
- start_x = element.center[:x]
76
- start_y = @driver.window_size.height * 0.8
77
- end_x = element.center[:x]
78
- end_y = element.center[:y]
79
- when :up
80
- start_x = @driver.window_size.width / 2
81
- start_y = @driver.window_size.height * 0.2
82
- end_x = element.center[:x]
83
- end_y = element.center[:y] / 0.5
84
- when :left
85
- start_x = @driver.window_size.width
86
- start_y = element.center[:y]
87
- end_x = element.center[:x]
88
- end_y = element.center[:y]
89
- when :right
90
- start_x = @driver.window_size.width
91
- start_y = element.center[:y]
92
- end_x = element.center[:x]
93
- end_y = element.center[:y]
94
- else raise "You selected an invalid direction. The valid directions are: :down, :up, :left, :right"
95
- end
80
+ def select_direction(element, direction, scrollable)
81
+ start_coordinates, end_coordinates = case direction
82
+ when :down
83
+ select_down(element)
84
+ when :up
85
+ select_up(element, scrollable)
86
+ when :left, :right
87
+ select_horizontal(element)
88
+ else
89
+ raise "You selected an invalid direction. The valid directions are: :down, :up, :left, :right"
90
+ end
91
+
96
92
  {
97
- start_coordinates: { x: start_x, y: start_y },
98
- end_coordinates: { x: end_x, y: end_y }
93
+ start_coordinates: { x: start_coordinates[:x], y: start_coordinates[:y] },
94
+ end_coordinates: { x: end_coordinates[:x], y: end_coordinates[:y] }
99
95
  }
100
96
  end
97
+
98
+ def select_down(element)
99
+ start_x = element.center[:x]
100
+ start_y = @driver.window_size.height * 0.8
101
+ end_x = element.center[:x]
102
+ end_y = element.center[:y]
103
+
104
+ [{x: start_x, y: start_y}, {x: end_x, y: end_y}]
105
+ end
106
+
107
+ def select_up(element, scrollable)
108
+ start_x = @driver.window_size.width / 2
109
+ start_y = @driver.window_size.height * 0.2
110
+ end_x = element.center[:x]
111
+ end_y = scrollable ? element.center[:y] : element.center[:y] / 0.5
112
+
113
+ [{x: start_x, y: start_y}, {x: end_x, y: end_y}]
114
+ end
115
+
116
+ def select_horizontal(element)
117
+ start_x = @driver.window_size.width
118
+ start_y = element.center[:y]
119
+ end_x = element.center[:x]
120
+ end_y = element.center[:y]
121
+
122
+ [{x: start_x, y: start_y}, {x: end_x, y: end_y}]
123
+ end
101
124
  end
102
125
  end
@@ -1,17 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
1
  require 'forwardable'
16
2
  require 'logger'
17
3
 
@@ -34,6 +34,18 @@ module SparklingWatir
34
34
  Screenshot.new driver
35
35
  end
36
36
 
37
+ def platform
38
+ capabilities[:platform_name]
39
+ end
40
+
41
+ def android?
42
+ platform == 'Android'
43
+ end
44
+
45
+ def ios?
46
+ platform == 'iOS'
47
+ end
48
+
37
49
  def method_missing(method_name, *arguments, &block)
38
50
  if driver.respond_to? method_name
39
51
  driver.send method_name, *arguments, &block
@@ -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.8'
8
+ spec.version = '0.0.9'
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.8
4
+ version: 0.0.9
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-15 00:00:00.000000000 Z
11
+ date: 2023-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -133,6 +133,7 @@ files:
133
133
  - ".gitignore"
134
134
  - ".rubocop.yml"
135
135
  - Gemfile
136
+ - Gemfile.lock
136
137
  - README.md
137
138
  - Rakefile
138
139
  - lib/sparkling_watir.rb