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
-
#box_coordinates ⇒ BoxCoordinates
:x1, :x2, :y1, :y2 coordinates of a box.
-
#collides_with_element?(second_element_object, collision_tolerance = 0) ⇒ Boolean
Element collides with other.
-
#element_center ⇒ Hash
:x, :y coordinates.
-
#height ⇒ Numeric
Height of element.
-
#location ⇒ Point
Get the location.
-
#size ⇒ Dimension
Get the size of an element.
-
#width ⇒ Numeric
Width of element.
-
#x ⇒ Numeric
X position of element.
-
#y ⇒ Numeric
Y position of element.
Instance Method Details
#box_coordinates ⇒ BoxCoordinates
Returns :x1, :x2, :y1, :y2 coordinates of a box
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
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_center ⇒ Hash
Returns :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 |
#height ⇒ Numeric
Returns height of element
26 27 28 |
# File 'lib/automation_object/driver/common_selenium/element_geometry.rb', line 26 def height @subject.size.height end |
#location ⇒ Point
Get the location
32 33 34 |
# File 'lib/automation_object/driver/common_selenium/element_geometry.rb', line 32 def location @subject.location end |
#size ⇒ Dimension
Get the size of an element
38 39 40 |
# File 'lib/automation_object/driver/common_selenium/element_geometry.rb', line 38 def size @subject.size end |
#width ⇒ Numeric
Returns width of element
21 22 23 |
# File 'lib/automation_object/driver/common_selenium/element_geometry.rb', line 21 def width @subject.size.width end |
#x ⇒ Numeric
Returns 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 |
#y ⇒ Numeric
Returns 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 |