testa_appium_driver 0.1.5 → 0.1.9

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: 57c9443d16200ae583fc1d8a4cae4b27890566bfd0cd919dc7aae5b7e9f371f9
4
- data.tar.gz: 4fd4ec8bd0b7bb3f0f9ccea250873878e17553ef06993d7f11d8c03db224a065
3
+ metadata.gz: d6d109085373d1b5104d594c05d198294301d008d6a59db3069c78af30694ec5
4
+ data.tar.gz: d7cd88ba139a0ee76ed56b7c1c60fba948ddb6986178286c940397b3b30ef0a9
5
5
  SHA512:
6
- metadata.gz: abadbdf89242733883b65c781d2b6875a7a373f5667a7aab7ba4c77bd13bacc4069d7a9ac031d3cc541bc292c9dd48e5bf520dff9dcbb996b8abe6bc5e565e1a
7
- data.tar.gz: 221a32b22c15d0ee23a75cb65fb61862700ff176c13a8fd573878a83896f65f518401a768218b3460fcaef12dc32780199a0e96fa718f07c3a8ac9d43087f0a4
6
+ metadata.gz: 6a4e0b8f0021eebf8adb857ca9ec261b0031d4dca89a83530302b95b0fa82e0f199aeda872031ecbdb3b7f8e6425b6c1be9bc4fec0b97731c91382040e394f7a
7
+ data.tar.gz: fbbd93b4dea4dc65a1350c0453984bfd9c345bf591040de63402ed4958780d730231aeed99e399d2caf30d52e104b961c8b653d1ac077faf403942a23b238447
data/.gitignore CHANGED
@@ -13,4 +13,4 @@
13
13
  /.idea/deployment.xml
14
14
  /.idea/workspace.xml
15
15
  /.idea/misc.xml
16
- Gemfile.lock
16
+ Gemfile.lock
data/.idea/deployment.xml CHANGED
@@ -1,8 +1,15 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <project version="4">
3
- <component name="PublishConfigData">
3
+ <component name="PublishConfigData" autoUpload="On explicit save action" serverName="supertesta.com" preserveTimestamps="false" autoUploadExternalChanges="true">
4
4
  <serverData>
5
5
  <paths name="supertesta.com">
6
+ <serverdata>
7
+ <mappings>
8
+ <mapping deploy="/testa_docker/path_data/testa_appium_driver" local="$PROJECT_DIR$" web="/" />
9
+ </mappings>
10
+ </serverdata>
11
+ </paths>
12
+ <paths name="testa.fun">
6
13
  <serverdata>
7
14
  <mappings>
8
15
  <mapping local="$PROJECT_DIR$" web="/" />
@@ -10,5 +17,6 @@
10
17
  </serverdata>
11
18
  </paths>
12
19
  </serverData>
20
+ <option name="myAutoUpload" value="ON_EXPLICIT_SAVE" />
13
21
  </component>
14
22
  </project>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="RunConfigurationProducerService">
4
+ <option name="ignoredProducers">
5
+ <set>
6
+ <option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
7
+ </set>
8
+ </option>
9
+ </component>
10
+ </project>
data/.idea/sshConfigs.xml CHANGED
@@ -5,6 +5,9 @@
5
5
  <sshConfig authType="PASSWORD" host="supertesta.com" id="ea45cb27-d516-4292-a1f7-430f02857685" port="22" customName="Supertesta.com" nameFormat="CUSTOM" username="testa">
6
6
  <option name="customName" value="Supertesta.com" />
7
7
  </sshConfig>
8
+ <sshConfig authType="PASSWORD" host="testa.fun" id="54640192-a130-4edc-ac3c-f3bc32df1130" port="22" customName="testa.fun" nameFormat="CUSTOM" username="root">
9
+ <option name="customName" value="testa.fun" />
10
+ </sshConfig>
8
11
  </configs>
9
12
  </component>
10
13
  </project>
data/.idea/webServers.xml CHANGED
@@ -9,6 +9,13 @@
9
9
  </advancedOptions>
10
10
  </fileTransfer>
11
11
  </webServer>
12
+ <webServer id="e1897dc5-c089-49e3-802d-1c69de9874a7" name="testa.fun" url="http://something">
13
+ <fileTransfer rootFolder="/ruby_apps" accessType="SFTP" host="testa.fun" port="22" sshConfigId="54640192-a130-4edc-ac3c-f3bc32df1130" sshConfig="testa.fun">
14
+ <advancedOptions>
15
+ <advancedOptions dataProtectionLevel="Private" keepAliveTimeout="0" passiveMode="true" shareSSLContext="true" />
16
+ </advancedOptions>
17
+ </fileTransfer>
18
+ </webServer>
12
19
  </option>
