appium_lib_core 1.7.1 → 1.7.2
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 +4 -4
- data/CHANGELOG.md +10 -0
- data/lib/appium_lib_core/common/base/bridge/mjsonwp.rb +68 -0
- data/lib/appium_lib_core/common/base/bridge/w3c.rb +70 -0
- data/lib/appium_lib_core/common/base/driver.rb +74 -1
- data/lib/appium_lib_core/common/base/screenshot.rb +83 -0
- data/lib/appium_lib_core/common/error.rb +2 -0
- data/lib/appium_lib_core/device.rb +6 -23
- data/lib/appium_lib_core/device/image_comparison.rb +4 -2
- data/lib/appium_lib_core/element/image.rb +106 -0
- data/lib/appium_lib_core/version.rb +2 -2
- data/release_notes.md +8 -0
- 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: e4396bf8502f02909fc45492b5f205554cd367f2
|
4
|
+
data.tar.gz: ece56ca4022cef888da977917121a403df721b47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 261082f3a1f085f18d549ad837d0b93dac630886ddcd24e4c40420744efac7f9ef0490ab94c32d171ba58816cb2607bd476988513a558435723eb7448ed212cc
|
7
|
+
data.tar.gz: f46ec6897d884275faa9260ef48c550c479e5173986e9464035e03d7af50e29ea576b97d2e33560e55ef0422c27990e5cb8b61dfe9d5761674ce3fd99cfbba51
|
data/CHANGELOG.md
CHANGED
@@ -8,6 +8,16 @@ All notable changes to this project will be documented in this file.
|
|
8
8
|
|
9
9
|
### Deprecations
|
10
10
|
|
11
|
+
## [1.7.2] - 2018-06-23
|
12
|
+
### Enhancements
|
13
|
+
- Add a `ImageElement` to handle images as elements by `matchTemplate`
|
14
|
+
- Experimental feature
|
15
|
+
- [Internal] Define screenshot methods in appium_lib_core instead of Selenium's one
|
16
|
+
|
17
|
+
### Bug fixes
|
18
|
+
|
19
|
+
### Deprecations
|
20
|
+
|
11
21
|
## [1.7.1] - 2018-06-15
|
12
22
|
### Enhancements
|
13
23
|
- Add a `format` argument for `device_time` [#94](https://github.com/appium/ruby_lib_core/pull/94)
|
@@ -6,6 +6,74 @@ module Appium
|
|
6
6
|
def commands(command)
|
7
7
|
::Appium::Core::Commands::MJSONWP::COMMANDS[command]
|
8
8
|
end
|
9
|
+
|
10
|
+
#
|
11
|
+
# @return [::Appium::Core::ImageElement|nil]
|
12
|
+
# @raise [::Selenium::WebDriver::Error::TimeOutError|::Selenium::WebDriver::Error::WebDriverError]
|
13
|
+
#
|
14
|
+
def find_element_by_image(full_image:, partial_image:, match_threshold: nil, visualize: false)
|
15
|
+
options = {}
|
16
|
+
options[:threshold] = match_threshold unless match_threshold.nil?
|
17
|
+
options[:visualize] = visualize
|
18
|
+
|
19
|
+
params = {}
|
20
|
+
params[:mode] = :matchTemplate
|
21
|
+
params[:firstImage] = full_image
|
22
|
+
params[:secondImage] = partial_image
|
23
|
+
params[:options] = options if options
|
24
|
+
|
25
|
+
result = execute(:compare_images, {}, params)
|
26
|
+
rect = result['rect']
|
27
|
+
|
28
|
+
if rect
|
29
|
+
return ::Appium::Core::ImageElement.new(self,
|
30
|
+
rect['x'],
|
31
|
+
rect['y'],
|
32
|
+
rect['width'],
|
33
|
+
rect['height'],
|
34
|
+
result['visualization'])
|
35
|
+
end
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
|
39
|
+
#
|
40
|
+
# @return [[]|[::Appium::Core::ImageElement]]
|
41
|
+
# @raise [::Selenium::WebDriver::Error::TimeOutError|::Selenium::WebDriver::Error::WebDriverError]
|
42
|
+
#
|
43
|
+
def find_elements_by_image(full_image:, partial_images:, match_threshold: nil, visualize: false)
|
44
|
+
options = {}
|
45
|
+
options[:threshold] = match_threshold unless match_threshold.nil?
|
46
|
+
options[:visualize] = visualize
|
47
|
+
|
48
|
+
params = {}
|
49
|
+
params[:mode] = :matchTemplate
|
50
|
+
params[:firstImage] = full_image
|
51
|
+
params[:options] = options if options
|
52
|
+
|
53
|
+
partial_images.each_with_object([]) do |partial_image, acc|
|
54
|
+
params[:secondImage] = partial_image
|
55
|
+
|
56
|
+
begin
|
57
|
+
result = execute(:compare_images, {}, params)
|
58
|
+
rect = result['rect']
|
59
|
+
|
60
|
+
if result['rect']
|
61
|
+
acc.push ::Appium::Core::ImageElement.new(self,
|
62
|
+
rect['x'],
|
63
|
+
rect['y'],
|
64
|
+
rect['width'],
|
65
|
+
rect['height'],
|
66
|
+
result['visualization'])
|
67
|
+
end
|
68
|
+
rescue ::Selenium::WebDriver::Error::WebDriverError => e
|
69
|
+
acc if e.message.include?('Cannot find any occurrences')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def take_element_screenshot(element)
|
75
|
+
execute :take_element_screenshot, id: element.ref
|
76
|
+
end
|
9
77
|
end # class MJSONWP
|
10
78
|
end # class Bridge
|
11
79
|
end # class Base
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
1
3
|
module Appium
|
2
4
|
module Core
|
3
5
|
class Base
|
@@ -84,6 +86,70 @@ module Appium
|
|
84
86
|
ids.map { |id| ::Selenium::WebDriver::Element.new self, element_id_from(id) }
|
85
87
|
end
|
86
88
|
|
89
|
+
#
|
90
|
+
# @return [::Appium::Core::ImageElement|nil]
|
91
|
+
# @raise [::Selenium::WebDriver::Error::TimeOutError|::Selenium::WebDriver::Error::WebDriverError]
|
92
|
+
#
|
93
|
+
def find_element_by_image(full_image:, partial_image:, match_threshold: nil, visualize: false)
|
94
|
+
options = {}
|
95
|
+
options[:threshold] = match_threshold unless match_threshold.nil?
|
96
|
+
options[:visualize] = visualize
|
97
|
+
|
98
|
+
params = {}
|
99
|
+
params[:mode] = :matchTemplate
|
100
|
+
params[:firstImage] = full_image
|
101
|
+
params[:secondImage] = partial_image
|
102
|
+
params[:options] = options if options
|
103
|
+
|
104
|
+
result = execute(:compare_images, {}, params)
|
105
|
+
rect = result['rect']
|
106
|
+
|
107
|
+
if rect
|
108
|
+
return ::Appium::Core::ImageElement.new(self,
|
109
|
+
rect['x'],
|
110
|
+
rect['y'],
|
111
|
+
rect['width'],
|
112
|
+
rect['height'],
|
113
|
+
result['visualization'])
|
114
|
+
end
|
115
|
+
nil
|
116
|
+
end
|
117
|
+
|
118
|
+
#
|
119
|
+
# @return [[]|[::Appium::Core::ImageElement]]
|
120
|
+
# @raise [::Selenium::WebDriver::Error::TimeOutError|::Selenium::WebDriver::Error::WebDriverError]
|
121
|
+
#
|
122
|
+
def find_elements_by_image(full_image:, partial_images:, match_threshold: nil, visualize: false)
|
123
|
+
options = {}
|
124
|
+
options[:threshold] = match_threshold unless match_threshold.nil?
|
125
|
+
options[:visualize] = visualize
|
126
|
+
|
127
|
+
params = {}
|
128
|
+
params[:mode] = :matchTemplate
|
129
|
+
params[:firstImage] = full_image
|
130
|
+
params[:options] = options if options
|
131
|
+
|
132
|
+
partial_images.each_with_object([]) do |partial_image, acc|
|
133
|
+
params[:secondImage] = partial_image
|
134
|
+
|
135
|
+
begin
|
136
|
+
result = execute(:compare_images, {}, params)
|
137
|
+
rect = result['rect']
|
138
|
+
|
139
|
+
if result['rect']
|
140
|
+
acc.push ::Appium::Core::ImageElement.new(self,
|
141
|
+
rect['x'],
|
142
|
+
rect['y'],
|
143
|
+
rect['width'],
|
144
|
+
rect['height'],
|
145
|
+
result['visualization'])
|
146
|
+
end
|
147
|
+
rescue ::Selenium::WebDriver::Error::WebDriverError => e
|
148
|
+
acc if e.message.include?('Cannot find any occurrences')
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
87
153
|
# For Appium
|
88
154
|
# override
|
89
155
|
# called in `extend DriverExtensions::HasNetworkConnection`
|
@@ -138,6 +204,10 @@ module Appium
|
|
138
204
|
end
|
139
205
|
end
|
140
206
|
|
207
|
+
def take_element_screenshot(element)
|
208
|
+
execute :take_element_screenshot, id: element.ref
|
209
|
+
end
|
210
|
+
|
141
211
|
private
|
142
212
|
|
143
213
|
# Don't convert locators for Appium Client
|
@@ -1,17 +1,19 @@
|
|
1
|
+
require 'base64'
|
1
2
|
require_relative 'search_context'
|
3
|
+
require_relative 'screenshot'
|
2
4
|
|
3
5
|
module Appium
|
4
6
|
module Core
|
5
7
|
class Base
|
6
8
|
class Driver < ::Selenium::WebDriver::Driver
|
7
9
|
include ::Selenium::WebDriver::DriverExtensions::UploadsFiles
|
8
|
-
include ::Selenium::WebDriver::DriverExtensions::TakesScreenshot
|
9
10
|
include ::Selenium::WebDriver::DriverExtensions::HasSessionId
|
10
11
|
include ::Selenium::WebDriver::DriverExtensions::Rotatable
|
11
12
|
include ::Selenium::WebDriver::DriverExtensions::HasRemoteStatus
|
12
13
|
include ::Selenium::WebDriver::DriverExtensions::HasWebStorage
|
13
14
|
|
14
15
|
include ::Appium::Core::Base::SearchContext
|
16
|
+
include ::Appium::Core::Base::TakeScreenshot
|
15
17
|
|
16
18
|
def initialize(opts = {})
|
17
19
|
listener = opts.delete(:listener)
|
@@ -183,6 +185,77 @@ module Appium
|
|
183
185
|
def session_capabilities
|
184
186
|
@bridge.session_capabilities
|
185
187
|
end
|
188
|
+
|
189
|
+
DEFAULT_MATCH_THRESHOLD = 0.5
|
190
|
+
|
191
|
+
# Return ImageElement if current view has a partial image
|
192
|
+
#
|
193
|
+
# @param [String] png_img_path A path to a partial image you'd like to find
|
194
|
+
# @param [Flood] match_threshold At what normalized threshold to reject
|
195
|
+
# @param [Bool] visualize Makes the endpoint to return an image, which contains the visualized result of
|
196
|
+
# the corresponding picture matching operation. This option is disabled by default.
|
197
|
+
#
|
198
|
+
# @return [::Appium::Core::ImageElement]
|
199
|
+
# @raise [::Appium::Core::Error::NoSuchElementError|::Appium::Core::Error::CoreError] No such element
|
200
|
+
#
|
201
|
+
# @example
|
202
|
+
#
|
203
|
+
# e = @@driver.find_element_by_image './test/functional/data/test_element_image.png'
|
204
|
+
#
|
205
|
+
def find_element_by_image(png_img_path, match_threshold: DEFAULT_MATCH_THRESHOLD, visualize: false)
|
206
|
+
full_image = @bridge.screenshot
|
207
|
+
partial_image = Base64.encode64 File.read(png_img_path)
|
208
|
+
|
209
|
+
element = begin
|
210
|
+
@bridge.find_element_by_image(full_image: full_image,
|
211
|
+
partial_image: partial_image,
|
212
|
+
match_threshold: match_threshold,
|
213
|
+
visualize: visualize)
|
214
|
+
rescue Selenium::WebDriver::Error::TimeOutError
|
215
|
+
raise ::Appium::Core::Error::NoSuchElementError
|
216
|
+
rescue ::Selenium::WebDriver::Error::WebDriverError => e
|
217
|
+
raise ::Appium::Core::Error::NoSuchElementError if e.message.include?('Cannot find any occurrences')
|
218
|
+
raise ::Appium::Core::Error::CoreError, e.message
|
219
|
+
end
|
220
|
+
raise ::Appium::Core::Error::NoSuchElementError if element.nil?
|
221
|
+
|
222
|
+
element
|
223
|
+
end
|
224
|
+
|
225
|
+
# Return ImageElement if current view has partial images
|
226
|
+
#
|
227
|
+
# @param [[String]] png_img_paths Paths to a partial image you'd like to find
|
228
|
+
# @param [Flood] match_threshold At what normalized threshold to reject
|
229
|
+
# @param [Bool] visualize Makes the endpoint to return an image, which contains the visualized result of
|
230
|
+
# the corresponding picture matching operation. This option is disabled by default.
|
231
|
+
#
|
232
|
+
# @return [[::Appium::Core::ImageElement]]
|
233
|
+
# @return [::Appium::Core::Error::CoreError]
|
234
|
+
#
|
235
|
+
# @example
|
236
|
+
#
|
237
|
+
# e = @@driver.find_elements_by_image './test/functional/data/test_element_image.png'
|
238
|
+
# e == [] # if the `e` is empty
|
239
|
+
#
|
240
|
+
def find_elements_by_image(png_img_paths, match_threshold: DEFAULT_MATCH_THRESHOLD, visualize: false)
|
241
|
+
full_image = @bridge.screenshot
|
242
|
+
|
243
|
+
partial_images = png_img_paths.map do |png_img_path|
|
244
|
+
Base64.encode64 File.read(png_img_path)
|
245
|
+
end
|
246
|
+
|
247
|
+
begin
|
248
|
+
@bridge.find_elements_by_image(full_image: full_image,
|
249
|
+
partial_images: partial_images,
|
250
|
+
match_threshold: match_threshold,
|
251
|
+
visualize: visualize)
|
252
|
+
rescue Selenium::WebDriver::Error::TimeOutError
|
253
|
+
[]
|
254
|
+
rescue ::Selenium::WebDriver::Error::WebDriverError => e
|
255
|
+
return [] if e.message.include?('Cannot find any occurrences')
|
256
|
+
raise ::Appium::Core::Error::CoreError, e.message
|
257
|
+
end
|
258
|
+
end
|
186
259
|
end # class Driver
|
187
260
|
end # class Base
|
188
261
|
end # module Core
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Appium
|
2
|
+
module Core
|
3
|
+
class Base
|
4
|
+
module TakeScreenshot
|
5
|
+
#
|
6
|
+
# Save a PNG screenshot to the given path
|
7
|
+
#
|
8
|
+
# @api public
|
9
|
+
#
|
10
|
+
def save_screenshot(png_path)
|
11
|
+
extension = File.extname(png_path).downcase
|
12
|
+
if extension != '.png'
|
13
|
+
::Appium::Logger.warn 'name used for saved screenshot does not match file type. '\
|
14
|
+
'It should end with .png extension'
|
15
|
+
end
|
16
|
+
File.open(png_path, 'wb') { |f| f << screenshot_as(:png) }
|
17
|
+
end
|
18
|
+
|
19
|
+
#
|
20
|
+
# Return a PNG screenshot in the given format as a string
|
21
|
+
#
|
22
|
+
# @param [:base64, :png] format
|
23
|
+
# @return String screenshot
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
#
|
27
|
+
# @@driver.screenshot_as :base64 #=> "iVBORw0KGgoAAAANSUhEUgAABDgAAAB+CAIAAABOPDa6AAAAAX"
|
28
|
+
#
|
29
|
+
# @api public
|
30
|
+
def screenshot_as(format)
|
31
|
+
case format
|
32
|
+
when :base64
|
33
|
+
bridge.screenshot
|
34
|
+
when :png
|
35
|
+
bridge.screenshot.unpack('m')[0]
|
36
|
+
else
|
37
|
+
raise Core::Error::UnsupportedOperationError, "unsupported format: #{format.inspect}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# @param [Selenium::WebDriver::Element] element A element you'd like to take screenshot.
|
42
|
+
# @param [String] png_path A path to save the screenshot
|
43
|
+
# @return [File] Path to the screenshot.
|
44
|
+
#
|
45
|
+
# @example
|
46
|
+
#
|
47
|
+
# @driver.save_element_screenshot(element, "fine_name.png")
|
48
|
+
#
|
49
|
+
def save_element_screenshot(element, png_path)
|
50
|
+
extension = File.extname(png_path).downcase
|
51
|
+
if extension != '.png'
|
52
|
+
::Appium::Logger.warn 'name used for saved screenshot does not match file type. '\
|
53
|
+
'It should end with .png extension'
|
54
|
+
end
|
55
|
+
File.open(png_path, 'wb') { |f| f << element_screenshot_as(element, :png) }
|
56
|
+
end
|
57
|
+
# backward compatibility
|
58
|
+
alias take_element_screenshot save_element_screenshot
|
59
|
+
|
60
|
+
#
|
61
|
+
# Return a PNG screenshot in the given format as a string
|
62
|
+
#
|
63
|
+
# @param [:base64, :png] format
|
64
|
+
# @return String screenshot
|
65
|
+
#
|
66
|
+
# @example
|
67
|
+
#
|
68
|
+
# @@driver.element_screenshot_as element, :base64 #=> "iVBORw0KGgoAAAANSUhEUgAABDgAAAB+CAIAAABOPDa6AAAAAX"
|
69
|
+
#
|
70
|
+
def element_screenshot_as(element, format)
|
71
|
+
case format
|
72
|
+
when :base64
|
73
|
+
bridge.take_element_screenshot(element)
|
74
|
+
when :png
|
75
|
+
bridge.take_element_screenshot(element).unpack('m')[0]
|
76
|
+
else
|
77
|
+
raise Core::Error::UnsupportedOperationError, "unsupported format: #{format.inspect}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require_relative 'common/touch_action/touch_actions'
|
2
2
|
require_relative 'common/touch_action/multi_touch'
|
3
3
|
|
4
|
+
require_relative 'element/image'
|
5
|
+
|
4
6
|
require_relative 'device/screen_record'
|
5
7
|
require_relative 'device/app_state'
|
6
8
|
require_relative 'device/clipboard_content_type'
|
@@ -475,16 +477,6 @@ module Appium
|
|
475
477
|
# @driver.switch_to_default_context
|
476
478
|
#
|
477
479
|
|
478
|
-
# @!method take_element_screenshot(element, png_path)
|
479
|
-
# @param [Selenium::WebDriver::Element] element A element you'd like to take screenshot.
|
480
|
-
# @param [String] png_path A path to save the screenshot
|
481
|
-
# @return [File] Path to the screenshot.
|
482
|
-
#
|
483
|
-
# @example
|
484
|
-
#
|
485
|
-
# @driver.take_element_screenshot(element, "fine_name.png")
|
486
|
-
#
|
487
|
-
|
488
480
|
# @!method stop_recording_screen(remote_path: nil, user: nil, pass: nil, method: 'PUT')
|
489
481
|
# @param [String] remote_path: The path to the remote location, where the resulting video should be uploaded.
|
490
482
|
# The following protocols are supported: http/https, ftp.
|
@@ -534,19 +526,6 @@ module Appium
|
|
534
526
|
end
|
535
527
|
end
|
536
528
|
|
537
|
-
add_endpoint_method(:take_element_screenshot) do
|
538
|
-
def take_element_screenshot(element, png_path)
|
539
|
-
result = execute :take_element_screenshot, id: element.ref
|
540
|
-
|
541
|
-
extension = File.extname(png_path).downcase
|
542
|
-
if extension != '.png'
|
543
|
-
::Appium::Logger.warn 'name used for saved screenshot does not match file type. '\
|
544
|
-
'It should end with .png extension'
|
545
|
-
end
|
546
|
-
File.open(png_path, 'wb') { |f| f << result.unpack('m')[0] }
|
547
|
-
end
|
548
|
-
end
|
549
|
-
|
550
529
|
add_endpoint_method(:save_viewport_screenshot) do
|
551
530
|
def save_viewport_screenshot(png_path)
|
552
531
|
extension = File.extname(png_path).downcase
|
@@ -572,6 +551,10 @@ module Appium
|
|
572
551
|
ScreenRecord.add_methods
|
573
552
|
ImageComparison.add_methods
|
574
553
|
AppState.add_methods
|
554
|
+
|
555
|
+
# Compatibility for appium_lib
|
556
|
+
# TODO: Will remove
|
557
|
+
delegate_from_appium_driver :take_element_screenshot
|
575
558
|
end
|
576
559
|
|
577
560
|
# def extended
|
@@ -45,7 +45,7 @@ module Appium
|
|
45
45
|
# File.write 'match_images_visual.png', Base64.decode64(visual['visualization']) # if the image is PNG
|
46
46
|
#
|
47
47
|
|
48
|
-
# @!method find_image_occurrence(full_image:, partial_image:,
|
48
|
+
# @!method find_image_occurrence(full_image:, partial_image:, visualize: false, threshold: nil)
|
49
49
|
# Performs images matching by template to find possible occurrence of the partial image
|
50
50
|
# in the full image with default options. Read https://docs.opencv.org/2.4/doc/tutorials/imgproc/histograms/template_matching/template_matching.html
|
51
51
|
# for more details on this topic.
|
@@ -55,6 +55,7 @@ module Appium
|
|
55
55
|
# are supported.
|
56
56
|
# @param [Bool] visualise: Makes the endpoint to return an image, which contains the visualized result of
|
57
57
|
# the corresponding picture matching operation. This option is disabled by default.
|
58
|
+
# @param [Float] threshold: [0.5] At what normalized threshold to reject
|
58
59
|
#
|
59
60
|
# @example
|
60
61
|
# @driver.find_image_occurrence full_image: "image data 1", partial_image: "image data 2"
|
@@ -129,13 +130,14 @@ module Appium
|
|
129
130
|
end
|
130
131
|
|
131
132
|
::Appium::Core::Device.add_endpoint_method(:find_image_occurrence) do
|
132
|
-
def find_image_occurrence(full_image:, partial_image:, visualize: false)
|
133
|
+
def find_image_occurrence(full_image:, partial_image:, visualize: false, threshold: nil)
|
133
134
|
unless ::Appium::Core::Device::ImageComparison::MATCH_TEMPLATE[:visualize].member?(visualize)
|
134
135
|
raise "visualize should be #{::Appium::Core::Device::ImageComparison::MATCH_TEMPLATE[:visualize]}"
|
135
136
|
end
|
136
137
|
|
137
138
|
options = {}
|
138
139
|
options[:visualize] = visualize
|
140
|
+
options[:threshold] = threshold unless threshold.nil?
|
139
141
|
|
140
142
|
compare_images(mode: :matchTemplate, first_image: full_image, second_image: partial_image, options: options)
|
141
143
|
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
module Appium
|
2
|
+
module Core
|
3
|
+
#
|
4
|
+
# ImageElement is an element for images by `find_element/s_by_image`
|
5
|
+
# Experimental feature
|
6
|
+
#
|
7
|
+
class ImageElement
|
8
|
+
Point = Struct.new(:x, :y)
|
9
|
+
Dimension = Struct.new(:width, :height)
|
10
|
+
Rectangle = Struct.new(:x, :y, :width, :height)
|
11
|
+
|
12
|
+
# Base64ed format
|
13
|
+
# @example
|
14
|
+
#
|
15
|
+
# File.write 'result.png', Base64.decode64(e.visual)
|
16
|
+
#
|
17
|
+
attr_reader :visual
|
18
|
+
|
19
|
+
def initialize(bridge, x, y, width, height, visual = nil) # rubocop:disable Metrics/ParameterLists
|
20
|
+
@bridge = bridge
|
21
|
+
@visual = visual
|
22
|
+
|
23
|
+
@center_x = x + width / 2
|
24
|
+
@center_y = y + height / 2
|
25
|
+
@x = x
|
26
|
+
@y = y
|
27
|
+
@width = width
|
28
|
+
@height = height
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Click this element.
|
33
|
+
#
|
34
|
+
# @example
|
35
|
+
#
|
36
|
+
# e = @@driver.find_element_by_image './test/functional/data/test_element_image.png'
|
37
|
+
# e.click
|
38
|
+
#
|
39
|
+
def click
|
40
|
+
@bridge.action.move_to_location(@center_x, @center_y).click.perform
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Get the location of this element.
|
45
|
+
#
|
46
|
+
# @return [Point]
|
47
|
+
#
|
48
|
+
# @example
|
49
|
+
#
|
50
|
+
# e = @@driver.find_element_by_image './test/functional/data/test_element_image.png'
|
51
|
+
# assert_equal [39, 1014], [e.location.x, e.location.y]
|
52
|
+
#
|
53
|
+
def location
|
54
|
+
Point.new @x, @y
|
55
|
+
end
|
56
|
+
|
57
|
+
#
|
58
|
+
# Get the size of this element
|
59
|
+
#
|
60
|
+
# @return [Dimension]
|
61
|
+
#
|
62
|
+
# @example
|
63
|
+
#
|
64
|
+
# e = @@driver.find_element_by_image './test/functional/data/test_element_image.png'
|
65
|
+
# assert_equal [326, 62], [e.size.width, e.size.height]
|
66
|
+
#
|
67
|
+
def size
|
68
|
+
Dimension.new @width, @height
|
69
|
+
end
|
70
|
+
|
71
|
+
#
|
72
|
+
# Get the dimensions and coordinates of this element.
|
73
|
+
#
|
74
|
+
# @return [Rectangle]
|
75
|
+
#
|
76
|
+
# @example
|
77
|
+
#
|
78
|
+
# e = @@driver.find_element_by_image './test/functional/data/test_element_image.png'
|
79
|
+
# assert_equal([39, 1014, 326, 62], [e.rect.x, e.rect.y, e.rect.width, e.rect.height])
|
80
|
+
#
|
81
|
+
def rect
|
82
|
+
Rectangle.new @x, @y, @width, @height
|
83
|
+
end
|
84
|
+
|
85
|
+
def displayed?
|
86
|
+
true
|
87
|
+
end
|
88
|
+
|
89
|
+
#-------------------------------- sugar --------------------------------
|
90
|
+
|
91
|
+
def first(full_image:, partial_image:, match_threshold: nil, visualize: false)
|
92
|
+
@bridge.find_element_by_image(full_image: full_image,
|
93
|
+
partial_image: partial_image,
|
94
|
+
match_threshold: match_threshold,
|
95
|
+
visualize: visualize)
|
96
|
+
end
|
97
|
+
|
98
|
+
def all(full_image:, partial_image:, match_threshold: nil, visualize: false)
|
99
|
+
@bridge.find_elements_by_image(full_image: full_image,
|
100
|
+
partial_image: partial_image,
|
101
|
+
match_threshold: match_threshold,
|
102
|
+
visualize: visualize)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Appium
|
2
2
|
module Core
|
3
|
-
VERSION = '1.7.
|
4
|
-
DATE = '2018-06-
|
3
|
+
VERSION = '1.7.2'.freeze unless defined? ::Appium::Core::VERSION
|
4
|
+
DATE = '2018-06-23'.freeze unless defined? ::Appium::Core::DATE
|
5
5
|
end
|
6
6
|
end
|
data/release_notes.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
#### v1.7.2 2018-06-23
|
2
|
+
|
3
|
+
- [72bbc01](https://github.com/appium/ruby_lib_core/commit/72bbc01dc69579c5b7dea43b6ec01fee37299ebe) Release 1.7.2
|
4
|
+
- [5438246](https://github.com/appium/ruby_lib_core/commit/54382468e226d38f16d651b7b9f6da952d766d22) Define screenshot methods in this lib (#98)
|
5
|
+
- [9bd9e11](https://github.com/appium/ruby_lib_core/commit/9bd9e11c20ce37a9e8e0384c09c663913aca0d15) Use bridge for imageelement(#96)
|
6
|
+
- [7e7fba3](https://github.com/appium/ruby_lib_core/commit/7e7fba32a89ce547e81d68eb6659db464be7a60f) add image element/s (#95)
|
7
|
+
|
8
|
+
|
1
9
|
#### v1.7.1 2018-06-15
|
2
10
|
|
3
11
|
- [84febaf](https://github.com/appium/ruby_lib_core/commit/84febaf3a5b4dff0084455556d3ffe1293b64471) Release 1.7.1
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appium_lib_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kazuaki MATSUO
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: selenium-webdriver
|
@@ -245,6 +245,7 @@ files:
|
|
245
245
|
- lib/appium_lib_core/common/base/command.rb
|
246
246
|
- lib/appium_lib_core/common/base/driver.rb
|
247
247
|
- lib/appium_lib_core/common/base/http_default.rb
|
248
|
+
- lib/appium_lib_core/common/base/screenshot.rb
|
248
249
|
- lib/appium_lib_core/common/base/search_context.rb
|
249
250
|
- lib/appium_lib_core/common/command.rb
|
250
251
|
- lib/appium_lib_core/common/command/common.rb
|
@@ -275,6 +276,7 @@ files:
|
|
275
276
|
- lib/appium_lib_core/device/touch_actions.rb
|
276
277
|
- lib/appium_lib_core/device/value.rb
|
277
278
|
- lib/appium_lib_core/driver.rb
|
279
|
+
- lib/appium_lib_core/element/image.rb
|
278
280
|
- lib/appium_lib_core/ios.rb
|
279
281
|
- lib/appium_lib_core/ios/device.rb
|
280
282
|
- lib/appium_lib_core/ios/device/clipboard.rb
|