wda_lib 0.0.15 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wda_lib/element.rb +1 -1
- data/lib/wda_lib/error.rb +7 -0
- data/lib/wda_lib/find_element.rb +53 -10
- data/lib/wda_lib/version.rb +1 -1
- data/lib/wda_lib/wait.rb +75 -0
- data/lib/wda_lib.rb +4 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0fefbb0acdf03d03f94d931270dba23ca8d5220
|
4
|
+
data.tar.gz: 297c4a2d95fcd048f2bf55c0e42cd4e3cc1f926c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba2fd6a51b7f68708efd90a1b052f8bf9b2650a425fb3e1e9c8a7cb300ee5fe97f0924085d09df2f4a6b9de5f7ad00120076a66adee364c145424d02153f15e3
|
7
|
+
data.tar.gz: deebfd7fe5067363cd3298e0d1bdfc654d91599beef073ddfad5ea70d24733492f895f0a44d81c8ff3a4ac705c29fa121a2d7557e8829fc791e1a2025d2887e5
|
data/lib/wda_lib/element.rb
CHANGED
data/lib/wda_lib/find_element.rb
CHANGED
@@ -6,33 +6,72 @@ class WDA
|
|
6
6
|
# @param type [String, Symbol], value [Stirng]
|
7
7
|
# @return [Hash]
|
8
8
|
def find(type, value)
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
wait = Wait.new(:timeout => @timeout) # seconds
|
10
|
+
|
11
|
+
begin
|
12
|
+
wait.until {
|
13
|
+
@element = post('/element', { using: stringlize(type), value: value })
|
14
|
+
@element['status'] == 0
|
15
|
+
}
|
16
|
+
ensure
|
17
|
+
raise Error::NoSuchElementError, "Can't find '#{value}' with type '#{type}'" if @element['status'] != 0
|
18
|
+
end
|
19
|
+
|
20
|
+
Element.new self, @element['value']
|
12
21
|
end
|
13
22
|
|
14
23
|
# Find all elements with given type and value, return in an Array
|
15
24
|
# @param type [String, Symbol], value [Stirng]
|
16
25
|
# @return [Array]
|
17
26
|
def finds(type, value)
|
18
|
-
|
19
|
-
|
27
|
+
wait = Wait.new(:timeout => @timeout) # seconds
|
28
|
+
|
29
|
+
begin
|
30
|
+
wait.until {
|
31
|
+
@elements = post('/elements', { using: stringlize(type), value: value })['value']
|
32
|
+
@elements.length != 0
|
33
|
+
}
|
34
|
+
ensure
|
35
|
+
raise Error::NoSuchElementError, "Can't find '#{value}' with type '#{type}'" if @elements.length == 0
|
36
|
+
end
|
37
|
+
|
38
|
+
@elements.map { |element| Element.new self, element }
|
20
39
|
end
|
21
40
|
|
22
41
|
# Find child element by given type and value, return first found element
|
23
42
|
# @param id [String] parent element id, type [String, Symbol], value [Stirng]
|
24
43
|
# @return [Object] found element
|
25
44
|
def find_subl_element(id, type, value)
|
26
|
-
|
27
|
-
|
45
|
+
wait = Wait.new(:timeout => @timeout) # seconds
|
46
|
+
begin
|
47
|
+
wait.until {
|
48
|
+
@element = post('/element/' + id + '/element', { using: stringlize(type), value: value })
|
49
|
+
@element['status'] == 0
|
50
|
+
}
|
51
|
+
ensure
|
52
|
+
raise Error::NoSuchElementError, "Can't find '#{value}' with type '#{type}'" if @element['status'] != 0
|
53
|
+
end
|
54
|
+
|
55
|
+
Element.new self, @element['value']
|
28
56
|
end
|
29
57
|
|
30
58
|
# Find children elements by given type and value, return elements array
|
31
59
|
# @param id [String] parent element id, type [String, Symbol], value [Stirng]
|
32
60
|
# @return [Array<Element>]
|
33
61
|
def find_subl_elements(id, type, value)
|
34
|
-
|
35
|
-
|
62
|
+
wait = Wait.new(:timeout => @timeout) # seconds
|
63
|
+
|
64
|
+
begin
|
65
|
+
wait.until {
|
66
|
+
@result = post('/element/' + id + '/elements', { using: stringlize(type), value: value })
|
67
|
+
@elements = @result['value']
|
68
|
+
@result['status'] != 7
|
69
|
+
}
|
70
|
+
ensure
|
71
|
+
raise Error::NoSuchElementError, "Can't find '#{value}' with type '#{type}'" if @result['status'] != 0
|
72
|
+
end
|
73
|
+
|
74
|
+
@elements.map { |element| Element.new self, element }
|
36
75
|
end
|
37
76
|
|
38
77
|
# Search with given name
|
@@ -355,10 +394,14 @@ class WDA
|
|
355
394
|
if instring.is_a? Symbol
|
356
395
|
instring.to_s.gsub('_', ' ')
|
357
396
|
elsif instring.is_a? String
|
358
|
-
return instring
|
397
|
+
return instring.gsub('_', ' ')
|
359
398
|
else
|
360
399
|
fail 'Xpath searching type should be a String'
|
361
400
|
end
|
401
|
+
end
|
402
|
+
|
403
|
+
def set_timeout(second)
|
404
|
+
@timeout = second
|
362
405
|
end
|
363
406
|
end
|
364
407
|
end
|
data/lib/wda_lib/version.rb
CHANGED
data/lib/wda_lib/wait.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Licensed to the Software Freedom Conservancy (SFC) under one
|
4
|
+
# or more contributor license agreements. See the NOTICE file
|
5
|
+
# distributed with this work for additional information
|
6
|
+
# regarding copyright ownership. The SFC licenses this file
|
7
|
+
# to you under the Apache License, Version 2.0 (the
|
8
|
+
# "License"); you may not use this file except in compliance
|
9
|
+
# with the License. You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing,
|
14
|
+
# software distributed under the License is distributed on an
|
15
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
16
|
+
# KIND, either express or implied. See the License for the
|
17
|
+
# specific language governing permissions and limitations
|
18
|
+
# under the License.
|
19
|
+
|
20
|
+
class WDA
|
21
|
+
class Wait
|
22
|
+
DEFAULT_TIMEOUT = 10
|
23
|
+
DEFAULT_INTERVAL = 2
|
24
|
+
|
25
|
+
#
|
26
|
+
# Create a new Wait instance
|
27
|
+
#
|
28
|
+
# @param [Hash] opts Options for this instance
|
29
|
+
# @option opts [Numeric] :timeout (10) Seconds to wait before timing out.
|
30
|
+
# @option opts [Numeric] :interval (2) Seconds to sleep between polls.
|
31
|
+
# @option opts [String] :message Exception mesage if timed out.
|
32
|
+
# @option opts [Array, Exception] :ignore Exceptions to ignore while polling (default: Error::NoSuchElementError)
|
33
|
+
#
|
34
|
+
|
35
|
+
def initialize(opts = {})
|
36
|
+
@timeout = opts.fetch(:timeout, DEFAULT_TIMEOUT)
|
37
|
+
@interval = opts.fetch(:interval, DEFAULT_INTERVAL)
|
38
|
+
@message = opts[:message]
|
39
|
+
@ignored = Array(opts[:ignore] || Error::NoSuchElementError)
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Wait until the given block returns a true value.
|
44
|
+
#
|
45
|
+
# @raise [Error::TimeOutError]
|
46
|
+
# @return [Object] the result of the block
|
47
|
+
#
|
48
|
+
|
49
|
+
def until
|
50
|
+
end_time = Time.now + @timeout
|
51
|
+
last_error = nil
|
52
|
+
|
53
|
+
until Time.now > end_time
|
54
|
+
begin
|
55
|
+
result = yield
|
56
|
+
return result if result
|
57
|
+
rescue *@ignored => last_error
|
58
|
+
# swallowed
|
59
|
+
end
|
60
|
+
|
61
|
+
sleep @interval
|
62
|
+
end
|
63
|
+
|
64
|
+
msg = if @message
|
65
|
+
@message.dup
|
66
|
+
else
|
67
|
+
"timed out after #{@timeout} seconds"
|
68
|
+
end
|
69
|
+
|
70
|
+
msg << " (#{last_error.message})" if last_error
|
71
|
+
|
72
|
+
raise Error::TimeoutError, msg
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/wda_lib.rb
CHANGED
@@ -21,11 +21,13 @@ class WDA
|
|
21
21
|
include ::WDA::Session
|
22
22
|
include ::WDA::TouchID
|
23
23
|
include ::WDA::Type
|
24
|
+
include ::WDA::Error
|
25
|
+
|
24
26
|
|
25
27
|
Point = Struct.new(:x, :y)
|
26
28
|
Dimension = Struct.new(:width, :height)
|
27
29
|
|
28
|
-
attr_accessor :session_id, :http, :bundle_id, :caps, :device, :driver
|
30
|
+
attr_accessor :session_id, :http, :bundle_id, :caps, :device, :driver, :timeout
|
29
31
|
attr_reader :base_url, :server_host, :server_port, :url, :window_w, :window_h, :win_x, :win_y
|
30
32
|
|
31
33
|
# Get base_url from XCTRunner logs: ServerURLHere->http://x.x.x.x:8100<-ServerURLHere
|
@@ -50,6 +52,7 @@ class WDA
|
|
50
52
|
@url = @base_url
|
51
53
|
@server_host = parsed_url.host
|
52
54
|
@server_port = parsed_url.port
|
55
|
+
@timeout = 10
|
53
56
|
status
|
54
57
|
window_size
|
55
58
|
capabilities(opts)
|
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.0.
|
4
|
+
version: 0.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MIN Yi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- lib/wda_lib/custom.rb
|
101
101
|
- lib/wda_lib/debug.rb
|
102
102
|
- lib/wda_lib/element.rb
|
103
|
+
- lib/wda_lib/error.rb
|
103
104
|
- lib/wda_lib/find_element.rb
|
104
105
|
- lib/wda_lib/orientation.rb
|
105
106
|
- lib/wda_lib/screenshot.rb
|
@@ -107,6 +108,7 @@ files:
|
|
107
108
|
- lib/wda_lib/touch_id.rb
|
108
109
|
- lib/wda_lib/type.rb
|
109
110
|
- lib/wda_lib/version.rb
|
111
|
+
- lib/wda_lib/wait.rb
|
110
112
|
- wda_lib.gemspec
|
111
113
|
homepage: https://github.com/znly/wda
|
112
114
|
licenses:
|