13
20
  </component>
14
21
  </project>
data/README.md CHANGED
@@ -202,12 +202,18 @@ siblings selector can only be used with xpath strategy.
202
202
  - search_views
203
203
  - spinner
204
204
  - spinners
205
+ - switch
206
+ - switches
205
207
  - toast
206
208
  - toasts
207
209
  - toolbar
208
210
  - toolbars
209
211
  - text_view
210
212
  - text_views
213
+ - web_view
214
+ - web_views
215
+ - card_view
216
+ - card_views
211
217
 
212
218
  Adjacent selectors
213
219
  - from_parent
@@ -323,11 +329,15 @@ Type Selector arguments
323
329
 
324
330
  # Scroll actions
325
331
  - each
326
- - align!
327
- - align_top!
328
- - align_bottom!
329
- - align_left!
330
- - align_right!
332
+ - each_down
333
+ - each_up
334
+ - each_left
335
+ - each_right
336
+ - align! (if does not exist, will scroll to find)
337
+ - align_top! (if does not exist, will scroll to find)
338
+ - align_bottom! (if does not exist, will scroll to find)
339
+ - align_left! (if does not exist, will scroll to find)
340
+ - align_right! (if does not exist, will scroll to find)
331
341
  - align
332
342
  - align_top
333
343
  - align_bottom
@@ -355,6 +365,9 @@ Type Selector arguments
355
365
  - as_scrollable
356
366
  - wait_until_exists
357
367
  - wait_while_exists
368
+ - wait_until
369
+ - wait_while
370
+ - when_exists
358
371
  - exists?
359
372
  - long_tap
360
373
 
@@ -24,6 +24,9 @@ module TestaAppiumDriver
24
24
  # @param selectors [Hash]
25
25
  # @return [TestaAppiumDriver::Locator] first element
26
26
  def element(selectors = {})
27
+ unless selectors[:image].nil?
28
+ selectors[:strategy] = FIND_STRATEGY_IMAGE
29
+ end
27
30
  add_selector(selectors)
28
31
  end
29
32
 
@@ -31,24 +34,9 @@ module TestaAppiumDriver
31
34
  # @param params [Hash]
32
35
  # @return [TestaAppiumDriver::Locator] all elements that match given selectors
33
36
  def elements(params = {})
34
- params[:single] = false
35
- add_selector(params)
36
- end
37
-
38
-
39
- # first element that has scrollable: true
40
- # @param selectors [Hash]
41
- # @return [TestaAppiumDriver::Locator] first scrollable element
42
- def scrollable(selectors = {})
43
- selectors[:scrollable] = true
44
- add_selector(selectors)
45
- end
46
-
47
- # all elements that have scrollable: true
48
- # @param params [Hash]
49
- # @return [TestaAppiumDriver::Locator] first scrollable element
50
- def scrollables(params = {})
51
- params[:scrollable] = true
37
+ unless params[:image].nil?
38
+ params[:strategy] = FIND_STRATEGY_IMAGE
39
+ end
52
40
  params[:single] = false
53
41
  add_selector(params)
54
42
  end
@@ -399,5 +387,52 @@ module TestaAppiumDriver
399
387
  add_selector(params)
400
388
  end
401
389
 
390
+
391
+ # first androidx.cardview.widget.CardView element that match given selectors
392
+ # @return [TestaAppiumDriver::Locator]
393
+ def card_view(params = {})
394
+ params[:class] = "androidx.cardview.widget.CardView"
395
+ add_selector(params)
396
+ end
397
+
398
+ # all androidx.cardview.widget.CardView elements that match given selectors
399
+ # @return [TestaAppiumDriver::Locator]
400
+ def card_views(params = {})
401
+ params[:class] = "androidx.cardview.widget.CardView"
402
+ params[:single] = false
403
+ add_selector(params)
404
+ end
405
+
406
+ # first android.widget.Switch element that match given selectors
407
+ # @return [TestaAppiumDriver::Locator]
408
+ def switch(params = {})
409
+ params[:class] = "android.widget.Switch"
410
+ add_selector(params)
411
+ end
412
+
413
+ # all android.widget.Switch elements that match given selectors
414
+ # @return [TestaAppiumDriver::Locator]
415
+ def switches(params = {})
416
+ params[:class] = "android.widget.Switch"
417
+ params[:single] = false
418
+ add_selector(params)
419
+ end
420
+
421
+
422
+ # first android.webkit.WebView element that match given selectors
423
+ # @return [TestaAppiumDriver::Locator]
424
+ def web_view(params = {})
425
+ params[:class] = "android.webkit.WebView"
426
+ add_selector(params)
427
+ end
428
+
429
+ # all android.webkit.WebView elements that match given selectors
430
+ # @return [TestaAppiumDriver::Locator]
431
+ def web_views(params = {})
432
+ params[:class] = "android.webkit.WebView"
433
+ params[:single] = false
434
+ add_selector(params)
435
+ end
436
+
402
437
  end
