testa_appium_driver 0.1.32 → 0.2.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: add83f6c9df4e695d9c8869c37d15611e0b87a065c6f844828264784e6d333a5
4
- data.tar.gz: fa96bc1504a4863534aa9557041ce611594e6267c75f8b6a2d300a42605652d3
3
+ metadata.gz: '09d419b756a039134b80c36cbc55e428649d85a1053e56f3253a7ab6b7d92180'
4
+ data.tar.gz: 7b6a010c67667be6a51d88d0d0ce17b5b44c96501051383eb8ebc9a0dc3c34d2
5
5
  SHA512:
6
- metadata.gz: b2fac94a46daef9a2782cc854f959434cc811ea3d853021c626c2b3eb12f9b80b8ce98e666472e916f0f2968524828c6635b9f52f5b0473a9a2f5ab92b230aef
7
- data.tar.gz: 23f90e32e4c4bb11893a5140202b11a6c7d81681833cd3525539ae470144bce5f92611e57b6c0ac75c90cf6f357183e7c38791d123991d21728d2bdc86a0b4b3
6
+ metadata.gz: ce0d991474bc79cd62af1783825c80f896b0bdb9ffce2f9d35d4f78a6fd36f65136bacaadb6fa14577069c2d9532b6c472139271792c7130d205207db348ac3c
7
+ data.tar.gz: 9fd7602e23e312da1ec2bd5927d1988d5bca966a27822683dd1081df39aa752d07f01de80d71f2e1b4cb4bc8a4650afc0cc2e5bb7ccc15d400231cf3cc5df141
@@ -1,107 +1,113 @@
1
1
  module TestaAppiumDriver
2
2
  module Attributes
3
3
 
4
- #noinspection RubyNilAnalysis
5
- def testa_attribute(name, *args)
4
+ # noinspection RubyNilAnalysis
5
+ def testa_attribute(name, *args, **kwargs)
6
6
  if self.instance_of?(::Selenium::WebDriver::Element) || self.instance_of?(::Appium::Core::Element)
7
7
  @driver = get_driver # does not get correct driver
8
8
  elements = self
9
9
  else
10
- elements = execute(*args)
10
+ elements = execute(*args, **kwargs)
11
11
  raise "Element not found" if elements.nil?
12
12
  end
13
-
13
+
14
14
  if elements.kind_of?(::Selenium::WebDriver::Element) || elements.kind_of?(::Appium::Core::Element)
15
- r = elements.send(:attribute, name.to_s)
16
- r = TestaAppiumDriver::Bounds.from_android(r, @driver) if name.to_s == "bounds"
15
+ if name.to_sym == :bounds
16
+ refresh_element = elements.find_element(xpath: ".")
17
+ r = TestaAppiumDriver::Bounds.from_android(refresh_element.send(:attribute, name), @driver)
18
+ else
19
+ r = elements.send(:attribute, name.to_s)
20
+ end
17
21
  else
22
+ # refreshing each element in collection would be too slow
23
+ # ignore the possibility that the bounds could be stale
18
24
  r = elements.map { |e| e.send(:attribute, name.to_s) }
19
- r.map! { |b| TestaAppiumDriver::Bounds.from_android(b, @driver) } if name.to_s == "bounds"
25
+ r.map! { |b| TestaAppiumDriver::Bounds.from_android(b, @driver) } if name.to_sym == :bounds
20
26
  end
21
27
  r
22
28
  end
23
29
 
24
- def text(*args)
25
- testa_attribute("text", *args)
30
+ def text(*args, **kwargs)
31
+ testa_attribute("text", *args, **kwargs)
26
32
  end
27
33
 
28
- def package(*args)
29
- testa_attribute("package", *args)
34
+ def package(*args, **kwargs)
35
+ testa_attribute("package", *args, **kwargs)
30
36
  end
31
37
 
32
- def class_name(*args)
33
- testa_attribute("className", *args)
38
+ def class_name(*args, **kwargs)
39
+ testa_attribute("className", *args, **kwargs)
34
40
  end
35
41
 
36
- def checkable?(*args)
37
- testa_attribute("checkable", *args).to_s == "true"
42
+ def checkable?(*args, **kwargs)
43
+ testa_attribute("checkable", *args, **kwargs).to_s == "true"
38
44
  end
39
45
 
