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
107 108 109 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 107 def self.app_installed?(bundle_id) $driver.app_installed?(bundle_id) end |
.available_contexts ⇒ Object
155 156 157 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 155 def self.available_contexts $driver.available_contexts end |
.close_app ⇒ Object
115 116 117 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 115 def self.close_app $driver.close_app end |
.current_context ⇒ Object
147 148 149 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 147 def self.current_context $driver.current_context end |
.default_context ⇒ Object
159 160 161 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 159 def self.default_context $driver.switch_to_default_context end |
.driver ⇒ Object
94 95 96 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 94 def self.driver $driver end |
.hide_keyboard ⇒ Object
131 132 133 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 131 def self.hide_keyboard $driver.hide_keyboard end |
.implicit_wait(timeout) ⇒ Object
127 128 129 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 127 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 |
# 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'] if ENV['UDID'] Environ.device = :device else Environ.device = :simulator end end @running = false end |
.install_app(app_path) ⇒ Object
103 104 105 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 103 def self.install_app(app_path) $driver.install_app(app_path) end |
.is_native_app? ⇒ Boolean
167 168 169 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 167 def self.is_native_app? $driver.current_context.start_with?('NATIVE_APP') end |
.is_webview? ⇒ Boolean
163 164 165 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 163 def self.is_webview? $driver.current_context.start_with?('WEBVIEW') end |
.keyboard_shown? ⇒ Boolean
135 136 137 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 135 def self.keyboard_shown? $driver.is_keyboard_shown end |
.launch_app ⇒ Object
111 112 113 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 111 def self.launch_app $driver.launch_app end |
.quit_driver ⇒ Object
87 88 89 90 91 92 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 87 def self.quit_driver if @running $driver.driver_quit @running = false end end |
.remove_app(bundle_id) ⇒ Object
123 124 125 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 123 def self.remove_app(bundle_id) $driver.remove_app(bundle_id) end |
.reset_app ⇒ Object
119 120 121 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 119 def self.reset_app $driver.reset end |
.set_context(context) ⇒ Object
151 152 153 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 151 def self.set_context(context) $driver.set_context(context) end |
.set_geolocation(latitude, longitude, altitude) ⇒ Object
143 144 145 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 143 def self.set_geolocation(latitude, longitude, altitude) $driver.set_location(latitude, longitude, altitude) end |
.set_orientation(orientation) ⇒ Object
139 140 141 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 139 def self.set_orientation(orientation) $driver.rotation = orientation.downcase.to_sym end |
.start_driver ⇒ Object
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 80 81 82 83 84 85 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 30 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? if Environ.is_device? capabilities[:app] = Environ.current.ios_ipa_path else capabilities[:app] = Environ.current.ios_app_path end 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
98 99 100 101 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 98 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
171 172 173 174 |
# File 'lib/testcentricity/app_core/appium_connect_helper.rb', line 171 def self.webview_context contexts = available_contexts set_context(contexts.last) end |