Module: TestCentricity::AppiumConnect

Defined in:
lib/testcentricity/app_core/appium_connect_helper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#config_file ⇒ Object

Returns the value of attribute config_file.



8
9
10
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 8

def config_file
  @config_file
end

#running ⇒ Object

Returns the value of attribute running.



7
8
9
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 7

def running
  @running
end

Class Method Details

.app_installed?(bundle_id) ⇒ Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 83

def self.app_installed?(bundle_id)
  $driver.app_installed?(bundle_id)
end

.available_contexts ⇒ Object



131
132
133
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 131

def self.available_contexts
  $driver.available_contexts
end

.close_app ⇒ Object



91
92
93
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 91

def self.close_app
  $driver.close_app
end

.current_context ⇒ Object



123
124
125
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 123

def self.current_context
  $driver.current_context
end

.default_context ⇒ Object



135
136
137
138
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 135

def self.default_context
  $driver.switch_to_default_context
  puts "Current context = #{$driver.current_context}" if ENV['DEBUG']
end

.driver ⇒ Object



70
71
72
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 70

def self.driver
  $driver
end

.hide_keyboard ⇒ Object



107
108
109
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 107

def self.hide_keyboard
  $driver.hide_keyboard
end

.implicit_wait(timeout) ⇒ Object



103
104
105
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 103

def self.implicit_wait(timeout)
  $driver.manage.timeouts.implicit_wait = timeout
end

.initialize_appium(project_path = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 10

def self.initialize_appium(project_path = nil)
  Environ.platform    = :mobile
  Environ.driver      = :appium
  Environ.device_type = ENV['DEVICE_TYPE'] if ENV['DEVICE_TYPE']
  Environ.device_orientation = ENV['ORIENTATION'] if ENV['ORIENTATION']

  @config_file = project_path

  if project_path.nil?
    browser = ENV['WEB_BROWSER']
    Environ.browser = browser
    case browser.downcase.to_sym
    when :appium
      Environ.device_name = ENV['APP_DEVICE']
      Environ.device_os   = ENV['APP_PLATFORM_NAME']
      ENV['UDID'] ? Environ.device = :device : Environ.device = :simulator
    when :browserstack
      Environ.device_name = ENV['BS_DEVICE']
      Environ.device_os   = ENV['BS_OS']
    end
  end
  @running = false
end

.install_app(app_path) ⇒ Object



79
80
81
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 79

def self.install_app(app_path)
  $driver.install_app(app_path)
end

.is_native_app? ⇒ Boolean

Returns:

  • (Boolean)


144
145
146
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 144

def self.is_native_app?
  $driver.current_context.start_with?('NATIVE_APP')
end

.is_webview? ⇒ Boolean

Returns:

  • (Boolean)


140
141
142
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 140

def self.is_webview?
  $driver.current_context.start_with?('WEBVIEW')
end

.keyboard_shown? ⇒ Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 111

def self.keyboard_shown?
  $driver.is_keyboard_shown
end

.launch_app ⇒ Object



87
88
89
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 87

def self.launch_app
  $driver.launch_app
end

.quit_driver ⇒ Object



63
64
65
66
67
68
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 63

def self.quit_driver
  if @running
    $driver.driver_quit
    @running = false
  end
end

.remove_app(bundle_id) ⇒ Object



99
100
101
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 99

def self.remove_app(bundle_id)
  $driver.remove_app(bundle_id)
end

.reset_app ⇒ Object



95
96
97
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 95

def self.reset_app
  $driver.reset
end

.set_context(context) ⇒ Object



127
128
129
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 127

def self.set_context(context)
  $driver.set_context(context)
end

.set_geolocation(latitude, longitude, altitude) ⇒ Object



119
120
121
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 119

def self.set_geolocation(latitude, longitude, altitude)
  $driver.set_location(latitude, longitude, altitude)
end

.set_orientation(orientation) ⇒ Object



115
116
117
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 115

def self.set_orientation(orientation)
  $driver.rotation = orientation.downcase.to_sym
end

.start_driver ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 34

def self.start_driver
  if @config_file.nil?
    browser = ENV['WEB_BROWSER']
    case browser.downcase.to_sym
    when :appium
      desired_capabilities = appium_local_capabilities
    when :browserstack
      desired_capabilities = browserstack_capabilities
    end
  else
    base_path = 'config'
    unless File.directory?(File.join(@config_file, base_path))
      raise 'Could not find appium.txt files in /config folder'
    end
    appium_caps = File.join(@config_file, base_path, 'appium.txt')
    desired_capabilities = Appium.load_appium_txt file: appium_caps
  end

  puts "Appium desired_capabilities = #{desired_capabilities}" if ENV['DEBUG']

  Appium::Driver.new(desired_capabilities).start_driver
  @running = true
  Appium.promote_appium_methods TestCentricity::ScreenObject
  Appium.promote_appium_methods TestCentricity::ScreenSection
  Appium.promote_appium_methods TestCentricity::AppUIElement

  Environ.screen_size = $driver.window_size
end

.take_screenshot(png_save_path) ⇒ Object



74
75
76
77
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 74

def self.take_screenshot(png_save_path)
  FileUtils.mkdir_p(File.dirname(png_save_path))
  $driver.driver.save_screenshot(png_save_path)
end

.webview_context ⇒ Object



148
149
150
151
152
153
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 148

def self.webview_context
  contexts = available_contexts
  puts "Contexts = #{contexts}" if ENV['DEBUG']
  set_context(contexts.last)
  puts "Current context = #{$driver.current_context}" if ENV['DEBUG']
end