Class: WDA::Element
- Inherits:
-
Object
- Object
- WDA::Element
- Defined in:
- lib/wda_lib/element.rb
Instance Method Summary collapse
-
#accessible? ⇒ Boolean
Check if element is accessible?.
-
#accessible_container? ⇒ Boolean
Check if element is accessibilityContainer?.
-
#attribute ⇒ Object
(also: #[])
Get attribute value.
-
#clear ⇒ Object
Clearing text of an given element.
-
#click ⇒ Object
Tap on an element with its id.
-
#displayed? ⇒ Boolean
Check if element is displayed?.
-
#double_tap ⇒ Object
Double tap on an element with its id.
-
#drag_element_from_to(fromX, toX, fromY, toY, duration = 0) ⇒ Object
Drag on an element with its id and position.
-
#drag_from_to(fromX, toX, fromY, toY, duration = 0) ⇒ Object
Drag from a position to another position.
- #eid ⇒ Object
-
#elswipe(scale, velocity) ⇒ Object
Element pinch.
-
#enabled? ⇒ Boolean
Check if element is enabled?.
-
#initialize(client, id) ⇒ Element
constructor
A new instance of Element.
-
#inspect ⇒ Object
Remove useless attributes, return object only with element.
-
#location ⇒ Struct
Get element size.
- #name ⇒ Object
-
#rect ⇒ Object
Get wdRect by id.
- #ref ⇒ Object
-
#scroll(direction = nil) ⇒ Hash
Scroll on an element with its id.
-
#send_keys(value) ⇒ Object
Set value to an element.
-
#size ⇒ Struct
Get element size.
-
#text ⇒ Object
Get text from an element(StaticText or Button).
-
#touch_hold(duration) ⇒ Object
Touch and hold on for a while finger tap on an element with its id.
-
#two_finger_tap ⇒ Object
Two finger tap on an element with its id.
-
#type ⇒ Object
Get type from an element, ex: type => “Icon”(XCUIElementTypeIcon).
Constructor Details
#initialize(client, id) ⇒ Element
Returns a new instance of Element.
8 9 10 11 |
# File 'lib/wda_lib/element.rb', line 8 def initialize(client, id) @client = client @id = id end |
Instance Method Details
#accessible? ⇒ Boolean
Check if element is accessible?
59 60 61 |
# File 'lib/wda_lib/element.rb', line 59 def accessible? client.get('/wda/element/' + eid + '/accessible')['value'] end |
#accessible_container? ⇒ Boolean
Check if element is accessibilityContainer?
65 66 67 |
# File 'lib/wda_lib/element.rb', line 65 def accessible_container? client.get('/wda/element/' + eid + '/accessibilityContainer')['value'] end |
#attribute ⇒ Object Also known as: []
Get attribute value
41 42 43 |
# File 'lib/wda_lib/element.rb', line 41 def attribute client.get '/element/' + eid + '/attribute/name' end |
#clear ⇒ Object
Clearing text of an given element
94 95 96 |
# File 'lib/wda_lib/element.rb', line 94 def clear client.post '/element/' + eid + '/clear' end |
#click ⇒ Object
Tap on an element with its id
88 89 90 |
# File 'lib/wda_lib/element.rb', line 88 def click client.post '/element/' + eid + '/click' end |
#displayed? ⇒ Boolean
Check if element is displayed?
53 54 55 |
# File 'lib/wda_lib/element.rb', line 53 def displayed? client.get('/element/' + eid + '/displayed')['value'] end |
#double_tap ⇒ Object
Double tap on an element with its id
114 115 116 |
# File 'lib/wda_lib/element.rb', line 114 def double_tap client.post '/wda/element/' + eid + '/doubleTap' end |
#drag_element_from_to(fromX, toX, fromY, toY, duration = 0) ⇒ Object
Drag on an element with its id and position
140 141 142 |
# File 'lib/wda_lib/element.rb', line 140 def drag_element_from_to(fromX, toX, fromY, toY, duration = 0) client.post '/wda/element/' + eid + '/dragfromtoforduration', { fromX: fromX, toX: toX, fromY: fromY, toY: toY, duration: duration } end |
#drag_from_to(fromX, toX, fromY, toY, duration = 0) ⇒ Object
Drag from a position to another position
146 147 148 |
# File 'lib/wda_lib/element.rb', line 146 def drag_from_to(fromX, toX, fromY, toY, duration = 0) client.post '/wda/dragfromtoforduration', { fromX: fromX, toX: toX, fromY: fromY, toY: toY, duration: duration } end |
#eid ⇒ Object
22 23 24 |
# File 'lib/wda_lib/element.rb', line 22 def eid @id['ELEMENT'] end |
#elswipe(scale, velocity) ⇒ Object
Element pinch
101 102 103 |
# File 'lib/wda_lib/element.rb', line 101 def elswipe(direction) client.post('/wda/element/' + eid + '/swipe', { direction: direction }) end |
#enabled? ⇒ Boolean
Check if element is enabled?
28 29 30 |
# File 'lib/wda_lib/element.rb', line 28 def enabled? client.get('/element/' + eid + '/enabled')['value'] end |
#inspect ⇒ Object
Remove useless attributes, return object only with element
14 15 16 |
# File 'lib/wda_lib/element.rb', line 14 def inspect format '#<%s:0x%x id=%s>', self.class, hash * 2, @id.inspect end |
#location ⇒ Struct
Get element size
159 160 161 162 |
# File 'lib/wda_lib/element.rb', line 159 def location r = rect Point.new(r['x'], r['y']) end |
#name ⇒ Object
75 76 77 |
# File 'lib/wda_lib/element.rb', line 75 def name type end |
#rect ⇒ Object
Get wdRect by id
34 35 36 |
# File 'lib/wda_lib/element.rb', line 34 def rect client.get('/element/' + eid + '/rect')['value'] end |
#ref ⇒ Object
18 19 20 |
# File 'lib/wda_lib/element.rb', line 18 def ref @id end |
#scroll(direction = nil) ⇒ Hash
Scroll on an element with its id
134 135 136 |
# File 'lib/wda_lib/element.rb', line 134 def scroll(direction = nil) client.post '/wda/element/' + eid + '/scroll', { direction: direction } end |
#send_keys(value) ⇒ Object
Set value to an element
82 83 84 |
# File 'lib/wda_lib/element.rb', line 82 def send_keys(value) client.post '/element/' + eid + '/value', { value: value.chars } end |
#size ⇒ Struct
Get element size
152 153 154 155 |
# File 'lib/wda_lib/element.rb', line 152 def size r = rect['value'] Dimension.new(r['width'], r['height']) end |
#text ⇒ Object
Get text from an element(StaticText or Button)
47 48 49 |
# File 'lib/wda_lib/element.rb', line 47 def text client.get('/element/' + eid + '/text')['value'] end |
#touch_hold(duration) ⇒ Object
Touch and hold on for a while finger tap on an element with its id
127 128 129 |
# File 'lib/wda_lib/element.rb', line 127 def touch_hold(duration) client.post '/wda/element/' + eid + '/touchAndHold', { duration: duration } end |
#two_finger_tap ⇒ Object
Two finger tap on an element with its id
120 121 122 |
# File 'lib/wda_lib/element.rb', line 120 def two_finger_tap client.post '/wda/element/' + eid + '/twoFingerTap' end |
#type ⇒ Object
Get type from an element, ex: type => “Icon”(XCUIElementTypeIcon)
71 72 73 |
# File 'lib/wda_lib/element.rb', line 71 def type client.get('/element/' + eid + '/name')['value'] end |