40
- def checked?(*args)
41
- testa_attribute("checked", *args).to_s == "true"
46
+ def checked?(*args, **kwargs)
47
+ testa_attribute("checked", *args, **kwargs).to_s == "true"
42
48
  end
43
49
 
44
- def clickable?(*args)
45
- testa_attribute("clickable", *args).to_s == "true"
50
+ def clickable?(*args, **kwargs)
51
+ testa_attribute("clickable", *args, **kwargs).to_s == "true"
46
52
  end
47
53
 
48
- def desc(*args)
49
- testa_attribute("contentDescription", *args)
54
+ def desc(*args, **kwargs)
55
+ testa_attribute("contentDescription", *args, **kwargs)
50
56
  end
51
57
 
52
- def enabled?(*args)
53
- testa_attribute("enabled", *args).to_s == "true"
58
+ def enabled?(*args, **kwargs)
59
+ testa_attribute("enabled", *args, **kwargs).to_s == "true"
54
60
  end
55
61
 
56
- def focusable?(*args)
57
- testa_attribute("focusable", *args).to_s == "true"
62
+ def focusable?(*args, **kwargs)
63
+ testa_attribute("focusable", *args, **kwargs).to_s == "true"
58
64
  end
59
65
 
60
- def focused?(*args)
61
- testa_attribute("focused", *args).to_s == "true"
66
+ def focused?(*args, **kwargs)
67
+ testa_attribute("focused", *args, **kwargs).to_s == "true"
62
68
  end
63
69
 
64
- def long_clickable?(*args)
65
- testa_attribute("longClickable", *args).to_s == "true"
70
+ def long_clickable?(*args, **kwargs)
71
+ testa_attribute("longClickable", *args, **kwargs).to_s == "true"
66
72
  end
67
73
 
68
- def password?(*args)
69
- testa_attribute("password", *args).to_s == "true"
74
+ def password?(*args, **kwargs)
75
+ testa_attribute("password", *args, **kwargs).to_s == "true"
70
76
  end
71
77
 
72
- def id(*args)
73
- testa_attribute("resourceId", *args)
78
+ def id(*args, **kwargs)
79
+ testa_attribute("resourceId", *args, **kwargs)
74
80
  end
75
81
 
76
- def scrollable?(*args)
77
- testa_attribute("scrollable", *args).to_s == "true"
82
+ def scrollable?(*args, **kwargs)
83
+ testa_attribute("scrollable", *args, **kwargs).to_s == "true"
78
84
  end
79
85
 
80
- def selected?(*args)
81
- testa_attribute("selected", *args).to_s == "true"
86
+ def selected?(*args, **kwargs)
87
+ testa_attribute("selected", *args, **kwargs).to_s == "true"
82
88
  end
83
89
 
84
- def displayed?(*args)
85
- testa_attribute("displayed", *args).to_s == "true"
90
+ def displayed?(*args, **kwargs)
91
+ testa_attribute("displayed", *args, **kwargs).to_s == "true"
86
92
  end
87
93
 
88
- def selection_start(*args)
89
- testa_attribute("selection-start", *args)
94
+ def selection_start(*args, **kwargs)
95
+ testa_attribute("selection-start", *args, **kwargs)
90
96
  end
91
97
 
92
- def selection_end(*args)
93
- testa_attribute("selection-end", *args)
98
+ def selection_end(*args, **kwargs)
99
+ testa_attribute("selection-end", *args, **kwargs)
94
100
  end
95
101
 
96
- def bounds(*args)
97
- testa_attribute("bounds", *args)
102
+ def bounds(*args, **kwargs)
103
+ testa_attribute("bounds", *args, **kwargs)
98
104
  end
99
105
  end
100
106
 
101
107
  class Locator
102
108
 
103
109
  # element index in parent element, starts from 0
104
- #noinspection RubyNilAnalysis,RubyYardReturnMatch
110
+ # noinspection RubyNilAnalysis,RubyYardReturnMatch
105
111
  # @return [Integer, nil] index of element
106
112
  def index(*args)
107
113
  raise "Index not supported for uiautomator strategy" if @strategy == FIND_STRATEGY_UIAUTOMATOR
@@ -9,4 +9,4 @@ module ::Appium
9
9
  end
10
10
  end
11
11
  end
12
- end
12
+ end
@@ -8,7 +8,6 @@ module TestaAppiumDriver
8
8
  attr_reader :height
9
9
  attr_reader :offset
10
10
 
11
-
12
11
  # @param top_left [Coordinates]
