wda_lib 0.2.3 → 0.3.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
  SHA1:
3
- metadata.gz: d54d671bdf87c1cfdea873faea31960872aac5ab
4
- data.tar.gz: af4dcf4df69c48f11beeaad35d0656d76a15cb7a
3
+ metadata.gz: 7517995dcdb3b10660a1f72b2f928aca7ba1ef0f
4
+ data.tar.gz: 18612a392b4c51a524f4df05163e2fce9f9cd65e
5
5
  SHA512:
6
- metadata.gz: 9ffa84e999ff834ffebcc5e9c8f1a97060571cb974ed543d979f1c05f00a4de78458743da50e609ae8589f8495597276acf650d2f3d920f4380600686a5b0fe6
7
- data.tar.gz: 1d8d6a97389a0c27907aa2f4d736996752db6a71c7a55bc1a1879bc33df83ff3197c1df3fd183b67708613370ccd4fa75216f651a9265e9f14e784eeb8571aa1
6
+ metadata.gz: 27167966a5303de42ad65f67b4267a39ecb02298eb98353142a70f025befaa51794019e73228549a54f4fcab754252edc430b2df9b4ca7e3d1181700ba7c63f2
7
+ data.tar.gz: 40125773e8a05e39eae7e61a42cad5eb5f7842565f1b8e6a5a9d8fb944f8e4ab2e6d86fb0d5521443a06c8af8434c5b4c3159c381bf79da30c3aaa7fd3f7c0ef
@@ -7,7 +7,7 @@ class WDA
7
7
 
8
8
  # Go to home screen
9
9
  def homescreen
10
- post(@base_url + '/homescreen')
10
+ post(@base_url + '/wda/homescreen')
11
11
  end
12
12
 
13
13
  # Same as homescreen, go to home screen
@@ -17,21 +17,19 @@ class WDA
17
17
 
18
18
  # Deactivate application for given time
19
19
  def pause(duration)
20
- post '/deactivateApp', { duration: duration }
20
+ post '/wda/deactivateApp', { duration: duration }
21
21
  end
22
22
 
23
- # Timeout(without Session)
23
+ # Timeouts
24
24
  # @param duration [Float] the timeout in milliseconds
25
25
  # @return [void]
26
- def timeout(duration)
27
- post(@base_url + '/timeout', { type: 'xctevent', ms: duration })
26
+ def timeouts(duration)
27
+ post '/timeouts', { type: 'xctevent', ms: duration }
28
28
  end
29
29
 
30
- # Timeout(with Session)
31
- # @param duration [Float] the timeout in milliseconds
32
- # @return [void]
33
- def timeout_in_session(duration)
34
- post '/timeout', { type: 'xctevent', ms: duration }
30
+ # Dismiss keyboard
31
+ def dismiss_keyboard
32
+ post '/wda/keyboard/dismiss'
35
33
  end
36
34
 
37
35
  def double_tap_homebutton
data/lib/wda_lib/debug.rb CHANGED
@@ -10,14 +10,20 @@ class WDA
10
10
  # When accessible is true, ignore all elements except for the main window for accessibility tree
11
11
  # When accessible is false, and visible is true, ignore all invisible elements
12
12
  # @return [Hash]
13
- def source(session_id = nil, not_fetch_inaccessible = true, not_fetch_invisible = true, timeout = 60)
13
+ def source(opts = {})
14
+ response_type = opts.fetch(:response_type, 'xml')
15
+ response_type = 'json' if opts.empty?
16
+ session_id = opts.fetch(:session_id, nil)
17
+ # not_fetch_inaccessible = opts.fetch(:not_fetch_inaccessible, true)
18
+ # not_fetch_invisible = opts.fetch(:not_fetch_invisible, true)
19
+ timeout = opts.fetch(:timeout, 60)
14
20
  @timeout = timeout.to_i if !timeout.nil?
21
+ url = '/source' + '?format=' + response_type
22
+ url = @base_url + '/source' + '?format=' + response_type if session_id.nil?
15
23
  begin
16
- if session_id.nil?
17
- res = post(@base_url + '/source', { accessible: not_fetch_inaccessible, visible: not_fetch_invisible }, @timeout)
18
- else
19
- res = post('/source', { accessible: not_fetch_inaccessible, visible: not_fetch_invisible }, @timeout)
20
- end
24
+ res = get(url,
25
+ # { accessible: not_fetch_inaccessible, visible: not_fetch_invisible },
26
+ @timeout)
21
27
  rescue
22
28
  raise Error::NoSuchElementError, "Can't fetch current screen elements within #{@timeout}s" if res['status'].nil?
23
29
  end
@@ -25,18 +31,31 @@ class WDA
25
31
  res
26
32
  end
27
33
 
28
-
34
+ # Get accessibility tree
35
+ def accessibility_tree(opts = {})
36
+ session_id = opts.fetch(:session_id, nil)
37
+ timeout = opts.fetch(:timeout, 60)
38
+ @timeout = timeout.to_i if !timeout.nil?
39
+ url = '/wda/accessibleSource'
40
+ url = @base_url + '/wda/accessibleSource' if session_id.nil?
41
+ begin
42
+ res = get(url, @timeout)
43
+ rescue
44
+ raise Error::NoSuchElementError, "Can't fetch current screen accessibility tree within #{@timeout}s" if res['status'].nil?
45
+ end
46
+ end
29
47
 
