module Platform::Android::Emulator
Public Instance Methods
cleanup_after_emulator()
click to toggle source
# File lib/mobmanager/mobile/platform/android/emulator.rb, line 83 def cleanup_after_emulator if mac? #remove /private/temp/android-<username> path = '/private/tmp' files = Dir["#{path}/**"] files.each do |file| if File.directory(file) FileUtils.remove_dir(file) if ((file.include? 'android-')) end end else # Delete temp files from AppData/Local/Temp/AndroidEmulator user_profile = %x[echo %USERPROFILE%].to_s.chomp! Dir.glob(user_profile.gsub("\\", '/')+ '//AppData//Local//Temp//AndroidEmulator//*.tmp').each { |f| File.delete(f) } end end
emulator_running?()
click to toggle source
# File lib/mobmanager/mobile/platform/android/emulator.rb, line 100 def emulator_running? if mac? if %x[ps aux | grep -i emulator | grep -v grep | wc -l].to_i > 0 return true end else if %x[tasklist /FI "IMAGENAME eq emulator-x86.exe"].to_s.include? 'emulator' return true end end false end
retry_again()
click to toggle source
# File lib/mobmanager/mobile/platform/android/emulator.rb, line 57 def retry_again puts 'Something went wrong while getting the AVD. Retrying now...' delete_locked_files terminate_emulator system 'adb kill-server' system 'adb start-server' start_emulator online = wait_for_emulator unless online fail 'Something went wrong while getting the AVD. Verify the selected AVD exists.' end end
setup_for_android_sauce(settings)
click to toggle source
# File lib/mobmanager/mobile/platform/android/emulator.rb, line 23 def setup_for_android_sauce(settings) sauce_user = %x[echo $SAUCE_USER].strip sauce_key = %x[echo $SAUCE_KEY].strip app_path = settings[:apk_path] app = app_path.split('/').select{|item| item.include?('.apk')}.first puts 'MobTest: Connecting to sauce server...' system "curl https://#{sauce_user}:#{sauce_key}@saucelabs.com/rest/v1/users/#{sauce_user}" puts 'MobTest: Sending apk to sauce storage' system 'curl -u '+"#{sauce_user}:#{sauce_key}"+' -X POST "https://saucelabs.com/rest/v1/storage/'+sauce_user+'/'+app+'?overwrite=true" -H "Content-Type: application/octet-stream" --data-binary @'+app_path end
start_emulator(settings = nil)
click to toggle source
# File lib/mobmanager/mobile/platform/android/emulator.rb, line 13 def start_emulator(settings = nil) if ENV['TARGET'] == 'sauce' caps = settings unless settings.nil? caps = YAML.load_file(Dir.pwd + '/features/support/settings/android.yml') if settings.nil? setup_for_android_sauce caps else spawn "emulator -avd #{ANDROID_EMULATOR} -no-audio" end end
terminate_emulator()
click to toggle source
# File lib/mobmanager/mobile/platform/android/emulator.rb, line 70 def terminate_emulator if emulator_running? puts 'Terminating Android emulator...' if mac? termination = system 'pkill -9 emulator' else termination = system 'TASKKILL /F /IM emulator-x86.exe' cleanup_after_emulator end print_termination_response(termination) end end
wait_for_emulator()
click to toggle source
Wait until emulator is online
# File lib/mobmanager/mobile/platform/android/emulator.rb, line 36 def wait_for_emulator online = false iterations = 0 while online == false && iterations < OFFLINE_CHECKS iterations += 1 sleep 3 puts 'Emulator is offline...' list_of_devices = %x[adb devices].to_s if list_of_devices.include? 'emulator' if list_of_devices.include? 'offline' online = false else puts "Emulator is online...\n\n" online = true end end end online end
Private Instance Methods
delete_locked_files()
click to toggle source
# File lib/mobmanager/mobile/platform/android/emulator.rb, line 124 def delete_locked_files # Delete lock files from ./.android/avd path = "#{Dir.home}/.android/avd" locks = Dir["#{path}/**/*.lock"] locks.each do |file| File.delete(file) end end
print_termination_response(success)
click to toggle source
# File lib/mobmanager/mobile/platform/android/emulator.rb, line 114 def print_termination_response(success) if success puts 'Android emulator terminated successfully.' elsif !success puts 'Android emulator was not found.' else warn '[PANIC]: Something went wrong while terminating the Android emulator.' end end