13
12
  # @param bottom_right [Coordinates]
14
13
  # @param window_width [Integer]
@@ -19,7 +18,7 @@ module TestaAppiumDriver
19
18
  @width = bottom_right.x - top_left.x
20
19
  @height = bottom_right.y - top_left.y
21
20
  @offset = Offset.new(self, window_width, window_height)
22
- @center = TestaAppiumDriver::Coordinates.new(@top_left.x + @width/2, @top_left.y + @height / 2)
21
+ @center = TestaAppiumDriver::Coordinates.new(@top_left.x + @width / 2, @top_left.y + @height / 2)
23
22
  end
24
23
 
25
24
  def as_json
@@ -28,7 +27,7 @@ module TestaAppiumDriver
28
27
  height: @height,
29
28
  top_left: @top_left.as_json,
30
29
  bottom_right: @bottom_right.as_json,
31
- offset: @offset.as_json
30
+ offset: @offset.as_json,
32
31
  }
33
32
  end
34
33
 
@@ -41,6 +40,7 @@ module TestaAppiumDriver
41
40
  def top_left
42
41
  @top_left
43
42
  end
43
+
44
44
  # @return [TestaAppiumDriver::Coordinates]
45
45
  def bottom_right
46
46
  @bottom_right
@@ -51,8 +51,12 @@ module TestaAppiumDriver
51
51
  @center
52
52
  end
53
53
 
54
+ def ai
55
+ as_json.ai
56
+ end
57
+
54
58
  def to_s
55
- JSON.dump(as_json)
59
+ "[#{@top_left.x}, #{@top_left.y}][#{@bottom_right.x}, #{@bottom_right.y}]"
56
60
  end
57
61
 
58
62
  # @param bounds [String] bounds that driver.attribute("bounds") return
@@ -81,7 +85,7 @@ module TestaAppiumDriver
81
85
  end
82
86
  end
83
87
 
84
- #noinspection ALL
88
+ # noinspection ALL
85
89
  class Coordinates
86
90
  def initialize(x, y)
87
91
  @x = x.to_i
@@ -95,7 +99,6 @@ module TestaAppiumDriver
95
99
  }
96
100
  end
97
101
 
98
-
99
102
  # @return [Integer]
100
103
  def x
101
104
  @x
@@ -107,7 +110,6 @@ module TestaAppiumDriver
107
110
  end
108
111
  end
109
112
 
110
-
111
113
  class Offset
112
114
  def initialize(bounds, window_width, window_height)
113
115
  @top = bounds.top_left.y
@@ -125,7 +127,6 @@ module TestaAppiumDriver
125
127
  }
126
128
  end
127
129
 
128
-
129
130
  # @return [Integer]
130
131
  def top
131
132
  @top
@@ -147,4 +148,4 @@ module TestaAppiumDriver
147
148
  end
148
149
 
149
150
  end
150
- end
151
+ end
@@ -110,7 +110,7 @@ module TestaAppiumDriver
110
110
  # If the distance is greater than the threshold, it will attempt to realign it up to 2 more times.
111
111
  # The retry mechanism allows alignment even for dynamic layouts when elements are hidden/show when scrolling to certain direction
112
112
  # @return [TestaAppiumDriver::Locator]
113
- def align_right(top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3)
113
+ def align_right(top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3)
114
114
  align(:right, top: top, bottom: bottom, right: right, left: left, max_attempts: max_attempts)
115
115
  end
116
116
 
@@ -119,7 +119,7 @@ module TestaAppiumDriver
119
119
  # If the distance is greater than the threshold, it will attempt to realign it up to 2 more times.
120
120
  # The retry mechanism allows alignment even for dynamic layouts when elements are hidden/show when scrolling to certain direction
121
121
  # @return [TestaAppiumDriver::Locator]
122
- def align!(with = :top, top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3)
122
+ def align!(with = :top, top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3)
123
123
  align(with, top: top, bottom: bottom, right: right, left: left, scroll_to_find: true, max_attempts: max_attempts)
124
124
  end
125
125
 
@@ -137,7 +137,7 @@ module TestaAppiumDriver
137
137
  # If the distance is greater than the threshold, it will attempt to realign it up to 2 more times.
138
138
  # The retry mechanism allows alignment even for dynamic layouts when elements are hidden/show when scrolling to certain direction
139
139
  # @return [TestaAppiumDriver::Locator]
