Class: Aaet::Locators
- Inherits:
-
Object
- Object
- Aaet::Locators
- Defined in:
- lib/aaet/common/locators.rb
Instance Method Summary collapse
- #activity ⇒ Object
- #click(locator, *optional) ⇒ Object
- #displayed?(locator) ⇒ Boolean
- #element_center(location, size) ⇒ Object
-
#enter(locator, string) ⇒ Object
For Login Method.
- #fa(locator) ⇒ Object
- #fe(locator) ⇒ Object
- #get_center(element) ⇒ Object
- #get_text(string) ⇒ Object
- #get_window_size ⇒ Object
- #long_press(element) ⇒ Object
- #press(coords) ⇒ Object
- #pull_to_refresh ⇒ Object
- #random_tap ⇒ Object
- #swipe_down ⇒ Object
- #swipe_left ⇒ Object
- #swipe_right ⇒ Object
- #swipe_up ⇒ Object
- #tap(args = {}) ⇒ Object
- #tap2(coords) ⇒ Object
- #type(string) ⇒ Object
Instance Method Details
#activity ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/aaet/common/locators.rb', line 4 def activity count = 0 begin JSON.parse(`curl -s #{caps_url}/session/#{driver.session_id}/appium/device/current_activity`)['value'] rescue count+=1 return if count > 3 retry end end |
#click(locator, *optional) ⇒ Object
155 156 157 158 159 160 161 |
# File 'lib/aaet/common/locators.rb', line 155 def click locator, *optional begin locator.click rescue nil end end |
#displayed?(locator) ⇒ Boolean
147 148 149 150 151 152 153 |
# File 'lib/aaet/common/locators.rb', line 147 def displayed? locator begin fe(locator).displayed? rescue false end end |
#element_center(location, size) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/aaet/common/locators.rb', line 27 def element_center(location, size) location_x = location.x.to_f location_y = location.y.to_f size_width = size.width.to_f size_height = size.height.to_f x = location_x + (size_width / 2.0) y = location_y + (size_height / 2.0) {x: x, y: y} end |
#enter(locator, string) ⇒ Object
For Login Method
172 173 174 175 176 177 178 |
# File 'lib/aaet/common/locators.rb', line 172 def enter locator, string begin locator.send_keys string rescue nil end end |
#fa(locator) ⇒ Object
131 132 133 134 135 136 137 |
# File 'lib/aaet/common/locators.rb', line 131 def fa locator begin find_elements(locator) rescue [] end end |
#fe(locator) ⇒ Object
123 124 125 126 127 128 129 |
# File 'lib/aaet/common/locators.rb', line 123 def fe locator begin find_element(locator) rescue nil end end |
#get_center(element) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/aaet/common/locators.rb', line 15 def get_center(element) location = element.location location_x = location.x.to_f location_y = location.y.to_f size = element.size size_width = size.width.to_f size_height = size.height.to_f x = location_x + (size_width / 2.0) y = location_y + (size_height / 2.0) {x: x, y: y} end |
#get_text(string) ⇒ Object
139 140 141 142 143 144 145 |
# File 'lib/aaet/common/locators.rb', line 139 def get_text string begin text string rescue nil end end |
#get_window_size ⇒ Object
82 83 84 |
# File 'lib/aaet/common/locators.rb', line 82 def get_window_size window_size.to_h end |
#long_press(element) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/aaet/common/locators.rb', line 37 def long_press element center = get_center(element) center.merge!(fingers: 1, duration: 550) action = Appium::TouchAction.new.long_press center action.release.perform end |
#press(coords) ⇒ Object
44 45 46 47 48 |
# File 'lib/aaet/common/locators.rb', line 44 def press coords coords.merge!(fingers: 1, duration: 550) action = Appium::TouchAction.new.long_press coords begin action.release.perform rescue nil end end |
#pull_to_refresh ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/aaet/common/locators.rb', line 73 def pull_to_refresh size = get_window_size start_x = size[:width] / 2 start_y = size[:height] / 2 end_x = size[:width] / 2 end_y = size[:height] - 100 Appium::TouchAction.new.press({x:start_x,y:start_y}).wait(200).move_to({x:end_x,y:end_y}).release.perform end |
#random_tap ⇒ Object
66 67 68 69 70 71 |
# File 'lib/aaet/common/locators.rb', line 66 def random_tap x = rand(0..@window_size[0]) y = rand(0..@window_size[1]) puts "\nRandom Tap Location: { x: #{x}, y: #{y} }\n".yellow tap({:x=>x, :y=>y}) end |
#swipe_down ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/aaet/common/locators.rb', line 86 def swipe_down size = @window_size start_x = size[0] / 2 start_y = size[1] / 2 end_x = size[0] / 2 end_y = size[1] - 200 Appium::TouchAction.new.press({x:start_x,y:start_y}).wait(200).move_to({x:end_x,y:end_y}).release.perform end |
#swipe_left ⇒ Object
104 105 106 107 108 109 110 111 112 |
# File 'lib/aaet/common/locators.rb', line 104 def swipe_left size = @window_size start_x = (size[0] - 60).to_f start_y = (size[1] / 2).to_f end_x = 60.to_f end_y = (size[1] / 2).to_f Appium::TouchAction.new.press({x:start_x,y:start_y}).wait(200).move_to({x:end_x,y:end_y}).release.perform #swipe({start_x:63,end_y:326}) end |
#swipe_right ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/aaet/common/locators.rb', line 114 def swipe_right size = @window_size start_x = 60.to_f start_y = (size[1] / 2).to_f end_x = (size[0] - 60).to_f end_y = (size[1] / 2).to_f Appium::TouchAction.new.press({x:start_x,y:start_y}).wait(200).move_to({x:end_x,y:end_y}).release.perform end |
#swipe_up ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/aaet/common/locators.rb', line 95 def swipe_up size = @window_size start_x = size[0] / 2 start_y = size[1] / 2 end_x = size[0] / 2 end_y = 100 Appium::TouchAction.new.press({x:start_x,y:start_y}).wait(200).move_to({x:end_x,y:end_y}).release.perform end |
#tap(args = {}) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/aaet/common/locators.rb', line 50 def tap args = {} begin Appium::TouchAction.new.tap(args).release.perform rescue nil end end |
#tap2(coords) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/aaet/common/locators.rb', line 58 def tap2 coords begin Appium::TouchAction.new.tap(coords).release.perform rescue nil end end |
#type(string) ⇒ Object
163 164 165 166 167 168 169 |
# File 'lib/aaet/common/locators.rb', line 163 def type string begin driver.keyboard.send_keys string rescue nil end end |