Class: AppPrism::Platforms::AppiumPlatform

Inherits:
Platform
  • Object
show all
Defined in:
lib/app_prism/platforms/appium_platform.rb

Instance Attribute Summary

Attributes inherited from Platform

#driver

Instance Method Summary collapse

Methods inherited from Platform

#initialize

Constructor Details

This class inherits a constructor from AppPrism::Platforms::Platform

Instance Method Details

#app_packageObject



85
86
87
# File 'lib/app_prism/platforms/appium_platform.rb', line 85

def app_package
  @driver.caps[:appPackage]
end

#find_element(identifiers) ⇒ Object



7
8
9
10
11
# File 'lib/app_prism/platforms/appium_platform.rb', line 7

def find_element(identifiers)
  @driver.find_element(identifiers)
rescue Selenium::WebDriver::Error::NoSuchElementError
  raise "Cannot find such element: #{identifiers}"
end

#find_elements(identifiers) ⇒ Object



26
27
28
# File 'lib/app_prism/platforms/appium_platform.rb', line 26

def find_elements(identifiers)
  @driver.find_elements(identifiers)
end

#hide_keyboardObject



65
66
67
68
69
70
71
# File 'lib/app_prism/platforms/appium_platform.rb', line 65

def hide_keyboard
  tries ||= 3
  sleep 1
  @driver.hide_keyboard
rescue Selenium::WebDriver::Error::UnknownError
  retry unless (tries -= 1).zero?
end

#native_context?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/app_prism/platforms/appium_platform.rb', line 81

def native_context?
  @driver.current_context == 'NATIVE_APP'
end

#refreshObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/app_prism/platforms/appium_platform.rb', line 13

def refresh
  start_x = screen_width/2
  start_y = screen_height/2
  end_y = start_y * 1.7

  end_x = start_x
  @driver.swipe(start_x: start_x,
                start_y: start_y,
                end_x: end_x,
                end_y: end_y,
                duration: 1000)
end

#screen_heightObject



34
35
36
# File 'lib/app_prism/platforms/appium_platform.rb', line 34

def screen_height
  @driver.window_size.height
end

#screen_widthObject



30
31
32
# File 'lib/app_prism/platforms/appium_platform.rb', line 30

def screen_width
  @driver.window_size.width
end

#set_native_contextObject



73
74
75
# File 'lib/app_prism/platforms/appium_platform.rb', line 73

def set_native_context
  @driver.set_context('NATIVE_APP')
end

#set_web_contextObject



77
78
79
# File 'lib/app_prism/platforms/appium_platform.rb', line 77

def set_web_context
  @driver.set_context("WEBVIEW_#{app_package}")
end

#swipe_down(element) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/app_prism/platforms/appium_platform.rb', line 51

def swipe_down(element)
  location = element.location
  start_x = location.x + element.size.width/2
  start_y = location.y + element.size.height * 0.05
  end_y = location.y + element.size.height * 0.95

  end_x = start_x
  @driver.swipe(start_x: start_x,
                start_y: start_y,
                end_x: end_x,
                end_y: end_y,
                duration: 3000)
end

#swipe_up(element) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/app_prism/platforms/appium_platform.rb', line 38

def swipe_up(element)
  start_x = element.location.x + element.size.width/2
  start_y = element.location.y + element.size.height * 0.95
  end_y = element.location.y * 1.05

  end_x = start_x
  @driver.swipe(start_x: start_x,
                start_y: start_y,
                end_x: end_x,
                end_y: end_y,
                duration: 3000)
end