AzimoLabs / fastlane-plugin-automated-test-emulator-run

Plugin dedicated for Android platform. Wraps gradle task/shell command used for launching instrumented tests. Provides start of as many AVDs with various configs as needed before test run, waits for boot, kills emulators and deletes them from hdd after tests are finished or disturbed.
MIT License
113 stars 48 forks source link

Launch multiple AVD #1

Closed mathroule closed 7 years ago

mathroule commented 7 years ago

Hi and thanks for your great fastlane plugin!

Is it possible to launch multiple AVD using the same command, in order to run spoon tests on a phone and a tablet in parallel?

FisherKK commented 7 years ago

Hello :) I'm glad that you liked it. To be honest I am still changing some stuff in it lately, because I seems to have trouble with it on our Jenkins CI. If you need some feature or something is not working as you'd expect I can try to change it for you :)

We are using spoon too. It was made to work with spoon. Spoon will detect your currently connected devices automatically. If you want to use it with my plugin there are examples:

https://github.com/AzimoLabs/fastlane-plugin-automated-test-emulator-run/blob/master/fastlane/Fastfile

You can run spoon directly or you can run lane of fastlane that is launching spoon for you. Ask anything you want. I will help or give you more examples. Tbh. I am very happy that you have reached to me. I guess I need to update examples on Git repo :) because it has now more possibilities than before.

And in a nutshell, if you have your tablet and smartphone connected - and run spoon via our plugin then you will get your whole test set running in parallel on emulator + 2 devices. Spoon will run it on all of them.

Plugin was designed to run only 1 AVD. Tbh. you can't launch more than 2 android AVD at once because the next ones will freeze on startup.

2016-11-08 19:48 GMT+01:00 Mathieu Rul notifications@github.com:

Hi and thanks for your great fastlane plugin!

Is it possible to launch multiple AVD using the same command, in order to run spoon tests on a phone and a tablet in parallel?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/AzimoLabs/fastlane-plugin-automated-test-emulator-run/issues/1, or mute the thread https://github.com/notifications/unsubscribe-auth/AEJUhzPxtBLIhR-119m2cEJsNbKNv5jeks5q8MPtgaJpZM4Ksxf3 .

mathroule commented 7 years ago

OK. So there is unfortunately no way to launch 2 or more AVD.

FisherKK commented 7 years ago

As long as the plugin use AVD provided by Google I don't think there is a way to launch more than 2. Did you succeed to launching more than two ever? I've made issue/question about it lately and I am waiting for answer.

