Ubuntu 16.04 does not have a video device, cannot run UI tests

From @bisonhubert on Thu Dec 08 2016 14:46:34 GMT-0500 (EST)

## Description of the issue

I am trying to run UI tests on an Android emulator, but because the Ubuntu stack does not have a visual device installed, the UI tests cannot locate different elements to interact with.

Environment:

Ubuntu 16.04 stack
React Native 0.38.0
Appium 16.0
WD 1.0
Mocha 2.5.3

Potential Workarounds

I’m currently trying to install a video device that will allow the emulator to run with a window. If you have an idea for a workaround I would be open to it as I’m not sure this is necessarily an issue, but it’s definitely blocking my ability to run UI tests as a workflow step.

Copied from original issue: https://github.com/bitrise-io/build.issues/issues/27

From @viktorbenei on Fri Dec 09 2016 06:25:28 GMT-0500 (EST)

How do you create & boot the android emulator?
Do you use our Create Android emulator and Start Android emulator steps?

From @bisonhubert on Fri Dec 09 2016 13:24:27 GMT-0500 (EST)

Hi @viktorbenei, I do use the built-in steps. I’ve also experimented with creating my own using a script.

Here are the details for the create-android-emulator step:

  • version 1.0.0
  • step does not run if previous step fails
  • name: test
  • target: android-24
  • options for ‘android create avd’: default
  • custom hardware profile content: default

And for the start-android-emulator step:

  • version 1.1.0
  • emulator to boot: $BITRISE_EMULATOR_NAME
  • skin: 768x1280
  • command’s flags -no-boot-anim -no-audio -no-window
  • sdk path: $ANDROID_HOME

I realize that starting the emulator with -no-window is probably why the UI tests aren’t able to locate page objects (no window, no UI), but when I remove that flag, the “start-android-emulator@1.1.0” step hangs for 13 minutes and eventually fails, so the appium driver isn’t able to locate a connected device. The step hangs on the message SDL init failure, reason is: No available video device.

I’ve also tried installing a video device with echo y | apt-get install ia32-libs-sdl but this returns the same string as above.

From @viktorbenei on Fri Dec 09 2016 13:26:51 GMT-0500 (EST)

Thanks for the infos @bisonhubert !

The emulator should be able to boot without the -no-window flag - we’ll try to check this ASAP and let you know if we can find anything!

From @bisonhubert on Tue Dec 13 2016 15:28:34 GMT-0500 (EST)

Hi @viktorbenei @godrei,

Were either of you able to replicate the issue I’m having getting the Android emulator to run without the -no-window flag?

From @viktorbenei on Tue Dec 13 2016 15:38:03 GMT-0500 (EST)

Sorry, we were a bit tight on schedule due to the new CLI release, but it’s scheduled as the first task for tomorrow!

From @godrei on Thu Dec 15 2016 11:07:33 GMT-0500 (EST)

Hi @bisonhubert ,

i validated, that on linux stacks, we can not run emulator without the -no-window flag. It may happens because of the linux vms are prepared with server version of ubuntu, which does not contains desktop, so there are no windows…

Alternatively you can run your android builds on xamarin stacks (they contains tools, for both ios and android development), this stacks are prepared with osx.

Somehow i was not able to run emulator with android-24 platform, (android-23 was removed by google), but android-22 emulator starts correctly on xamarin stack.

We are working on to provide solution to run emulator on linux stack and figure out, what is the problem with android-24 + -no-window on xamarin stack.

From @bisonhubert on Thu Dec 15 2016 18:27:41 GMT-0500 (EST)

Hi @godrei

Thank you for getting back to me. I will be sure to try the Xamarin stacks to see if I can get the UI tests to run.

From @viktorbenei on Mon Dec 19 2016 09:58:08 GMT-0500 (EST)

@bisonhubert we found another possible workaround, although we’re still validating this:

Install the libqt5widgets5 package (e.g. with a Script step: sudo apt-get install -y libqt5widgets5), before the first Emulator step, and also set the QT_QPA_PLATFORM environment variable to offscreen (you can set this as an App Env Var).

With this config we could successfully boot an android-21 emulator without the -no-window flag, although there are a couple of warnings which could probably be fixed with other configs / packages (we’re still investigating).

If you have the time @bisonhubert it’d help a lot if you could test this with your project.

From @viktorbenei on Mon Dec 19 2016 09:58:28 GMT-0500 (EST)

On the Android/Ubuntu stack of course, not on the Xamarin stack

From @viktorbenei on Tue Dec 20 2016 03:30:51 GMT-0500 (EST)

The libqt5widgets5 package is now preinstalled on the Android/Ubuntu 16 stack, so only the environment variable have to be set. Once we confirm that this works properly in every case (including the window mode) we’ll add the env var to the standard config/image too.

Please let us know @bisonhubert if you can validate it with your project!

From @bisonhubert on Tue Dec 20 2016 17:20:18 GMT-0500 (EST)

Hi @viktorbenei,

Thank you for the updates. Starting an Android emulator with the no-window flag no longer hangs the build, and my first test is passing (!!!)

To set the QT_QPA_PLATFORM environment variable within a script step, I had to set the key and value explicitly, as listed in the first example of the Expose an Environment Variable section of your documentation. Working with the pipe operator in the second example caused the start-emulator step to hang with the following error:

Starting emulator
/opt/android-sdk-linux/tools/emulator64-arm -avd test -skin 768x1280 -no-boot-anim -no-audio
emulator: WARNING: Classic qemu does not support SMP. The hw.cpu.ncore option from your config file is ignored.
This application failed to start because it could not find or load the Qt platform plugin "offscreen".

Available platform plugins are: linuxfb, minimal, offscreen, xcb.

Reinstalling the application may fix this problem.

I will be working now to optimize the speed of the testing workflow step, as the ARM abis are notoriously slow. Thank you for all your help.

From @viktorbenei on Wed Dec 21 2016 05:43:40 GMT-0500 (EST)

@bisonhubert thanks for the info!

We tested a couple of things and decided to set these environment variables by default, so, ideally, after this weekend’s stack update you won’t need to define anything, the emulator steps should “just work”, with or without the -no-window flag.

Related PR: https://github.com/bitrise-docker/android/pull/49/files