Module: Platform::Android::Emulator
Instance Method Summary collapse
- #cleanup_after_emulator ⇒ Object
- #emulator_running? ⇒ Boolean
- #retry_again ⇒ Object
- #setup_for_android_sauce(settings) ⇒ Object
- #start_emulator(settings = nil) ⇒ Object
- #terminate_emulator ⇒ Object
-
#wait_for_emulator ⇒ Object
Wait until emulator is online.
Methods included from OS
Instance Method Details
#cleanup_after_emulator ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# 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? ⇒ Boolean
100 101 102 103 104 105 106 107 108 109 110 111 |
# 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 ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# 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) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# 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) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# 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 ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# 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 ⇒ Object
Wait until emulator is online
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# 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 |