Class: Appium::Core::Base::Bridge::MJSONWP

Inherits:
Selenium::WebDriver::Remote::OSS::Bridge
  • Object
show all
Defined in:
lib/appium_lib_core/common/base/bridge/mjsonwp.rb

Instance Method Summary collapse

Instance Method Details

#commands(command) ⇒ Object



6
7
8
# File 'lib/appium_lib_core/common/base/bridge/mjsonwp.rb', line 6

def commands(command)
  ::Appium::Core::Commands::MJSONWP::COMMANDS[command]
end

#find_element_by_image(full_image:, partial_image:, match_threshold: nil, visualize: false) ⇒ ::Appium::Core::ImageElement|nil

Returns:

Raises:

  • (::Selenium::WebDriver::Error::TimeOutError|::Selenium::WebDriver::Error::WebDriverError)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/appium_lib_core/common/base/bridge/mjsonwp.rb', line 14

def find_element_by_image(full_image:, partial_image:, match_threshold: nil, visualize: false)
  options = {}
  options[:threshold] = match_threshold unless match_threshold.nil?
  options[:visualize] = visualize

  params = {}
  params[:mode] = :matchTemplate
  params[:firstImage] = full_image
  params[:secondImage] = partial_image
  params[:options] = options if options

  result = execute(:compare_images, {}, params)
  rect = result['rect']

  if rect
    return ::Appium::Core::ImageElement.new(self,
                                            rect['x'],
                                            rect['y'],
                                            rect['width'],
                                            rect['height'],
                                            result['visualization'])
  end
  nil
end

#find_elements_by_image(full_image:, partial_images:, match_threshold: nil, visualize: false) ⇒ []|[::Appium::Core::ImageElement]

Returns:

Raises:

  • (::Selenium::WebDriver::Error::TimeOutError|::Selenium::WebDriver::Error::WebDriverError)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/appium_lib_core/common/base/bridge/mjsonwp.rb', line 43

def find_elements_by_image(full_image:, partial_images:, match_threshold: nil, visualize: false)
  options = {}
  options[:threshold] = match_threshold unless match_threshold.nil?
  options[:visualize] = visualize

  params = {}
  params[:mode] = :matchTemplate
  params[:firstImage] = full_image
  params[:options] = options if options

  partial_images.each_with_object([]) do |partial_image, acc|
    params[:secondImage] = partial_image

    begin
      result = execute(:compare_images, {}, params)
      rect = result['rect']

      if result['rect']
        acc.push ::Appium::Core::ImageElement.new(self,
                                                  rect['x'],
                                                  rect['y'],
                                                  rect['width'],
                                                  rect['height'],
                                                  result['visualization'])
      end
    rescue ::Selenium::WebDriver::Error::WebDriverError => e
      acc if e.message.include?('Cannot find any occurrences')
    end
  end
end

#take_element_screenshot(element) ⇒ Object



74
75
76
# File 'lib/appium_lib_core/common/base/bridge/mjsonwp.rb', line 74

def take_element_screenshot(element)
  execute :take_element_screenshot, id: element.ref
end