140
- def align_bottom!(top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3)
140
+ def align_bottom!(top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3)
141
141
  align(:bottom, top: top, bottom: bottom, right: right, left: left, scroll_to_find: true, max_attempts: max_attempts)
142
142
  end
143
143
 
@@ -146,7 +146,7 @@ module TestaAppiumDriver
146
146
  # If the distance is greater than the threshold, it will attempt to realign it up to 2 more times.
147
147
  # The retry mechanism allows alignment even for dynamic layouts when elements are hidden/show when scrolling to certain direction
148
148
  # @return [TestaAppiumDriver::Locator]
149
- def align_left!(top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3)
149
+ def align_left!(top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3)
150
150
  align(:left, top: top, bottom: bottom, right: right, left: left, scroll_to_find: true, max_attempts: max_attempts)
151
151
  end
152
152
 
@@ -155,7 +155,7 @@ module TestaAppiumDriver
155
155
  # If the distance is greater than the threshold, it will attempt to realign it up to 2 more times.
156
156
  # The retry mechanism allows alignment even for dynamic layouts when elements are hidden/show when scrolling to certain direction
157
157
  # @return [TestaAppiumDriver::Locator]
158
- def align_right!(top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3)
158
+ def align_right!(top: nil, bottom: nil, right: nil, left: nil, max_attempts: 3)
159
159
  align(:right, top: top, bottom: bottom, right: right, left: left, scroll_to_find: true, max_attempts: max_attempts)
160
160
  end
161
161
 
@@ -269,7 +269,12 @@ module TestaAppiumDriver
269
269
  end
270
270
 
271
271
  if to.kind_of?(::Selenium::WebDriver::Element) || to.kind_of?(::Appium::Core::Element)
272
- bounds = TestaAppiumDriver::Bounds.from_android(to.bounds, @driver)
272
+ if @driver.device == :android
273
+ bounds = TestaAppiumDriver::Bounds.from_android(to.bounds, @driver)
274
+ else
275
+ bounds = TestaAppiumDriver::Bounds.from_ios(to.bounds, @driver)
276
+ end
277
+
273
278
  x = bounds.center.x
274
279
  y = bounds.center.y
275
280
  end
@@ -308,6 +313,7 @@ module TestaAppiumDriver
308
313
  end
309
314
 
310
315
  private
316
+
311
317
  def _process_deadzone(top, bottom, right, left)
312
318
  deadzone = nil
313
319
  if !top.nil? || !bottom.nil? || !right.nil? || !left.nil?
@@ -207,25 +207,25 @@ module ::TestaAppiumDriver
207
207
  when :top
208
208
  y0 = @bounds.bottom_right.y - @deadzone[:bottom]
209
209
  y1 = y0 - @align_offset
210
- x0 = @bounds.width / 2
210
+ x0 = @bounds.center.x
211
211
  x1 = x0
212
212
  scroll_direction = :down
213
213
  when :bottom
214
214
  y0 = @bounds.top_left.y + @deadzone[:top]
215
215
  y1 = y0 + @align_offset
216
- x0 = @bounds.width / 2
216
+ x0 = @bounds.center.x
217
217
  x1 = x0
218
218
  scroll_direction = :up
219
219
  when :left
220
220
  x0 = @bounds.bottom_right.x - @deadzone[:right]
221
221
  x1 = x0 - @align_offset
222
- y0 = @bounds.height / 2
222
+ y0 = @bounds.center.y
223
223
  y1 = y0
224
224
  scroll_direction = :right
225
225
  when :right
226
226
  x0 = @bounds.top_left.x + @deadzone[:top]
227
227
  x1 = x0 + @align_offset
228
- y0 = @bounds.height / 2
228
+ y0 = @bounds.center.y
229
229
  y1 = y0
230
230
  scroll_direction = :left
231
231
  else
@@ -2,13 +2,12 @@ module TestaAppiumDriver
2
2
  module Attributes
3
3
 
4
4
  #noinspection RubyNilAnalysis
5
- def testa_attribute(name, *args)
6
-
5
+ def testa_attribute(name, *args, **kwargs)
7
6
  if self.instance_of?(::Selenium::WebDriver::Element) || self.instance_of?(::Appium::Core::Element)
8
7
  @driver = get_driver
9
8
  elements = self
10
9
  else
11
- elements = execute(*args)
10
+ elements = execute(*args, **kwargs)
12
11
  end