30
48
  def get_source
31
- get(@base_url + '/source')['value']['tree']['children']
49
+ response = source
50
+ response['value']['children']
32
51
  end
33
52
 
34
- def get_window_statusbar
35
- get(@base_url + '/source')['value']['tree']['children'][2]
36
- end
53
+ # def get_window_statusbar
54
+ # source['value']['children'][-3]
55
+ # end
37
56
 
38
57
  def get_window(window_number = 0)
39
- get(@base_url + '/source')['value']['tree']['children'][window_number]
58
+ source['value']['children'][window_number]
40
59
  end
41
60
 
42
61
  # Had issue when there is app shortcut in SIRI search or Today's extention,
@@ -57,13 +57,13 @@ class WDA
57
57
  # Check if element is accessible?
58
58
  # @return is accessible? [Boolean]
59
59
  def accessible?
60
- client.get('/element/' + eid + '/accessible')['value']
60
+ client.get('/wda/element/' + eid + '/accessible')['value']
61
61
  end
62
62
 
63
63
  # Check if element is accessibilityContainer?
64
64
  # @return is accessibilityContainer? [Boolean]
65
65
  def accessible_container?
66
- client.get('/element/' + eid + '/accessibilityContainer')['value']
66
+ client.get('/wda/element/' + eid + '/accessibilityContainer')['value']
67
67
  end
68
68
 
69
69
  # Get type from an element, ex: type => "Icon"(XCUIElementTypeIcon)
@@ -91,38 +91,56 @@ class WDA
91
91
  client.post '/element/' + eid + '/clear'
92
92
  end
93
93
 
94
+ # Element swipe
95
+ # @param direction [String] up, down, left, right
96
+ # @return element uuid [String]
97
+ def elswipe(direction)
98
+ client.post('/wda/element/' + eid + '/swipe', { direction: direction })
99
+ end
100
+
101
+ # Element pinch
102
+ # @param scale [Double], velocity [Double]
103
+ # @return element uuid [String]
104
+ def elswipe(scale, velocity)
105
+ client.post('/wda/element/' + eid + '/pinch', { scale: scale, velocity: velocity })
106
+ end
107
+
94
108
  # Double tap on an element with its id
95
109
  # @return element uuid [String]
96
110
  def double_tap
97
- client.post '/uiaElement/' + eid + '/doubleTap'
111
+ client.post '/wda/element/' + eid + '/doubleTap'
98
112
  end
99
113
 
100
114
  # Two finger tap on an element with its id
101
115
  # @return element uuid [String]
102
116
  def two_finger_tap
103
- client.post '/uiaElement/' + eid + '/twoFingerTap'
117
+ client.post '/wda/element/' + eid + '/twoFingerTap'
104
118
  end
105
119
 
106
120
  # Touch and hold on for a while finger tap on an element with its id
107
121
  # @param duration [Double]
108
122
  # @return element uuid [String]
109
123
  def touch_hold(duration)
110
- client.post '/uiaElement/' + eid + '/touchAndHold', { duration: duration }
124
+ client.post '/wda/element/' + eid + '/touchAndHold', { duration: duration }
111
125
  end
112
126
 
113
127
  # Scroll on an element with its id
114
128
  # @param direction [String] up, down, left, right
115
129
  # @return [Hash]
116
130
  def scroll(direction = nil)
117
- client.post '/uiaElement/' + eid + '/scroll', { direction: direction }
131
+ client.post '/wda/element/' + eid + '/scroll', { direction: direction }
118
132
  end
119
133
 
120
134
  # Drag on an element with its id and position
121
- # @param toX [String], toY [String], duration [Double]
122
- def drag_to(toX, toY, duration = 0)
123
- fromX = location[:x]
124
- fromY = location[:y]
125
- client.post '/uiaTarget/' + eid + '/dragfromtoforduration', { fromX: fromX, toX: toX, fromY: fromY, toY: toY, duration: duration }
135
+ # @param fromX [Double], toX [Double], fromY [Double], toY [Double], duration [Double]
136
+ def drag_element_from_to(fromX, toX, fromY, toY, duration = 0)
137
+ client.post '/wda/element/' + eid + '/dragfromtoforduration', { fromX: fromX, toX: toX, fromY: fromY, toY: toY, duration: duration }
138
+ end
139
+
140
+ # Drag from a position to another position
141
+ # @param fromX [Double], toX [Double], fromY [Double], toY [Double], duration [Double]
142
+ def drag_from_to(fromX, toX, fromY, toY, duration = 0)
143
+ client.post '/wda/dragfromtoforduration', { fromX: fromX, toX: toX, fromY: fromY, toY: toY, duration: duration }
126
144
  end
127
145
 
128
146
  # Get element size
@@ -156,13 +174,26 @@ class WDA
156
174
  # Tap on a given positon
157
175
  # @param x [Integer], y [Integer]
