@@ -6,6 +6,74 @@ class MJSONWP < ::Selenium::WebDriver::Remote::OSS::Bridge
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
0 commit comments