Class: Fastlane::Actions::AppiumAction
- Inherits:
-
Fastlane::Action
- Object
- Fastlane::Action
- Fastlane::Actions::AppiumAction
- Defined in:
- lib/fastlane/actions/appium.rb
Constant Summary collapse
- INVOKE_TIMEOUT =
30
- APPIUM_PATH_HOMEBREW =
'/usr/local/bin/appium'
- APPIUM_APP_PATH =
'/Applications/Appium.app'
- APPIUM_APP_BUNDLE_PATH =
'Contents/Resources/node_modules/.bin/appium'
Constants inherited from Fastlane::Action
Fastlane::Action::AVAILABLE_CATEGORIES
Class Method Summary collapse
- .author ⇒ Object
- .available_options ⇒ Object
- .category ⇒ Object
- .configure_rspec(params) ⇒ Object
- .description ⇒ Object
- .detect_appium(params) ⇒ Object
- .example_code ⇒ Object
- .invoke_appium_server(params) ⇒ Object
- .is_supported?(platform) ⇒ Boolean
- .run(params) ⇒ Object
- .wait_for_appium_server(params) ⇒ Object
Methods inherited from Fastlane::Action
action_name, authors, details, lane_context, method_missing, other_action, output, return_value, sample_return_value, sh, step_text
Class Method Details
.author ⇒ Object
166 167 168 |
# File 'lib/fastlane/actions/appium.rb', line 166 def self. 'yonekawa' end |
.available_options ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/fastlane/actions/appium.rb', line 105 def self. [ FastlaneCore::ConfigItem.new( key: :platform, env_name: 'FL_APPIUM_PLATFORM', description: 'Appium platform name', is_string: true ), FastlaneCore::ConfigItem.new( key: :spec_path, env_name: 'FL_APPIUM_SPEC_PATH', description: 'Path to Appium spec directory', is_string: true ), FastlaneCore::ConfigItem.new( key: :app_path, env_name: 'FL_APPIUM_APP_FILE_PATH', description: 'Path to Appium target app file', is_string: true ), FastlaneCore::ConfigItem.new( key: :invoke_appium_server, env_name: 'FL_APPIUM_INVOKE_APPIUM_SERVER', description: 'Use local Appium server with invoke automatically', is_string: false, default_value: true, optional: true ), FastlaneCore::ConfigItem.new( key: :host, env_name: 'FL_APPIUM_HOST', description: 'Hostname of Appium server', is_string: true, default_value: '0.0.0.0', optional: true ), FastlaneCore::ConfigItem.new( key: :port, env_name: 'FL_APPIUM_PORT', description: 'HTTP port of Appium server', is_string: false, default_value: 4723, optional: true ), FastlaneCore::ConfigItem.new( key: :appium_path, env_name: 'FL_APPIUM_EXECUTABLE_PATH', description: 'Path to Appium executable', is_string: true, optional: true ), FastlaneCore::ConfigItem.new( key: :caps, env_name: 'FL_APPIUM_CAPS', description: 'Hash of caps for Appium::Driver', is_string: false, optional: true ) ] end |
.category ⇒ Object
174 175 176 |
# File 'lib/fastlane/actions/appium.rb', line 174 def self.category :testing end |
.configure_rspec(params) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/fastlane/actions/appium.rb', line 79 def self.configure_rspec(params) RSpec.configure do |c| c.before(:each) do caps = params[:caps] || {} caps[:platformName] ||= params[:platform] caps[:autoAcceptAlerts] ||= true caps[:app] = params[:app_path] @driver = Appium::Driver.new( caps: caps, server_url: params[:host], port: params[:port] ).start_driver Appium.promote_appium_methods(RSpec::Core::ExampleGroup) end c.after(:each) do @driver.quit unless @driver.nil? end end end |
.description ⇒ Object
101 102 103 |
# File 'lib/fastlane/actions/appium.rb', line 101 def self.description 'Run UI test by Appium with RSpec' end |
.detect_appium(params) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/fastlane/actions/appium.rb', line 45 def self.detect_appium(params) appium_path = params[:appium_path] || `which appium`.to_s.strip if appium_path.empty? if File.exist?(APPIUM_PATH_HOMEBREW) appium_path = APPIUM_PATH_HOMEBREW elsif File.exist?(APPIUM_APP_PATH) appium_path = APPIUM_APP_PATH end end unless File.exist?(appium_path) UI.user_error!("You have to install Appium using `npm install -g appium`") end if appium_path.end_with?('.app') appium_path = "#{appium_path}/#{APPIUM_APP_BUNDLE_PATH}" end UI.("Appium executable detected: #{appium_path}") appium_path end |
.example_code ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/fastlane/actions/appium.rb', line 178 def self.example_code [ 'appium( app_path: "appium/apps/TargetApp.app", spec_path: "appium/spec", platform: "iOS", caps: { versionNumber: "9.1", deviceName: "iPhone 6" } )' ] end |
.invoke_appium_server(params) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/fastlane/actions/appium.rb', line 38 def self.invoke_appium_server(params) appium = detect_appium(params) fork do Process.exec("#{appium} -a #{params[:host]} -p #{params[:port]}") end end |
.is_supported?(platform) ⇒ Boolean
170 171 172 |
# File 'lib/fastlane/actions/appium.rb', line 170 def self.is_supported?(platform) platform == :ios end |
.run(params) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fastlane/actions/appium.rb', line 9 def self.run(params) Actions.verify_gem!('rspec') Actions.verify_gem!('appium_lib') require 'rspec' require 'appium_lib' unless Helper.test? FastlaneCore::PrintTable.print_values( config: params, title: "Summary for Appium Action" ) if params[:invoke_appium_server] appium_pid = invoke_appium_server(params) wait_for_appium_server(params) end configure_rspec(params) rspec_args = [] rspec_args << params[:spec_path] status = RSpec::Core::Runner.run(rspec_args).to_i if status != 0 UI.user_error!("Failed to run Appium spec. status code: #{status}") end ensure Actions.sh "kill #{appium_pid}" if appium_pid end |
.wait_for_appium_server(params) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/fastlane/actions/appium.rb', line 68 def self.wait_for_appium_server(params) loop.with_index do |_, count| break if `lsof -i:#{params[:port]}`.to_s.length != 0 if count * 5 > INVOKE_TIMEOUT UI.user_error!("Invoke Appium server timed out") end sleep 5 end end |