Module: AutomationObject::Driver::CommonSelenium::ElementGeometry

Included in:
Element
Defined in:
lib/automation_object/driver/common_selenium/element_geometry.rb

Overview

Helper module for Selenium based elements

Instance Method Summary collapse

Instance Method Details

#box_coordinatesBoxCoordinates

Returns :x1, :x2, :y1, :y2 coordinates of a box

Returns:



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/automation_object/driver/common_selenium/element_geometry.rb', line 55

def box_coordinates
  element_location = @subject.location
  element_size = @subject.size

  box_coordinates = BoxCoordinates.new
  box_coordinates.x1 = element_location.x.to_f
  box_coordinates.y1 = element_location.y.to_f
  box_coordinates.x2 = element_location.x.to_f + element_size.width.to_f
  box_coordinates.y2 = element_location.y.to_f + element_size.height.to_f

  box_coordinates
end

#collides_with_element?(second_element_object, collision_tolerance = 0) ⇒ Boolean

Returns element collides with other

Parameters:

  • second_element_object (Object)

    element to compare to

  • collision_tolerance (Numeric) (defaults to: 0)

    pixel tolerance of collisions

Returns:

  • (Boolean)

    element collides with other



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/automation_object/driver/common_selenium/element_geometry.rb', line 71

def collides_with_element?(second_element_object, collision_tolerance = 0)
  box_one = box_coordinates
  box_two = second_element_object.box_coordinates

  if box_one.x2 > box_two.x1 && box_one.x1 < box_two.x2 && box_one.y2 > box_two.y1 && box_one.y1 < box_two.y2
    if box_one.x2 > (box_two.x1 + collision_tolerance) && (box_one.x1 + collision_tolerance) < box_two.x2 &&
       box_one.y2 > (box_two.y1 + collision_tolerance) && (box_one.y1 + collision_tolerance) < box_two.y2
      return true
    end
  end

  false
end

#element_centerHash

Returns :x, :y coordinates

Returns:

  • (Hash)

    :x, :y coordinates



43
44
45
46
47
48
49
50
51
52
# File 'lib/automation_object/driver/common_selenium/element_geometry.rb', line 43

def element_center
  element_location = @subject.location
  element_size = @subject.size

  center = Point.new
  center.x = (element_location.x.to_f + element_size.width.to_f / 2).to_f
  center.y = (element_location.y.to_f + element_size.height.to_f / 2).to_f

  center
end

#heightNumeric

Returns height of element

Returns:

  • (Numeric)

    height of element



26
27
28
# File 'lib/automation_object/driver/common_selenium/element_geometry.rb', line 26

def height
  @subject.size.height
end

#locationPoint

Get the location

Returns:



32
33
34
# File 'lib/automation_object/driver/common_selenium/element_geometry.rb', line 32

def location
  @subject.location
end

#sizeDimension

Get the size of an element

Returns:



38
39
40
# File 'lib/automation_object/driver/common_selenium/element_geometry.rb', line 38

def size
  @subject.size
end

#widthNumeric

Returns width of element

Returns:

  • (Numeric)

    width of element



21
22
23
# File 'lib/automation_object/driver/common_selenium/element_geometry.rb', line 21

def width
  @subject.size.width
end

#xNumeric

Returns x position of element

Returns:

  • (Numeric)

    x position of element



11
12
13
# File 'lib/automation_object/driver/common_selenium/element_geometry.rb', line 11

def x
  @subject.location.x
end

#yNumeric

Returns y position of element

Returns:

  • (Numeric)

    y position of element



16
17
18
# File 'lib/automation_object/driver/common_selenium/element_geometry.rb', line 16

def y
  @subject.location.y
end