Module: TestCentricity::AppiumConnect
- Defined in:
- lib/testcentricity/app_core/appium_connect_helper.rb
Instance Attribute Summary collapse
-
#config_file ⇒ Object
Returns the value of attribute config_file.
-
#running ⇒ Object
Returns the value of attribute running.
Class Method Summary collapse
- .app_installed?(bundle_id) ⇒ Boolean
- .available_contexts ⇒ Object
- .close_app ⇒ Object
- .current_context ⇒ Object
- .default_context ⇒ Object
- .driver ⇒ Object
- .hide_keyboard ⇒ Object
- .implicit_wait(timeout) ⇒ Object
- .initialize_appium(project_path = nil) ⇒ Object
- .install_app(app_path) ⇒ Object
- .is_native_app? ⇒ Boolean
- .is_webview? ⇒ Boolean
- .keyboard_shown? ⇒ Boolean
- .launch_app ⇒ Object
- .quit_driver ⇒ Object
- .remove_app(bundle_id) ⇒ Object
- .reset_app ⇒ Object
- .set_context(context) ⇒ Object
- .set_geolocation(latitude, longitude, altitude) ⇒ Object
- .set_orientation(orientation) ⇒ Object
- .start_driver ⇒ Object
- .take_screenshot(png_save_path) ⇒ Object
- .webview_context ⇒ Object
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
101 102 103 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 101 def self.app_installed?(bundle_id) $driver.app_installed?(bundle_id) end |
.available_contexts ⇒ Object
149 150 151 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 149 def self.available_contexts $driver.available_contexts end |
.close_app ⇒ Object
109 110 111 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 109 def self.close_app $driver.close_app end |
.current_context ⇒ Object
141 142 143 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 141 def self.current_context $driver.current_context end |
.default_context ⇒ Object
153 154 155 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 153 def self.default_context $driver.switch_to_default_context end |
.driver ⇒ Object
88 89 90 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 88 def self.driver $driver end |
.hide_keyboard ⇒ Object
125 126 127 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 125 def self.hide_keyboard $driver.hide_keyboard end |
.implicit_wait(timeout) ⇒ Object
121 122 123 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 121 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 |
# 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'] @config_file = project_path if project_path.nil? Environ.device_name = ENV['APP_DEVICE'] Environ.device_os = ENV['APP_PLATFORM_NAME'] Environ.device_orientation = ENV['ORIENTATION'] if ENV['ORIENTATION'] ENV['UDID'] ? Environ.device = :device : Environ.device = :simulator end @running = false end |
.install_app(app_path) ⇒ Object
97 98 99 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 97 def self.install_app(app_path) $driver.install_app(app_path) end |
.is_native_app? ⇒ Boolean
161 162 163 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 161 def self.is_native_app? $driver.current_context.start_with?('NATIVE_APP') end |
.is_webview? ⇒ Boolean
157 158 159 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 157 def self.is_webview? $driver.current_context.start_with?('WEBVIEW') end |
.keyboard_shown? ⇒ Boolean
129 130 131 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 129 def self.keyboard_shown? $driver.is_keyboard_shown end |
.launch_app ⇒ Object
105 106 107 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 105 def self.launch_app $driver.launch_app end |
.quit_driver ⇒ Object
81 82 83 84 85 86 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 81 def self.quit_driver if @running $driver.driver_quit @running = false end end |
.remove_app(bundle_id) ⇒ Object
117 118 119 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 117 def self.remove_app(bundle_id) $driver.remove_app(bundle_id) end |
.reset_app ⇒ Object
113 114 115 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 113 def self.reset_app $driver.reset end |
.set_context(context) ⇒ Object
145 146 147 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 145 def self.set_context(context) $driver.set_context(context) end |
.set_geolocation(latitude, longitude, altitude) ⇒ Object
137 138 139 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 137 def self.set_geolocation(latitude, longitude, altitude) $driver.set_location(latitude, longitude, altitude) end |
.set_orientation(orientation) ⇒ Object
133 134 135 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 133 def self.set_orientation(orientation) $driver.rotation = orientation.downcase.to_sym end |
.start_driver ⇒ Object
26 27 28 29 30 31 32 33 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 26 def self.start_driver if @config_file.nil? desired_capabilities = { caps: { platformName: ENV['APP_PLATFORM_NAME'], platformVersion: ENV['APP_VERSION'], deviceName: ENV['APP_DEVICE'], automationName: ENV['AUTOMATION_ENGINE'] } } capabilities = desired_capabilities[:caps] capabilities[:avd] = ENV['APP_DEVICE'] if ENV['APP_PLATFORM_NAME'].downcase.to_sym == :android capabilities[:orientation] = ENV['ORIENTATION'].upcase if ENV['ORIENTATION'] capabilities[:language] = ENV['LANGUAGE'] if ENV['LANGUAGE'] capabilities[:locale] = ENV['LOCALE'].gsub('-', '_') if ENV['LOCALE'] capabilities[:newCommandTimeout] = ENV['NEW_COMMAND_TIMEOUT'] if ENV['NEW_COMMAND_TIMEOUT'] capabilities[:noReset] = ENV['APP_NO_RESET'] if ENV['APP_NO_RESET'] capabilities[:fullReset] = ENV['APP_FULL_RESET'] if ENV['APP_FULL_RESET'] if ENV['UDID'] capabilities[:udid] = ENV['UDID'] capabilities[:bundleId] = ENV['BUNDLE_ID'] if ENV['BUNDLE_ID'] capabilities[:xcodeOrgId] = ENV['TEAM_ID'] if ENV['TEAM_ID'] capabilities[:xcodeSigningId] = ENV['TEAM_NAME'] if ENV['TEAM_NAME'] capabilities[:appActivity] = ENV['APP_ACTIVITY'] if ENV['APP_ACTIVITY'] capabilities[:appPackage] = ENV['APP_PACKAGE'] if ENV['APP_PACKAGE'] end if ENV['APP'] capabilities[:app] = ENV['APP'] else if Environ.is_android? capabilities[:app] = Environ.current.android_apk_path elsif Environ.is_ios? Environ.is_device? ? capabilities[:app] = Environ.current.ios_ipa_path : capabilities[:app] = Environ.current.ios_app_path end 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 Appium::Driver.new(desired_capabilities).start_driver @running = true Appium.promote_appium_methods TestCentricity::ScreenObject Appium.promote_appium_methods TestCentricity::AppUIElement Environ.screen_size = $driver.window_size end |
.take_screenshot(png_save_path) ⇒ Object
92 93 94 95 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 92 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
165 166 167 168 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 165 def self.webview_context contexts = available_contexts set_context(contexts.last) end |