403
438
  end
@@ -24,6 +24,23 @@ module TestaAppiumDriver
24
24
  end
25
25
 
26
26
 
27
+ def scrollable
28
+ locator = Locator.new(self, self, {single: true})
29
+ locator.xpath_selector = "//androidx.recyclerview.widget.RecyclerView|//android.widget.ScrollView|//android.widget.ListView|//android.widget.HorizontalScrollView"
30
+ locator.ui_selector = "new UiSelector().scrollable(true).instance(0)"
31
+ locator
32
+ end
33
+
34
+
35
+ def scrollables
36
+ locator = Locator.new(self, self, {single: false})
37
+ locator.xpath_selector = "//androidx.recyclerview.widget.RecyclerView|//android.widget.ScrollView|//android.widget.ListView|//android.widget.HorizontalScrollView"
38
+ locator.ui_selector = "new UiSelector().scrollable(true)"
39
+ locator
40
+ end
41
+
42
+
43
+
27
44
  private
28
45
  def handle_testa_opts
29
46
  if @testa_opts[:default_find_strategy].nil?
@@ -7,7 +7,6 @@ module TestaAppiumDriver
7
7
 
8
8
  @driver = get_driver if self.instance_of?(Selenium::WebDriver::Element)
9
9
 
10
- @driver.disable_wait_for_idle
11
10
  if elements.kind_of?(Selenium::WebDriver::Element)
12
11
  r = elements.send(:attribute, name.to_s)
13
12
  r = TestaAppiumDriver::Bounds.from_android(r, @driver) if name.to_s == "bounds"
@@ -15,7 +14,6 @@ module TestaAppiumDriver
15
14
  r = elements.map { |e| e.send(:attribute, name.to_s) }
16
15
  r.map! { |b| TestaAppiumDriver::Bounds.from_android(b, @driver) } if name.to_s == "bounds"
17
16
  end
18
- @driver.enable_wait_for_idle
19
17
  r
20
18
  end
21
19
 
@@ -110,7 +108,7 @@ module TestaAppiumDriver
110
108
  children = self.dup.parent.children.execute
111
109
  index = children.index(this)
112
110
  raise "Index not found" if index.nil?
113
- index
111
+ index.to_i
114
112
  end
115
113
  end
116
114
  end
@@ -36,15 +36,23 @@ module TestaAppiumDriver
36
36
 
37
37
 
38
38
  # resolve selector which will be used for finding element
39
- def strategy_and_selector
39
+ def strategies_and_selectors
40
+ ss = []
40
41
  if @can_use_id_strategy
41
- return FIND_STRATEGY_ID, @can_use_id_strategy
42
+ ss.push({"#{FIND_STRATEGY_ID}": @can_use_id_strategy})
42
43
  end
43
- if (@strategy.nil? && @default_find_strategy == FIND_STRATEGY_UIAUTOMATOR) || @strategy == FIND_STRATEGY_UIAUTOMATOR
44
- [FIND_STRATEGY_UIAUTOMATOR, ui_selector]
45
- elsif (@strategy.nil? && @default_find_strategy == FIND_STRATEGY_XPATH) || @strategy == FIND_STRATEGY_XPATH
46
- [FIND_STRATEGY_XPATH, @xpath_selector]
44
+ if @strategy.nil? || @strategy == FIND_STRATEGY_UIAUTOMATOR
45
+ ss.push({"#{FIND_STRATEGY_UIAUTOMATOR}": ui_selector})
47
46
  end
47
+
48
+ if @strategy.nil? || @strategy == FIND_STRATEGY_XPATH
49
+ ss.push({"#{FIND_STRATEGY_XPATH}": @xpath_selector})
50
+ end
51
+
52
+ if @strategy == FIND_STRATEGY_IMAGE
53
+ ss.push({"#{FIND_STRATEGY_IMAGE}": @image_selector})
54
+ end
55
+ ss
48
56
  end
49
57
 
50
58
 
@@ -89,6 +97,8 @@ module TestaAppiumDriver
89
97
  add_xpath_child_selectors(locator, selectors, single)
90
98
  elsif @strategy == FIND_STRATEGY_UIAUTOMATOR
