appium_lib 9.4.0 → 9.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,20 +7,47 @@ module Appium
7
7
  private
8
8
 
9
9
  # @private
10
- def _button_visible_selectors
10
+ def _button_visible_selectors_xpath
11
11
  "//#{Button}|#{ImageButton}"
12
12
  end
13
13
 
14
+ def _button_visible_selectors(opts = {})
15
+ button_index = opts.fetch :button_index, false
16
+ image_button_index = opts.fetch :image_button_index, false
17
+
18
+ if button_index && image_button_index
19
+ "new UiSelector().className(#{Button}).instance(#{button_index});" \
20
+ "new UiSelector().className(#{ImageButton}).instance(#{image_button_index});"
21
+ else
22
+ "new UiSelector().className(#{Button});" \
23
+ "new UiSelector().className(#{ImageButton});"
24
+ end
25
+ end
26
+
14
27
  # @private
28
+ # For automationName is uiautomator2
29
+ def _button_exact_string_xpath(value)
30
+ string_visible_exact_xpath(Button, value) +
31
+ string_visible_exact_xpath(ImageButton, value).sub(/\A\/\//, '|')
32
+ end
33
+
15
34
  def _button_exact_string(value)
16
- string_visible_exact(Button, value) +
17
- string_visible_exact(ImageButton, value).sub(/\A\/\//, '|')
35
+ button = string_visible_exact Button, value
36
+ image_button = string_visible_exact ImageButton, value
37
+ button + image_button
18
38
  end
19
39
 
20
40
  # @private
41
+ # For automationName is uiautomator2
42
+ def _button_contains_string_xpath(value)
43
+ string_visible_contains_xpath(Button, value) +
44
+ string_visible_contains_xpath(ImageButton, value).sub(/\A\/\//, '|')
45
+ end
46
+
21
47
  def _button_contains_string(value)
22
- string_visible_contains(Button, value) +
23
- string_visible_contains(ImageButton, value).sub(/\A\/\//, '|')
48
+ button = string_visible_contains Button, value
49
+ image_button = string_visible_contains ImageButton, value
50
+ button + image_button
24
51
  end
25
52
 
26
53
  public
@@ -36,12 +63,21 @@ module Appium
36
63
  index = value
37
64
  raise "#{index} is not a valid index. Must be >= 1" if index <= 0
38
65
 
39
- result = find_elements(:xpath, _button_visible_selectors)[value - 1]
40
- raise Selenium::WebDriver::Error::NoSuchElementError unless result
66
+ if automation_name_is_uiautomator2?
67
+ result = find_elements(:xpath, _button_visible_selectors_xpath)[value - 1]
68
+ raise Selenium::WebDriver::Error::NoSuchElementError unless result
69
+ else
70
+ result = find_element :uiautomator, _button_visible_selectors(index: index)
71
+ end
72
+
41
73
  return result
42
74
  end
43
75
 
44
- find_element :xpath, _button_contains_string(value)
76
+ if automation_name_is_uiautomator2?
77
+ find_element :xpath, _button_contains_string_xpath(value)
78
+ else
79
+ find_element :uiautomator, _button_contains_string(value)
80
+ end
45
81
  end
46
82
 
47
83
  # Find all buttons containing value.
@@ -49,36 +85,66 @@ module Appium
49
85
  # @param value [String] the value to search for
50
86
  # @return [Array<Button>]
51
87
  def buttons(value = false)
52
- return find_elements :xpath, _button_visible_selectors unless value
53
- find_elements :xpath, _button_contains_string(value)
88
+ if automation_name_is_uiautomator2?
89
+ return find_elements :xpath, _button_visible_selectors_xpath unless value
90
+ find_elements :xpath, _button_contains_string_xpath(value)
91
+ else
92
+ return find_elements :uiautomator, _button_visible_selectors unless value
93
+ find_elements :uiautomator, _button_contains_string(value)
94
+ end
54
95
  end
55
96
 
56
97
  # Find the first button.
57
98
  # @return [Button]
58
99
  def first_button
59
- find_element :xpath, _button_visible_selectors
100
+ if automation_name_is_uiautomator2?
101
+ find_element :xpath, _button_visible_selectors_xpath
102
+ else
103
+ find_element :uiautomator, _button_visible_selectors(button_index: 0, image_button_index: 0)
104
+ end
60
105
  end
61
106
 
62
107
  # Find the last button.
63
108
  # @return [Button]
64
109
  def last_button
65
- result = find_elements(:xpath, _button_visible_selectors).last
66
- raise Selenium::WebDriver::Error::NoSuchElementError unless result
67
- result
110
+ if automation_name_is_uiautomator2?
111
+ result = find_elements(:xpath, _button_visible_selectors_xpath).last
112
+ raise Selenium::WebDriver::Error::NoSuchElementError unless result
113
+ result
114
+ else
115
+ # uiautomator index doesn't support last
116
+ # and it's 0 indexed
117
+ button_index = tags(Button).length
118
+ button_index -= 1 if button_index > 0
119
+ image_button_index = tags(ImageButton).length
120
+ image_button_index -= 1 if image_button_index > 0
121
+
122
+ find_element :uiautomator,
123
+ _button_visible_selectors(button_index: button_index,
124
+ image_button_index: image_button_index)
125
+ end
68
126
  end
69
127
 
70
128
  # Find the first button that exactly matches value.
71
129
  # @param value [String] the value to match exactly
72
130
  # @return [Button]
73
131
  def button_exact(value)
74
- find_element :xpath, _button_exact_string(value)
132
+ if automation_name_is_uiautomator2?
133
+ find_element :xpath, _button_exact_string_xpath(value)
134
+ else
135
+ find_element :uiautomator, _button_exact_string(value)
136
+ end
75
137
  end
76
138
 
77
139
  # Find all buttons that exactly match value.
78
140
  # @param value [String] the value to match exactly
79
141
  # @return [Array<Button>]
80
142
  def buttons_exact(value)
81
- find_elements :xpath, _button_exact_string(value)
143
+ if automation_name_is_uiautomator2?
144
+ find_elements :xpath, _button_exact_string_xpath(value)
145
+ else
146
+ find_elements :uiautomator, _button_exact_string(value)
147
+ end
82
148
  end
83
149
  end # module Android
84
150
  end # module Appium
@@ -279,13 +279,13 @@ module Appium
279
279
  end
280
280
 
281
281
  # Returns a string that matches the first element that contains value
282
- #
283
- # example: complex_find_contains 'UIATextField', 'sign in'
282
+ # For automationName is uiautomator2
283
+ # example: string_visible_contains_xpath 'UIATextField', 'sign in'
284
284
  #
285
285
  # @param class_name [String] the class name for the element
286
286
  # @param value [String] the value to search for
287
287
  # @return [String]
288
- def string_visible_contains(class_name, value)
288
+ def string_visible_contains_xpath(class_name, value)
289
289
  r_id = resource_id(value, " or @resource-id='#{value}'")
290
290
 
291
291
  if class_name == '*'
@@ -297,12 +297,37 @@ module Appium
297
297
  " or contains(translate(@content-desc,'#{value.upcase}', '#{value}'), '#{value}')" + r_id + ']'
298
298
  end
299
299
 
300
+ # Returns a string that matches the first element that contains value
301
+ # For automationName is Appium
302
+ # example: string_visible_contains 'UIATextField', 'sign in'
303
+ #
304
+ # @param class_name [String] the class name for the element
305
+ # @param value [String] the value to search for
306
+ # @return [String]
307
+ def string_visible_contains(class_name, value)
308
+ value = %("#{value}")
309
+ if class_name == '*'
310
+ return (resource_id(value, "new UiSelector().resourceId(#{value});") +
311
+ "new UiSelector().descriptionContains(#{value});" \
312
+ "new UiSelector().textContains(#{value});")
313
+ end
314
+
315
+ class_name = %("#{class_name}")
316
+ resource_id(value, "new UiSelector().className(#{class_name}).resourceId(#{value});") +
317
+ "new UiSelector().className(#{class_name}).descriptionContains(#{value});" \
318
+ "new UiSelector().className(#{class_name}).textContains(#{value});"
319
+ end
320
+
300
321
  # Find the first element that contains value
301
322
  # @param element [String] the class name for the element
302
323
  # @param value [String] the value to search for
303
324
  # @return [Element]
304
325
  def complex_find_contains(element, value)
305
- find_element :xpath, string_visible_contains(element, value)
326
+ if automation_name_is_uiautomator2?
327
+ find_element :xpath, string_visible_contains_xpath(element, value)
328
+ else
329
+ find_element :uiautomator, string_visible_contains(element, value)
330
+ end
306
331
  end
307
332
 
308
333
  # Find all elements containing value
@@ -310,15 +335,20 @@ module Appium
310
335
  # @param value [String] the value to search for
311
336
  # @return [Array<Element>]
312
337
  def complex_finds_contains(element, value)
313
- find_elements :xpath, string_visible_contains(element, value)
338
+ if automation_name_is_uiautomator2?
339
+ find_elements :xpath, string_visible_contains_xpath(element, value)
340
+ else
341
+ find_elements :uiautomator, string_visible_contains(element, value)
342
+ end
314
343
  end
315
344
 
316
345
  # @private
317
346
  # Create an string to exactly match the first element with target value
347
+ # For automationName is uiautomator2
318
348
  # @param class_name [String] the class name for the element
319
349
  # @param value [String] the value to search for
320
350
  # @return [String]
321
- def string_visible_exact(class_name, value)
351
+ def string_visible_exact_xpath(class_name, value)
322
352
  r_id = resource_id(value, " or @resource-id='#{value}'")
323
353
 
324
354
  if class_name == '*'
@@ -328,12 +358,36 @@ module Appium
328
358
  "//#{class_name}[@text='#{value}' or @content-desc='#{value}'" + r_id + ']'
329
359
  end
330
360
 
361
+ # @private
362
+ # Create an string to exactly match the first element with target value
363
+ # @param class_name [String] the class name for the element
364
+ # @param value [String] the value to search for
365
+ # @return [String]
366
+ def string_visible_exact(class_name, value)
367
+ value = %("#{value}")
368
+
369
+ if class_name == '*'
370
+ return (resource_id(value, "new UiSelector().resourceId(#{value});") +
371
+ "new UiSelector().description(#{value});" \
372
+ "new UiSelector().text(#{value});")
373
+ end
374
+
375
+ class_name = %("#{class_name}")
376
+ resource_id(value, "new UiSelector().className(#{class_name}).resourceId(#{value});") +
377
+ "new UiSelector().className(#{class_name}).description(#{value});" \
378
+ "new UiSelector().className(#{class_name}).text(#{value});"
379
+ end
380
+
331
381
  # Find the first element exactly matching value
332
382
  # @param class_name [String] the class name for the element
333
383
  # @param value [String] the value to search for
334
384
  # @return [Element]
335
385
  def complex_find_exact(class_name, value)
336
- find_element :xpath, string_visible_exact(class_name, value)
386
+ if automation_name_is_uiautomator2?
387
+ find_element :xpath, string_visible_exact_xpath(class_name, value)
388
+ else
389
+ find_element :uiautomator, string_visible_exact(class_name, value)
390
+ end
337
391
  end
338
392
 
339
393
  # Find all elements exactly matching value
@@ -341,7 +395,11 @@ module Appium
341
395
  # @param value [String] the value to search for
342
396
  # @return [Element]
343
397
  def complex_finds_exact(class_name, value)
344
- find_elements :xpath, string_visible_exact(class_name, value)
398
+ if automation_name_is_uiautomator2?
399
+ find_elements :xpath, string_visible_exact_xpath(class_name, value)
400
+ else
401
+ find_elements :uiautomator, string_visible_exact(class_name, value)
402
+ end
345
403
  end
346
404
 
347
405
  # Returns XML string for the current page
@@ -1,5 +1,5 @@
1
1
  module Appium
2
2
  # Version and Date are defined on the 'Appium' module, not 'Appium::Common'
3
- VERSION = '9.4.0'.freeze unless defined? ::Appium::VERSION
4
- DATE = '2017-04-17'.freeze unless defined? ::Appium::DATE
3
+ VERSION = '9.4.1'.freeze unless defined? ::Appium::VERSION
4
+ DATE = '2017-04-19'.freeze unless defined? ::Appium::DATE
5
5
  end
@@ -474,6 +474,12 @@ module Appium
474
474
  !@automation_name.nil? && 'xcuitest'.casecmp(@automation_name).zero?
475
475
  end
476
476
 
477
+ # Return true if automationName is 'uiautomator2'
478
+ # @return [Boolean]
479
+ def automation_name_is_uiautomator2?
480
+ !@automation_name.nil? && 'uiautomator2'.casecmp(@automation_name).zero?
481
+ end
482
+
477
483
  # Return true if the target Appium server is over REQUIRED_VERSION_XCUITEST.
478
484
  # If the Appium server is under REQUIRED_VERSION_XCUITEST, then error is raised.
479
485
  # @return [Boolean]
@@ -1,3 +1,11 @@
1
+ #### v9.4.0 2017-04-17
2
+
3
+ - [9492690](https://github.com/appium/ruby_lib/commit/9492690f80efaab79ce165e16dd335fca9717c4a) Release 9 4 0 (#545)
4
+ - [2ea94c3](https://github.com/appium/ruby_lib/commit/2ea94c3933f1ecd1362c33f306348236facefc37) add mobile gesture (#542)
5
+ - [1c7dd0f](https://github.com/appium/ruby_lib/commit/1c7dd0ff844265e76b3f2e15a0e6b3651005518f) use xpath instead of uiselectors (#544)
6
+ - [5841a39](https://github.com/appium/ruby_lib/commit/5841a39d60b0986f1a1dd786b910bfbd6223d124) add mobile gesture for XCUITest (#537)
7
+
8
+
1
9
  #### v9.3.8 2017-04-13
2
10
 
3
11
  - [7a7cf44](https://github.com/appium/ruby_lib/commit/7a7cf44c3cb11a90142285b8e8d731dc452b89eb) Release 9 3 8 (#540)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appium_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.4.0
4
+ version: 9.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - code@bootstraponline.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-17 00:00:00.000000000 Z
11
+ date: 2017-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: selenium-webdriver