If you want many emulators you can try Genymotion (you can start 6+, I haven't tried more), but you need license to be able to access/manage them from terminal/console (by shell).

mathroule commented 7 years ago

By using this command i'm able to start 3 AVD on a mac:

echo "no" | $ANDROID_HOME/tools/android create avd --name "Test-Emulator-API23-Nexus-5" --target "Google Inc.:Google APIs:23" --abi google_apis/x86_64  --device "Nexus 5" --skin "1080x1920"
echo "no" | $ANDROID_HOME/tools/android create avd --name "Test-Emulator-API23-Nexus-7" --target "Google Inc.:Google APIs:23" --abi google_apis/x86_64  --device "Nexus 7" --skin "1200x1920"
echo "no" | $ANDROID_HOME/tools/android create avd --name "Test-Emulator-API23-Nexus-10" --target "Google Inc.:Google APIs:23" --abi google_apis/x86_64  --device "Nexus 10" --skin "2560x1600"

$ANDROID_HOME/platform-tools/adb kill-server
$ANDROID_HOME/platform-tools/adb start-server

$ANDROID_HOME/tools/emulator -port 5556 -avd Test-Emulator-API23-Nexus-5  -gpu on &>/dev/null &
$ANDROID_HOME/tools/emulator -port 5558 -avd Test-Emulator-API23-Nexus-7  -gpu on &>/dev/null &
$ANDROID_HOME/tools/emulator -port 5560 -avd Test-Emulator-API23-Nexus-10  -gpu on &>/dev/null &

capture d ecran 2016-11-09 a 14 17 51

FisherKK commented 7 years ago

Hmm, that's pretty amazing.

I haven't tried to do it from terminal. I've created few AVD by AVD Manager in Android Studio and I couldn't launch more than 2 that way. By using your code I managed to launch 4. Thanks I guess!

With that I will for sure try to rewrite whole plugin in near future so it supports more AVDs.

Any suggestions what features would you be interested in?

2016-11-09 14:19 GMT+01:00 Mathieu Rul notifications@github.com:

By using this command i'm able to run start 3 AVD on a mac: ` echo "no" | $ANDROID_HOME/tools/android create avd --name "Test-Emulator-API23-Nexus-5" --target "Google Inc.:Google APIs:23" --abi google_apis/x86_64 --device "Nexus 5" --skin "1080x1920" echo "no" | $ANDROID_HOME/tools/android create avd --name "Test-Emulator-API23-Nexus-7" --target "Google Inc.:Google APIs:23" --abi google_apis/x86_64 --device "Nexus 7" --skin "1200x1920" echo "no" | $ANDROID_HOME/tools/android create avd --name "Test-Emulator-API23-Nexus-10" --target "Google Inc.:Google APIs:23" --abi google_apis/x86_64 --device "Nexus 10" --skin "2560x1600"

$ANDROID_HOME/platform-tools/adb kill-server $ANDROID_HOME/platform-tools/adb start-server

$ANDROID_HOME/tools/emulator -port 5556 -avd Test-Emulator-API23-Nexus-5 -gpu on &>/dev/null & $ANDROID_HOME/tools/emulator -port 5558 -avd Test-Emulator-API23-Nexus-7 -gpu on &>/dev/null & $ANDROID_HOME/tools/emulator -port 5560 -avd Test-Emulator-API23-Nexus-10 -gpu on &>/dev/null & `

[image: capture d ecran 2016-11-09 a 14 17 51] https://cloud.githubusercontent.com/assets/4117425/20139656/75eeb2dc-a687-11e6-973a-450ecfbe657a.png

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/AzimoLabs/fastlane-plugin-automated-test-emulator-run/issues/1#issuecomment-259412562, or mute the thread https://github.com/notifications/unsubscribe-auth/AEJUhxr1EAaC53IL2XKOYu1_82Q8M5aoks5q8chKgaJpZM4Ksxf3 .

mathroule commented 7 years ago

Yes I think it's depend of your computer performance.

It would be awesome to have something like that in order to execute spoon test on several AVD and then take screenshots using Screengrab on the same AVD. And of course close the AVD when the lane is done.

For instance:

lane :instrumentationTest do
    automated_test_emulator_run(
        avd_name: 'Test-Emulator-API23-Nexus-5',
        target_id: 'Google Inc.:Google APIs:23',
        avd_create_options: '--device "Nexus 5" --skin "1080x1920"',
        avd_abi: 'google_apis/x86_64',
        avd_start_options: '-gpu on'
    )
    automated_test_emulator_run(
        avd_name: 'Test-Emulator-API23-Nexus-7',
        target_id: 'Google Inc.:Google APIs:23',
        avd_create_options: '--device "Nexus 7" --skin "1200x1920"',
        avd_abi: 'google_apis/x86_64',
        avd_start_options: '-gpu on',
        gradle_task: 'spoonProdReleaseInstrumentationAndroidTest'
    )
    automated_test_emulator_run(
        avd_name: 'Test-Emulator-API23-Nexus-10',
        target_id: 'Google Inc.:Google APIs:23',
        avd_create_options: '--device "Nexus 10" --skin "2560x1600"',
        avd_abi: 'google_apis/x86_64',
        avd_start_options: '-gpu on',
        gradle_task: 'spoonProdReleaseInstrumentationAndroidTest'
    )
    gradle(task: 'spoon')
    screengrab
)
mathroule commented 7 years ago

Also, it's not really easy to create AVD using custom hardware. Indeed by default when creating a Nexus 5 using CLI, I can't define VM heap size, which is 16 Mb by default and obviously not enough to run my tests. But I think it's more an AVD CLI related issue.

FisherKK commented 7 years ago

I see. I will take it into consideration. I have some ideas how it might work. I think the biggest issue for now would be:

How to parametrize number of AVD that should be launched and be able to set different settings to each of them at the same time. I mean it would be easy to start 4 the same AVDs - but hard to set e.g. AVD_num=5 and access parameters of each created that way AVD separately.

Hardcoding AVD_num doesn't seem good option to me as you might need more of them in the future or someone has weaker hardware and can run only 3 for example. From the other side creating AVD_num of the same AVDs is not solving all problems as you might need to test different screen sizes and API versions.

What do you think about changing plugin so it takes only 4 parameters: a) AVD_config_file - that would be your own setup of AVD you want to create/run written in e.g txt file. Plugin would read that file and parse it. I could create example file and you could modify it. That way if you put only 1 AVD in that config file - plugin would start only 1 AVD, but there wouldn't be problem to launch 4 or 5 that way - and each of them could have different settings separately. b) shell_cmd -> your test launch command from shell (optional) c) gradle_cmd -> your test launch command as gradle task (optional) d) sdk location

How does it sound to you?

Additionally about VM heap problem. We are having it too. They way we are handling it is that we have tests divided into packages. And we have fastlane task for each package that launches it. So all we need to do is to create something like:

 lane :Automation_Bdd_EndToEnd_CompleteTestSuite do |config|
     Automation_Bdd_EndToEnd_CardsManagement config
     Automation_Bdd_EndToEnd_ExistingUserFlow config
     Automation_Bdd_EndToEnd_FacebookMessenger config
     Automation_Bdd_EndToEnd_Login config
     Automation_Bdd_EndToEnd_NewUserFlow config
     Automation_Bdd_EndToEnd_PasswordChange config
     Automation_Bdd_EndToEnd_PromoCodes config
     Automation_Bdd_EndToEnd_Recipient config
     Automation_Bdd_EndToEnd_Referral config
     Automation_Bdd_EndToEnd_Register config
     Automation_Bdd_EndToEnd_ScreenLock config
     Automation_Bdd_EndToEnd_TransferStatuses config
     Automation_Bdd_EndToEnd_UpdateUserProfile config
  end

That way before each package we kill, recreate and launch new emulator. So the heap is cleaned. Of course we use spoon so the project is built from scratch over and over and you lose some time on it - but at least you are able to launch all of your tests.

mathroule commented 7 years ago

Indeed it could be a solution to have a config file with AVD configuration and limited for 4 or 5 device maximum. But the feature to have all the configuration in one Fastfile is lost.

By the way, the ability to create AVD from CLI is sadly no longer supported, see: https://developer.android.com/studio/tools/help/android.html

So maybe a solution, will be to create AVD using Android Studio (easily fit configuration need), and then start it using CLI via your plugin (with a wipe-data). But the lane portability will be unfortunately lost because AVD should be manualy created on Fastlane platform (i.e. for CI platform).

With your solution to run each test package in a different spoon job, how do you generate a global spoon test reports? Each time a package is tested, the report is overwrited.

Furthermore, I wasn't be able to start spoon using the Gradle plugin for a spesific package, only for a specific class.

mathroule commented 7 years ago

I've added two new options to specify an hardware configuration file for the AVD and the AVD root path. Now I could perfectly configure my AVD with correct heap size for instance.

The PR is coming.

FisherKK commented 7 years ago

Hello. Sorry for not responding for last 6 days. I have seen your pull request but I am currently working on new plugin and it's done in 70%. It will be totally different.

I came across weird problem and I wanted to ask you if you could check something. Indeed I was able to start more than 2 AVD with code you gave me:

$ANDROID_HOME/tools/emulator -port 5556 -avd Test-Emulator-API23-Nexus-5  -gpu on &>/dev/null &
$ANDROID_HOME/tools/emulator -port 5558 -avd Test-Emulator-API23-Nexus-7  -gpu on &>/dev/null &
$ANDROID_HOME/tools/emulator -port 5560 -avd Test-Emulator-API23-Nexus-10  -gpu on &>/dev/null &

But weird thing is:

a) It works if I copy paste all 3 launching commands at once to terminal. AVDs starts to launch at the same time and successfully boot.

b) It doesn't work if I try to launch AVDs sequentially. So I start 1st one and wait until it boots. Then I start 2nd one - it also boots. Third one will freeze with black screen on startup.

Any idea what might causing a problem?

mathroule commented 7 years ago

Hi. Indeed I've got this strange behavior too. It seems the memory limit is reached and the emulator never start. I think the memory limit verification appears after startup when launched simultaneously.

Second emulator launch

Hax is enabled
Hax ram_size 0x40000000
HAX is working and emulator runs in fast virt mode.
coreaudio: Could not initialize input - Unknown Audiodevice
coreaudio: Could not initialize input - Unknown Audiodevice
audio: Failed to create voice `goldfish_audio_in'
qemu-system-x86_64: warning: opening audio input failed
emulator: Listening for console connections on port: 5558
emulator: Serial number of this emulator (for ADB): emulator-5558

Third emulator launch

Hax is enabled
Hax ram_size 0x40000000
**The memory needed by this VM exceeds the driver limit.**
HAX is not working and emulator runs in emulation mode.
coreaudio: Could not initialize input - Unknown Audiodevice
coreaudio: Could not initialize input - Unknown Audiodevice
audio: Failed to create voice `goldfish_audio_in'
qemu-system-x86_64: warning: opening audio input failed
emulator: Listening for console connections on port: 5560
emulator: Serial number of this emulator (for ADB): emulator-5560

Actually, HAXM was allowed to use 2Go of RAM. After a a reinstallation of HAXM using 6Go of available RAM, I was able to launch correctly the 3 emulators sequentially. Indeed the Nexus 5 use 1024 Mb of RAM, and 1536 Mb for the Nexus 7 and 10. If you want more AVD, just increase the available RAM for HAXM. Of course don't exceed the memory available on your system ;)

FisherKK commented 7 years ago

Thanks. Communication with you gave me push in this matter and helped a lot.

I have currently running, new version of plugin that is starting amount of AVDs described in *.json file. Currently 4 of them and it works fine :) It is usable yet I didn't push new gem as I need to implement 2 things more:

Anyway, plugin is done in 90%

Could you please give me more hint about how can I reinstall HAXM to increase RAM allowance? I got similar response on Google Issue in this matter. I was about to investigate that soon cuz I have never tried it.

mathroule commented 7 years ago

Which OS are you running ?

FisherKK commented 7 years ago

OS X Yosemite 10.10.5 (14F27) at the moment

mathroule commented 7 years ago

On mac OS Sierra I've used installation package available here: https://software.intel.com/en-us/android/articles/intel-hardware-accelerated-execution-manager

Direct DL link: https://software.intel.com/sites/default/files/managed/38/16/haxm-macosx_v6_0_3.zip

FisherKK commented 7 years ago

Thanks I will give it a look :)

FisherKK commented 7 years ago

Works like a charm. Thanks again.

FisherKK commented 7 years ago

I am short on time lately but I've tried to provide some examples/explanations in readme.md. New plugin is available. Check it out. Give some feedback if something is a bit too complicated and if it works :)

mathroule commented 7 years ago

Great works! I will soon have a look to the new plugin.

mathroule commented 7 years ago

The new plugin works like a charm. Thanks!