13
12
 
14
13
 
@@ -23,62 +22,62 @@ module TestaAppiumDriver
23
22
  end
24
23
 
25
24
 
26
- def accessibility_container(*args)
27
- testa_attribute("accessibilityContainer", *args)
25
+ def accessibility_container(*args, **kwargs)
26
+ testa_attribute("accessibilityContainer", *args, **kwargs)
28
27
  end
29
28
 
30
- def accessible?(*args)
31
- testa_attribute("accessible", *args).to_s == "true"
29
+ def accessible?(*args, **kwargs)
30
+ testa_attribute("accessible", *args, **kwargs).to_s == "true"
32
31
  end
33
32
 
34
33
 
35
- def class_name(*args)
36
- testa_attribute("class", *args)
34
+ def class_name(*args, **kwargs)
35
+ testa_attribute("class", *args, **kwargs)
37
36
  end
38
37
 
39
- def enabled?(*args)
40
- testa_attribute("enabled", *args).to_s == "true"
38
+ def enabled?(*args, **kwargs)
39
+ testa_attribute("enabled", *args, **kwargs).to_s == "true"
41
40
  end
42
41
 
43
- def frame(*args)
44
- testa_attribute("frame", *args)
42
+ def frame(*args, **kwargs)
43
+ testa_attribute("frame", *args, **kwargs)
45
44
  end
46
45
 
47
- def index(*args)
48
- index = testa_attribute("index", *args)
46
+ def index(*args, **kwargs)
47
+ index = testa_attribute("index", *args, **kwargs)
49
48
  index = "1" if index == "true"
50
49
  index = "0" if index == "false"
51
50
 
52
51
  index
53
52
  end
54
53
 
55
- def label(*args)
56
- testa_attribute("label", *args)
54
+ def label(*args, **kwargs)
55
+ testa_attribute("label", *args, **kwargs)
57
56
  end
58
57
 
59
- def name(*args)
60
- testa_attribute("name", *args)
58
+ def name(*args, **kwargs)
59
+ testa_attribute("name", *args, **kwargs)
61
60
  end
62
61
 
63
62
 
64
- def rect(*args)
65
- testa_attribute("rect", *args)
63
+ def rect(*args, **kwargs)
64
+ testa_attribute("rect", *args, **kwargs)
66
65
  end
67
66
 
68
- def selected?(*args)
69
- testa_attribute("selected", *args).to_s == "true"
67
+ def selected?(*args, **kwargs)
68
+ testa_attribute("selected", *args, **kwargs).to_s == "true"
70
69
  end
71
70
 
72
- def type(*args)
73
- testa_attribute("type", *args)
71
+ def type(*args, **kwargs)
72
+ testa_attribute("type", *args, **kwargs)
74
73
  end
75
74
 
76
- def value(*args)
77
- testa_attribute("value", *args)
75
+ def value(*args, **kwargs)
76
+ testa_attribute("value", *args, **kwargs)
78
77
  end
79
78
 
80
- def visible?(*args)
81
- testa_attribute("visible", *args).to_s == "true"
79
+ def visible?(*args, **kwargs)
80
+ testa_attribute("visible", *args, **kwargs).to_s == "true"
82
81
  end
83
82
 
84
83
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testa_appium_driver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.32
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - karlo.razumovic
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-16 00:00:00.000000000 Z
11
+ date: 2025-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appium_lib_core
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: awesome_print
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: json
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -90,7 +104,7 @@ metadata:
90
104
  homepage_uri: https://github.com/Karazum/testa_appium_driver
91
105
  source_code_uri: https://github.com/Karazum/testa_appium_driver
92
106
  changelog_uri: https://github.com/Karazum/testa_appium_driver
93
- post_install_message:
107
+ post_install_message:
94
108
  rdoc_options: []
95
109
  require_paths:
96
110
  - lib
@@ -98,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
112
  requirements:
99
113
  - - ">="
100
114
  - !ruby/object:Gem::Version
101
- version: 2.7.6
115
+ version: 3.2.6
102
116
  required_rubygems_version: !ruby/object:Gem::Requirement
103
117
  requirements:
104
118
  - - ">="
@@ -106,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
120
  version: '0'
107
121
  requirements: []
108
122
  rubygems_version: 3.1.6
109
- signing_key:
123
+ signing_key:
110
124
  specification_version: 4
111
125
  summary: Appium made easy
112
126
  test_files: []