91
99
  locator = add_uiautomator_child_selector(locator, selectors, single)
100
+ elsif @strategy == FIND_STRATEGY_IMAGE
101
+ locator = add_image_child_selector(locator, selectors, single)
92
102
  else
93
103
  # both paths are valid
94
104
  add_xpath_child_selectors(locator, selectors, single)
@@ -96,7 +106,7 @@ module TestaAppiumDriver
96
106
  end
97
107
 
98
108
  if is_scrollable_selector?(selectors, single)
99
- locator.scrollable_locator = self
109
+ locator.scrollable_locator = locator
100
110
  if selectors[:class] == "android.widget.HorizontalScrollView"
101
111
  locator.scrollable_locator.scroll_orientation = :horizontal
102
112
  else
@@ -123,5 +133,10 @@ module TestaAppiumDriver
123
133
  locator
124
134
  end
125
135
  end
136
+
137
+ def add_image_child_selector(locator, selectors, single)
138
+ params = selectors.merge({single: single, scrollable_locator: locator.scrollable_locator})
139
+ Locator.new(@driver, self, params)
140
+ end
126
141
  end
127
142
  end
@@ -4,8 +4,6 @@ module TestaAppiumDriver
4
4
  private
5
5
 
6
6
  def uiautomator_scroll_to_start_or_end(type)
7
- @driver.disable_wait_for_idle
8
- @driver.disable_implicit_wait
9
7
 
10
8
  scrollable_selector = @scrollable.ui_selector(false)
11
9
  orientation = @scrollable.scroll_orientation == :vertical ? ".setAsVerticalList()" : ".setAsHorizontalList()"
@@ -19,18 +17,12 @@ module TestaAppiumDriver
19
17
  end
20
18
 
21
19
 
22
- @driver.enable_implicit_wait
23
- @driver.enable_wait_for_idle
24
20
  end
25
21
 
26
22
 
27
23
  def uiautomator_scroll_to
28
24
  raise "UiAutomator scroll cannot work with specified direction" unless @direction.nil?
29
25
 
30
-
31
- @driver.disable_wait_for_idle
32
- @driver.disable_implicit_wait
33
-
34
26
  scrollable_selector = @scrollable.ui_selector(false)
35
27
  element_selector = @locator.ui_selector(false)
36
28
  orientation_command = @scrollable.scroll_orientation == :vertical ? ".setAsVerticalList()" : ".setAsHorizontalList()"
@@ -41,15 +33,11 @@ module TestaAppiumDriver
41
33
  rescue
42
34
  # Ignored
43
35
  ensure
44
- @driver.enable_implicit_wait
45
- @driver.enable_wait_for_idle
46
36
  end
47
37
  end
48
38
 
49
39
 
50
40
  def uiautomator_page_or_fling(type, direction)
51
- @driver.disable_wait_for_idle
52
- @driver.disable_implicit_wait
53
41
 
54
42
  scrollable_selector = @scrollable.ui_selector(false)
55
43
  orientation = direction == :up || direction == :down ? ".setAsVerticalList()" : ".setAsHorizontalList()"
@@ -67,8 +55,6 @@ module TestaAppiumDriver
67
55
  rescue
68
56
  # Ignored
69
57
  end
70
- @driver.enable_implicit_wait
71
- @driver.enable_wait_for_idle
72
58
  end
73
59
 
74
60
 
@@ -6,6 +6,8 @@ module TestaAppiumDriver
6
6
  FIND_STRATEGY_XPATH = :xpath
7
7
  FIND_STRATEGY_ID = :id
8
8
  FIND_STRATEGY_NAME = :name
9
+ FIND_STRATEGY_IMAGE = :image
10
+ FIND_STRATEGY_CLASS_CHAIN = :class_chain
9
11
 
10
12
  SCROLL_STRATEGY_UIAUTOMATOR = :uiautomator
11
13
  SCROLL_STRATEGY_W3C = :w3c
@@ -120,7 +120,9 @@ module TestaAppiumDriver
120
120
  command = "#{ command }[@focused=\"#{ hash[:focused] }\"]" unless hash[:focused].nil?
121
121
  command = "#{ command }[@index=\"#{ hash[:index] }\"]" unless hash[:index].nil?
122
122
  command = "#{ command }[@selected=\"#{ hash[:selected] }\"]" unless hash[:selected].nil?
123
- command = "#{ command }[@scrollable=\"#{ hash[:scrollable] }\"]" unless hash[:scrollable].nil?
123
+
124
+ # it seems like you cannot query by scrollable
125
+ # command = "#{ command }[@scrollable=\"#{ hash[:scrollable] }\"]" unless hash[:scrollable].nil?
124
126
  else
