Class: Appium::Core::ImageElement

Inherits:
Object
  • Object
show all
Defined in:
lib/appium_lib_core/element/image.rb

Overview

ImageElement is an element for images by ‘find_element/s_by_image` Experimental feature

Defined Under Namespace

Classes: Dimension, Point, Rectangle

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bridge, x, y, width, height, visual = nil) ⇒ ImageElement

Returns a new instance of ImageElement.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/appium_lib_core/element/image.rb', line 19

def initialize(bridge, x, y, width, height, visual = nil)
  @bridge = bridge
  @visual = visual

  @center_x = x + width / 2
  @center_y = y + height / 2
  @x = x
  @y = y
  @width = width
  @height = height
end

Instance Attribute Details

#visualObject (readonly)

Base64ed format

Examples:


File.write 'result.png', Base64.decode64(e.visual)


17
18
19
# File 'lib/appium_lib_core/element/image.rb', line 17

def visual
  @visual
end

Instance Method Details

#all(full_image:, partial_image:, match_threshold: nil, visualize: false) ⇒ Object



98
99
100
101
102
103
# File 'lib/appium_lib_core/element/image.rb', line 98

def all(full_image:, partial_image:, match_threshold: nil, visualize: false)
  @bridge.find_elements_by_image(full_image: full_image,
                                 partial_image: partial_image,
                                 match_threshold: match_threshold,
                                 visualize: visualize)
end

#clickObject

Click this element.

Examples:


e = @@driver.find_element_by_image './test/functional/data/test_element_image.png'
e.click


39
40
41
# File 'lib/appium_lib_core/element/image.rb', line 39

def click
  @bridge.action.move_to_location(@center_x, @center_y).click.perform
end

#displayed?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/appium_lib_core/element/image.rb', line 85

def displayed?
  true
end

#first(full_image:, partial_image:, match_threshold: nil, visualize: false) ⇒ Object

——————————– sugar ——————————–



91
92
93
94
95
96
# File 'lib/appium_lib_core/element/image.rb', line 91

def first(full_image:, partial_image:, match_threshold: nil, visualize: false)
  @bridge.find_element_by_image(full_image: full_image,
                                partial_image: partial_image,
                                match_threshold: match_threshold,
                                visualize: visualize)
end

#locationPoint

Get the location of this element.

Examples:


e = @@driver.find_element_by_image './test/functional/data/test_element_image.png'
assert_equal [39, 1014], [e.location.x, e.location.y]

Returns:



53
54
55
# File 'lib/appium_lib_core/element/image.rb', line 53

def location
  Point.new @x, @y
end

#rectRectangle

Get the dimensions and coordinates of this element.

Examples:


e = @@driver.find_element_by_image './test/functional/data/test_element_image.png'
    assert_equal([39, 1014, 326, 62], [e.rect.x, e.rect.y, e.rect.width, e.rect.height])

Returns:



81
82
83
# File 'lib/appium_lib_core/element/image.rb', line 81

def rect
  Rectangle.new @x, @y, @width, @height
end

#sizeDimension

Get the size of this element

Examples:


e = @@driver.find_element_by_image './test/functional/data/test_element_image.png'
    assert_equal [326, 62], [e.size.width, e.size.height]

Returns:



67
68
69
# File 'lib/appium_lib_core/element/image.rb', line 67

def size
  Dimension.new @width, @height
end