Preface from the post :
Selenoid is a program that allows you to control browsers and Android emulators using special drivers. Able to run each of them in isolation in the Docker container.
The main idea of Selenoid is to launch a new container for each session (launch a new browser or emulator) and stop it immediately after closing the session.
Selenoid allows you to maintain a high load without additional resource costs.
This post will run simple tests in an Android emulator .
Training
Check first that your system can run virtual machines.
Hardware virtualization must be supported by your processor. This means that IntelVT or AMDV processor extensions are required. To verify that the processor supports one of these, run the command:
egrep '(vmx|svm)' /proc/cpuinfo
Docker
Docker must be installed and running on your operating system.
Install Selenoid
If you have a Redhat-based operating system, you can use my repository to install the Configuration manager .
yum -y install yum-plugin-copr yum copr enable antonpatsev/aerokube-cm-rpm yum -y install aerokube-cm
If you do not have a Redhat-based operating system, then you can download and use the Configuration manager binary.
Running Selenoid using the Configuration manager and building browsers.json
If you do not have direct access to the Internet and docker images you download through the registry:
aerokube-cm selenoid start --force --browsers "android:6.0;chrome:78" --args "-session-attempt-timeout 2m -service-startup-timeout 2m" --registry -docker-registry
If you have direct access to the Internet.
aerokube-cm selenoid start --force --browsers "android:6.0;chrome:78" --args "-session-attempt-timeout 2m -service-startup-timeout 2m"
The key --args "-session-attempt-timeout 2m -service-startup-timeout 2m"
needed if you have a large apk installed for a long time.
The --force
overwrites the browsers.json file
Since Selenoid Configuration manager does not yet know how to configure browsers.json for mobile Chrome, you need to fix it yourself.
By default, browsers.json is generated in the ~ / .aerokube / selenoid directory.
The resulting browsers.json file for testing Android applications and Chrome inside the Android emulator.
{ "android": { "default": "6.0", "versions": { "6.0": { "image": "docker-registry:443/selenoid/android:6.0", "port": "4444", "path": "/wd/hub" } } }, "chrome": { "default": "mobile-75.0", "versions": { "mobile-75.0": { "image": "docker-registry:443/selenoid/chrome-mobile:75.0", "port": "4444", "path": "/wd/hub" } } } }
So far, the version of mobile chrome is behind the version of regular chrome.
Download the image of mobile chrome
docker pull selenoid/chrome-mobile:75.0
Changing browsers.json
When changing browsers.json file, selenoid needs to be reloaded
aerokube-cm selenoid stop
aerokube-cm selenoid start
Reloading configuration
You can do a Reloading configuration. Details on the link:
https://aerokube.com/selenoid/latest/#_reloading_configuration
Check that the docker container has started and the images have downloaded.
docker ps docker images
Running Selenoid UI using Configuration manager
aerokube-cm selenoid-ui start --registry https://docker-registry
Or
aerokube-cm selenoid-ui start
Check that the docker container has started and the images have downloaded.
docker ps docker images
Go to selenoid-ui at ip-where-you-ran-selenoid-and-selenoid-ui: 8080
You should have 2 CONNECTED lights green and written in android and chrome.
Demo test
Download https://github.com/aerokube/demo-tests
In all three java files, change the path in RemoteWebDriver to localhost
or to another address where you started selenoid.
In the AndroidRemoteApkTest.java file, change the path where you can download your APK.
device.setCapability("app", "http://ci.example.com/game2048.apk");
on
device.setCapability ("app", " http: // link-to-your-apk ");
or
device.setCapability("app", "http://hostname--FQDN----apk:8000/game2048.apk");
If you refer to localhost from docker, then you will have this error, since you are trying to access localhost from the main server from the docker network:
Tests in error: browserTest(com.aerokube.selenoid.AndroidRemoteApkTest): An unknown server-side error occurred while processing the command. Original error: Problem downloading app from url http://localhost:8000/apk/game2048.apk: connect ECONNREFUSED 127.0.0.1:8000
How to make available for download your local files will be lower.
In the file DemoTest.java add setCapability to run chrome on Android to get something like this.
In each java file, you can enable or disable video recording, remote viewing or management via VNC, and logging to a file. To disable the option you need to add 2 slashes to the beginning of the line.
To make files from the current directory available for download, you need to run the following command in a separate console in this directory:
ruby -rwebrick -e'WEBrick::HTTPServer.new(:Port => 8000, :DocumentRoot => Dir.pwd).start'
Running tests
In the demo-tests directory, run the tests:
If you need to specify settings and you use maven proxies (Nexus, Artifactory)
mvn -s settings.xml clean test
If we run with direct access to the Internet and without any settings
mvn clean test
Speed
The total deployment time of the android emulator and the launch of 1 test takes less than 1 minute.
Known bugs
https://github.com/aerokube/demo-tests/issues/5
Test Record
AndroidDemoTest.java:
AndroidRemoteApkTest.java:
DemoTest.java:
Search for the desired location in a mobile application using Appium
Appium is a cross-platform tool, i.e. allows you to write tests for mobile platforms (iOS, Android, Windows) using the API. This is one of the most widely used tools for regression testing applications on smartphones and tablets.
Download and run Appium
Go to File
-> New Session Window
In the Remote host
field, specify the address of the server where Selenoid is running.
In the Remote Port
field, specify the port on which Selenoid is running - usually 4444.
In the Remote Path
field, specify /wd/hub
In Desired Capabiliting
specify the Capabilities
you need.
The minimum JSON is this:
{ "browserName": "chrome", "browserVersion": "mobile-75.0", "enableVNC": true }
After the start of the session you will have this picture:
Now you can explore / search for the location you need.
Telegram chats:
https://t.me/aerokube - chat Aerokube
https://t.me/atinfo_chat - chat for test automation engineers