125
127
 
126
128
  hash[:type] = hash[:class] unless hash[:class].nil?
@@ -155,6 +157,33 @@ module TestaAppiumDriver
155
157
  command
156
158
  end
157
159
 
160
+
161
+ def hash_to_class_chain(hash, single = true)
162
+ command = "**/"
163
+
164
+ hash[:type] = hash[:class] unless hash[:class].nil?
165
+ hash[:label] = hash[:text] unless hash[:text].nil?
166
+ hash[:name] = hash[:id] unless hash[:id].nil?
167
+ if hash[:type] && hash[:type].kind_of?(String)
168
+ command = "#{ command }#{hash[:type] }"
169
+ else
170
+ command = "#{command}*"
171
+ end
172
+
173
+ command = "#{ command }[`enabled == #{ hash[:enabled] }`]" unless hash[:enabled].nil?
174
+ command = "#{ command }[`label == \"#{ %(#{hash[:label] }) }\"`]" if hash[:label] && hash[:label].kind_of?(String)
175
+ command = "#{ command }[`label CONTAINS \"#{ %(#{hash[:label].source }) }\"`]" if hash[:label] && hash[:label].kind_of?(Regexp)
176
+ command = "#{ command }[`name == \"#{ %(#{hash[:name] }) }\"`]" if hash[:name] && hash[:name].kind_of?(String)
177
+ command = "#{ command }[`name CONTAINS \"#{ %(#{hash[:name].source }) }\"`]" if hash[:name] && hash[:name].kind_of?(Regexp)
178
+ command = "#{ command }[`value == \"#{ %(#{hash[:value] }) }\"`]" if hash[:value] && hash[:value].kind_of?(String)
179
+ command = "#{ command }[`value CONTAINS \"#{ %(#{hash[:value].source }) }\"`]" if hash[:value] && hash[:value].kind_of?(Regexp)
180
+ command = "#{ command }[`visible == #{ hash[:visible] }`]" unless hash[:visible].nil?
181
+
182
+ command += "[1]" if single
183
+
184
+ command
185
+ end
186
+
158
187
  # check if selectors are for a scrollable element
159
188
  # @param [Boolean] single should the command return first instance or all of matched elements
160
189
  # @param [Hash] selectors for fetching elements
@@ -205,6 +234,8 @@ module TestaAppiumDriver
205
234
  :visible,
206
235
  :name,
207
236
  :value,
237
+
238
+ :image
208
239
  ].include?(key) }
209
240
  params = Hash[params.to_a - selectors.to_a]
210
241
 
@@ -250,6 +250,22 @@ module TestaAppiumDriver
250
250
  _fling(:right, _process_deadzone(top, bottom, right, left))
251
251
  end
252
252
 
253
+ def drag_up_by(amount)
254
+ drag_by(amount, direction: :top)
255
+ end
256
+
257
+ def drag_down_by(amount)
258
+ drag_by(amount, direction: :bottom)
259
+ end
260
+
261
+ def drag_left_by(amount)
262
+ drag_by(amount, direction: :left)
263
+ end
264
+
265
+ def drag_right_by(amount)
266
+ drag_by(amount, direction: :right)
267
+ end
268
+
253
269
 
254
270
  # @param [TestaAppiumDriver::Locator, Hash, Selenium::WebDriver::Element, String] to
255
271
  #noinspection RubyYardParamTypeMatch,RubyScope
@@ -273,7 +289,7 @@ module TestaAppiumDriver
273
289
  x = to[:x]
274
290
  y = to[:y]
275
291
  end
276
- _drag_to(x, y)
292
+ _drag_to(bounds.center.x, bounds.center.y, x, y)
277
293
  end
278
294
 
279
295
  def drag_by(amount, direction: :top)
@@ -292,7 +308,7 @@ module TestaAppiumDriver
292
308
  else
293
309
  raise "Unknown direction #{direction}"
294
310
  end
295
- _drag_to(x, y)
311
+ _drag_to(b.center.x, b.center.y, x, y)
296
312
  end
297
313
 
298
314
 
@@ -310,11 +326,11 @@ module TestaAppiumDriver
310
326
  deadzone
311
327
  end
312
328
 
313
- def _drag_to(x, y)
329
+ def _drag_to(x0, y0, x1, y1)
314
330
  sa = ScrollActions.new(@scrollable_locator,
315
331
  locator: self,
316
332
  default_scroll_strategy: @default_scroll_strategy)
317
- sa.drag_to(x, y)
333
+ sa.drag_to(x0, y0, x1, y1)
318
334
  self
319
335
  end
320
336