158
176
  def tap_on(x, y)
159
- post '/tap/0', { x: x, y: y }
177
+ post '/wda/tap/0', { x: x, y: y }
178
+ end
179
+
180
+ # Double tap on a given positon
181
+ # @param x [Integer], y [Integer]
182
+ def double_tap(x, y)
183
+ post '/wda/doubleTap', { x: x, y: y }
184
+ end
185
+
186
+ # Touch and hold on for a while
187
+ # @param x [Double], y [Double], duration [Double]
188
+ # @return element uuid [String]
189
+ def touch_hold(x, y, duration)
190
+ client.post '/wda/touchAndHold', { x: x, y: y, duration: duration }
160
191
  end
161
192
 
162
193
  # Type text to textfield
163
194
  # @param value [String]
164
195
  def keys(value)
165
- post '/keys', { value: value.chars }
196
+ post '/wda/keys', { value: value.chars }
166
197
  end
167
198
 
168
199
  # @return width, height
@@ -199,7 +199,7 @@ class WDA
199
199
 
200
200
  # @return element's visible cells [Array]
201
201
  def visible_cell(id)
202
- get '/uiaElement/' + id + '/getVisibleCells'
202
+ get '/wda/element/' + id + '/getVisibleCells'
203
203
  end
204
204
 
205
205
  # Find button by given index or value
@@ -5,19 +5,19 @@
5
5
  class WDA
6
6
  module Orientation
7
7
  def orientation
8
- get @base_url + '/orientation'
8
+ get '/orientation'
9
9
  end
10
10
 
11
11
  def set_orientation
12
- post @base_url + '/orientation'
12
+ post '/orientation'
13
13
  end
14
14
 
15
15
  def get_rotation
16
- get @base_url + '/rotation'
16
+ get '/rotation'
17
17
  end
18
18
 
19
19
  def set_rotation
20
- post @base_url + '/rotation'
20
+ post '/rotation'
21
21
  end
22
22
  end
23
23
  end
@@ -48,6 +48,13 @@ class WDA
48
48
  response
49
49
  end
50
50
 
51
+ # Post url to wda server to open a url in browser and create a session
52
+ # @return [self]
53
+ def open_url(url)
54
+ post('/url', { url: url })
55
+ status
56
+ end
57
+
51
58
  # Post desired_capabilities to wda server to create a session
52
59
  # This is not realy needed since we can find and click app icon to start app
53
60
  # @return [self]
@@ -84,7 +91,6 @@ class WDA
84
91
  # @return delete session response [Json]
85
92
  def quit(session_id = nil)
86
93
  (session_id.nil?)? sessionId = @session_id : sessionId = session_id
87
- @base_url + '/session/' + sessionId
88
94
  delete(@base_url + '/session/' + sessionId)
89
95
  status
90
96
  end
@@ -95,8 +101,9 @@ class WDA
95
101
  end
96
102
 
97
103
  # Healthcheck
104
+ # This api does also get back to homescreen
98
105
  def healthcheck
99
- response = get(@base_url + '/healthcheck')
106
+ response = get(@base_url + '/wda/healthcheck')
100
107
  update_status(response)
101
108
  end
102
109
  end
@@ -8,12 +8,12 @@ class WDA
8
8
  # Touch ID
9
9
  # Match TouchID
10
10
  def match_touchid
11
- post(@base_url + '/simulator/touch_id', { match: 1 }.to_json)
11
+ post(@base_url + '/wda/touch_id', { match: 1 }.to_json)
12
12
  end
13
13
 
14
14
  # Do not match TouchID
15
15
  def unmatch_touchid
16
- post(@base_url + '/Simulator/touch_id', { match: 0 }.to_json)
16
+ post(@base_url + '/wda/touch_id', { match: 0 }.to_json)
17
17
  end
18
18
  end
19
19
  end
@@ -3,5 +3,5 @@
3
3
  # Copyright © 2016 Zenly. All rights reserved.
4
4
  #
5
5
  class WDA
6
- VERSION = '0.2.3'
6
+ VERSION = '0.3.0'
7
7
  end
data/lib/wda_lib.rb CHANGED
@@ -67,12 +67,6 @@ class WDA
67
67
  status
68
68
  window_size
69
69
  capabilities(opts)
70
- @http_client ||= Selenium::WebDriver::Remote::Http::Default.new(open_timeout: 999_999, read_timeout: 999_999)
71
- @driver = Selenium::WebDriver.for(:remote,
72
- http_client: @http_client,
73
- :url => @base_url,
74
- :desired_capabilities => @caps[:desired_capabilities],
75
- :listener => @listener)
76
70
  end
77
71
 
78
72
  # Build desired_capabilities with options
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wda_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - MIN Yi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-27 00:00:00.000000000 Z
11
+ date: 2017-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  version: '0'
132
132
  requirements: []
133
133
  rubyforge_project:
134
- rubygems_version: 2.5.1
134
+ rubygems_version: 2.6.1
135
135
  signing_key:
136
136
  specification_version: 4
137
137
  summary: A simple ruby lib of binding methods for WebDriverAgent