sparkling_watir 0.0.8 → 0.1.0

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
  SHA256:
3
- metadata.gz: a1fb79506e6d1a4f5fac02234aa27b306dc4257b9ad233b431791f201161e2df
4
- data.tar.gz: ab09ba90d145c958825ef0defe79f277d53cccf32fd9709e3ef89a90d14ef1ad
3
+ metadata.gz: 3380d869ffa3595391cc478a5d93bdb6236a767040550d964afd5e22da2aef9f
4
+ data.tar.gz: 2bb22863cad09f16c5b67d71350c5c582a2ebaa59783f1c6cb34e6643f9cc9e6
5
5
  SHA512:
6
- metadata.gz: 48911c738df981dcf3637f4699f9b6754a1708836bf4de69644bed5978fa95f62862d09bc4d6a3cc2c5c1966ae16862fadf90c844d52c4004b24b9b534e5baca
7
- data.tar.gz: 9cd71b1a686cb352805548dec1fa3fdeadd7d5d127d892ea952208f118beee85739a3d98ad77cb7c461d21b8babe739503283b054e04f6759923fcd6078448d7
6
+ metadata.gz: 617137f0d20e8d8b47b6b9fb156fb07ebb336cc221693fe83a29ca8161e48c689da354edc829ba284df1217252b5be33e4277c0272add29fc3a2108bc4bd5c87
7
+ data.tar.gz: 8b56fb08ebee6400ec7eeee70ac03c7f7797bdecc18fa1daff0b8f766018af25a13563589e999eac3f6a212fc2b15d249e93fb7685e36a56984967f7af5ec8c2
data/Gemfile.lock ADDED
@@ -0,0 +1,90 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sparkling_watir (0.1.0)
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,155 @@ 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
+ The default duration is 30 seconds.
77
+
78
+ ```ruby
79
+ app.scroll into: scrollable_view, for: element, direction: :down, duration: 40
80
+ ```
81
+
82
+
83
+ **More gestures coming soon**
84
+
85
+ ## Element
86
+
87
+ You can use the following methods on an element:
88
+
89
+ **wd:** Get the driver from the element
90
+
91
+ ```ruby
92
+ element.wd
93
+ ```
94
+
95
+ **exists?:** Returns true if element exists, else false
96
+
97
+ ```ruby
98
+ element.exists?
99
+ ```
100
+
101
+ **present?:** Returns true if element is present, else false
102
+
103
+ ```ruby
104
+ element.present?
105
+ ```
106
+
107
+ **enabled?:** Returns true if element is enabled, else false
108
+
109
+ ```ruby
110
+ element.enabled?
111
+ ```
112
+
113
+ **coordinates:** Returns a hash with x and y coordinates
114
+
115
+ ```ruby
116
+ element.coordinates
117
+ ```
118
+
119
+ **size:** Returns a hash with width and height values
120
+
121
+ ```ruby
122
+ element.size
123
+ ```
124
+
125
+ **bounds:** Returns a hash with x and y values representing bounds
126
+
127
+ ```ruby
128
+ element.bounds
129
+ ```
130
+
131
+ **center:** Returns a hash with x and y values representing center
132
+
133
+ ```ruby
134
+ element.center
135
+ ```
136
+
137
+ **attribute(attribute_name):** Returns the attribute value
138
+
139
+ ```ruby
140
+ element.attribute('className')
141
+ ```
142
+
143
+ **text:** Returns the text of the element
144
+
145
+ ```ruby
146
+ element.text
147
+ ```
148
+
149
+ ## Waits
150
+
151
+ You can use the following waits:
152
+
153
+ **wait_until:** Waits until a condition is true
154
+
155
+ ```ruby
156
+ element.wait_until(&:present?)
157
+ ```
158
+
159
+ **wait_while:** Waits while a condition is true
160
+
161
+ ```ruby
162
+ element.wait_while(&:present?)
163
+ ```
164
+
165
+ ## Screenshot
166
+
167
+ You can use the following screenshot methods:
168
+
169
+ **save:** Saves a screenshot at the given path
170
+
171
+ ```ruby
172
+ app.screenshot.save("screenshot.png")
173
+ ```
174
+
175
+ **png:** This method represents the screenshot as a PNG image string.
176
+
177
+ ```ruby
178
+ app.screenshot.png
179
+ ```
180
+
181
+ **base64:** Returns a string representing the screenshot as a Base64 encoded string
182
+
183
+ ```ruby
184
+ app-screenshot.base64
185
+ ```
186
+
38
187
 
39
188
  ## License
40
189
 
@@ -47,10 +47,19 @@ 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
+ duration = opts[:duration] || 30
56
+ timeout = Time.now + duration
57
+ while Time.now < timeout
58
+ swipe to: opts[:into], direction: opts[:direction], scrollable: true
59
+ break if opts[:for].present?
60
+ end
61
+ end
62
+
54
63
  private
55
64
 
56
65
  def execute_swipe(coordinates)
@@ -69,34 +78,49 @@ module SparklingWatir
69
78
  perform finger
70
79
  end
71
80
 
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
81
+ def select_direction(element, direction, scrollable)
82
+ start_coordinates, end_coordinates = case direction
83
+ when :down
84
+ select_down(element)
85
+ when :up
86
+ select_up(element, scrollable)
87
+ when :left, :right
88
+ select_horizontal(element)
89
+ else
90
+ raise "You selected an invalid direction. The valid directions are: :down, :up, :left, :right"
91
+ end
92
+
96
93
  {
97
- start_coordinates: { x: start_x, y: start_y },
98
- end_coordinates: { x: end_x, y: end_y }
94
+ start_coordinates: { x: start_coordinates[:x], y: start_coordinates[:y] },
95
+ end_coordinates: { x: end_coordinates[:x], y: end_coordinates[:y] }
99
96
  }
100
97
  end
98
+
99
+ def select_down(element)
100
+ start_x = element.center[:x]
101
+ start_y = @driver.window_size.height * 0.8
102
+ end_x = element.center[:x]
103
+ end_y = element.center[:y]
104
+
105
+ [{x: start_x, y: start_y}, {x: end_x, y: end_y}]
106
+ end
107
+
108
+ def select_up(element, scrollable)
109
+ start_x = @driver.window_size.width / 2
110
+ start_y = @driver.window_size.height * 0.2
111
+ end_x = element.center[:x]
112
+ end_y = scrollable ? element.center[:y] : element.center[:y] / 0.5
113
+
114
+ [{x: start_x, y: start_y}, {x: end_x, y: end_y}]
115
+ end
116
+
117
+ def select_horizontal(element)
118
+ start_x = @driver.window_size.width
119
+ start_y = element.center[:y]
120
+ end_x = element.center[:x]
121
+ end_y = element.center[:y]
122
+
123
+ [{x: start_x, y: start_y}, {x: end_x, y: end_y}]
124
+ end
101
125
  end
102
126
  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.1.0'
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.1.0
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