Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc0972318f | ||
|
|
3a88fa4ae4 | ||
|
|
398a694ccd | ||
|
|
14a29344b8 | ||
|
|
47621a7ccb | ||
|
|
c1d66496fb | ||
|
|
1365ec736b | ||
|
|
4aee17de2d | ||
|
|
5c9ad32522 | ||
|
|
366aa8b3b3 | ||
|
|
905f2c723b | ||
|
|
0e028d9a4a | ||
|
|
ce61b992f9 | ||
|
|
e62573036c | ||
|
|
e27b2e5fdf | ||
|
|
fdd4a86c40 | ||
|
|
15012fd3b4 | ||
|
|
1f440e1a07 | ||
|
|
567a494ccb | ||
|
|
d28c4dc5e0 | ||
|
|
7a052b7e2f | ||
|
|
988397318f | ||
|
|
0d6356ba47 | ||
|
|
0ea71ea6b8 | ||
|
|
08ff64d950 | ||
|
|
fcffca21ff | ||
|
|
95adfd1fbd | ||
|
|
5029d33528 | ||
|
|
c9ab42ecfb | ||
|
|
7c48af9b84 | ||
|
|
e1d6e3cdbe | ||
|
|
648010d519 | ||
|
|
9d3cb60f41 | ||
|
|
e2ad6b75d2 | ||
|
|
486fb5825b | ||
|
|
e56eb0e3ab | ||
|
|
6fe6a80f40 | ||
|
|
f7b30c3129 | ||
|
|
1062da3dcc | ||
|
|
c431118465 | ||
|
|
b6a1a57bed | ||
|
|
83baa09384 | ||
|
|
8a69c64de3 | ||
|
|
488e53149c | ||
|
|
2bc30edf4c | ||
|
|
8d544448f1 | ||
|
|
f7b560a28b | ||
|
|
0e578710f3 | ||
|
|
65df456066 | ||
|
|
5b694c2c55 | ||
|
|
6406504f94 | ||
|
|
b7c4538896 | ||
|
|
c7d988bd61 | ||
|
|
47e968927a | ||
|
|
dcf196ec4a | ||
|
|
aff1b062e1 | ||
|
|
59f6e4bd33 | ||
|
|
0b9af7e6b2 | ||
|
|
d9b5f8d86c | ||
|
|
0360c181c0 | ||
|
|
47ff7bf223 | ||
|
|
bedf77e83d | ||
|
|
151e3a8d6f | ||
|
|
7170ee20d4 | ||
|
|
768d793ba0 | ||
|
|
5501a20426 | ||
|
|
1a7453d6b6 | ||
|
|
d379133801 | ||
|
|
333c2b2a90 | ||
|
|
ab45f6bb52 | ||
|
|
a2e59992d9 | ||
|
|
e9ed10d08c | ||
|
|
d1a1bb5fa7 | ||
|
|
c3c7f9506f | ||
|
|
8c4d947833 | ||
|
|
80bbf1bd36 | ||
|
|
f05d2564fa | ||
|
|
81e63fb88e | ||
|
|
a7c9be6fc3 | ||
|
|
76393754fb | ||
|
|
10eb1b0d31 | ||
|
|
c3ad9b3d48 | ||
|
|
e2a0b7c840 |
@@ -0,0 +1,22 @@
|
||||
**Please make sure that it is an issue / a feature request. If it is a question / help wanted, please visit [our group chat](https://gitter.im/butomo1989/docker-android). Thank you!**
|
||||
|
||||
Operating System:
|
||||
<!-- OSX Yosemite, Ubuntu 16.04, Windows 10 etc -->
|
||||
|
||||
Docker Image:
|
||||
<!-- butomo1989/docker-android-x86-7.1.1, butomo1989/docker-android-real-device etc -->
|
||||
|
||||
Docker Version:
|
||||
<!-- 17.09.0-ce, 17.06.2-ce etc -->
|
||||
|
||||
Docker-compose version (Only if you use it):
|
||||
<!-- 1.16.1 etc -->
|
||||
|
||||
Docker Command to start docker-android:
|
||||
<!-- docker run ... -->
|
||||
|
||||
## Expected Behavior
|
||||
<!-- Explaination about expected behaviour goes here -->
|
||||
|
||||
## Actual Behavior
|
||||
<!-- Explaination about actual behaviour goes here -->
|
||||
@@ -0,0 +1,12 @@
|
||||
### Purpose of changes
|
||||
<!-- Please describe why this change is required / What problem you want to solve. -->
|
||||
|
||||
### Types of changes
|
||||
_Put an `x` in the boxes that apply_
|
||||
|
||||
- [ ] Bug fix (non-breaking change which fixes an issue)
|
||||
- [ ] New feature (non-breaking change which adds functionality)
|
||||
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
|
||||
|
||||
### How has this been tested?
|
||||
<!-- Please describe in detail how you tested your changes. -->
|
||||
@@ -6,4 +6,7 @@
|
||||
.coverage
|
||||
coverage.xml
|
||||
xunit.xml
|
||||
coverage/*
|
||||
coverage/*
|
||||
|
||||
# Video
|
||||
video*
|
||||
|
||||
@@ -11,12 +11,12 @@ services:
|
||||
install: "pip install -r requirements.txt"
|
||||
|
||||
env:
|
||||
matrix:
|
||||
- ANDROID_VERSION=5.0.1
|
||||
- ANDROID_VERSION=5.1.1
|
||||
- ANDROID_VERSION=6.0
|
||||
- ANDROID_VERSION=7.0
|
||||
- ANDROID_VERSION=7.1.1
|
||||
- ANDROID_VERSION=5.0.1
|
||||
- ANDROID_VERSION=5.1.1
|
||||
- ANDROID_VERSION=6.0
|
||||
- ANDROID_VERSION=7.0
|
||||
- ANDROID_VERSION=7.1.1
|
||||
- REAL_DEVICE=True
|
||||
|
||||
script: bash travis.sh
|
||||
|
||||
|
||||
@@ -1,32 +1,38 @@
|
||||
Docker-Android
|
||||
==============
|
||||
<p align="center">
|
||||
<img id="header" src="./images/logo_dockerandroid_small.png" />
|
||||
</p>
|
||||
|
||||
[](https://gitter.im/butomo1989/docker-android?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
[](https://travis-ci.org/butomo1989/docker-android)
|
||||
[](https://hub.docker.com/r/butomo1989/docker-android-x86-7.1.1/)
|
||||
[](https://codecov.io/gh/butomo1989/docker-android)
|
||||
[](https://www.codacy.com/app/butomo1989/docker-appium?utm_source=github.com&utm_medium=referral&utm_content=butomo1989/docker-appium&utm_campaign=Badge_Grade)
|
||||
|
||||
Docker-Android is an android environment, an android emulator that facilitates different devices and [appium] in docker solution integrated with noVNC.
|
||||
Docker-Android is a docker image built to be used for everything related to mobile website testing and Android project.
|
||||
|
||||
Samsung Device | Google Device
|
||||
:---------------------------:|:---------------------------:
|
||||
![][docker android samsung] | ![][docker android nexus]
|
||||
Emulator - Samsung Device | Emulator - Nexus Device | Real Device
|
||||
:---------------------------:|:---------------------------:|:---------------------------:
|
||||
![][emulator samsung] |![][emulator nexus] |![][real device]
|
||||
|
||||
Purpose
|
||||
-------
|
||||
|
||||
1. Build android project and run unit test inside container
|
||||
2. Run UI Test for mobile application with different frameworks (appium, espresso, etc.)
|
||||
3. Run UI Test for mobile website with appium test framework
|
||||
4. Video recording to analyse failing test cases ***(soon)***
|
||||
5. Monkey test for stress test ***(soon)***
|
||||
1. Run UI tests for mobile websites with [appium]
|
||||
2. Build Android project and run unit tests with the latest build-tools
|
||||
3. Run UI tests for Android applications with different frameworks ([appium], [espresso], [robotium], etc.)
|
||||
4. Run monkey / stress tests
|
||||
5. SMS testing
|
||||
|
||||
Advantages compare with other docker-android projects
|
||||
-----------------------------------------------------
|
||||
|
||||
1. noVNC to see what happen inside docker container
|
||||
2. Android emulator that facilitates different devices
|
||||
3. Able to connect with selenium grid
|
||||
4. Able to control emulator from outside container by using adb connect
|
||||
5. It will have more important features for testing purpose like video recording and monkey test ***(soon)***
|
||||
2. Emulator for different devices / skins, such as Samsung Galaxy S6, LG Nexus 4, HTC Nexus One and more.
|
||||
3. Ability to connect to Selenium Grid
|
||||
4. Ability to control emulator from outside container by using adb connect
|
||||
5. Support real devices with screen mirroring
|
||||
6. Ability to record video during test execution for debugging
|
||||
7. Open source with more features coming
|
||||
|
||||
List of Docker images
|
||||
---------------------
|
||||
@@ -43,6 +49,7 @@ List of Docker images
|
||||
|OSX / Windows|6.0|23|butomo1989/docker-android-arm-6.0|[](https://microbadger.com/images/butomo1989/docker-android-arm-6.0 "Get your own image badge on microbadger.com")|
|
||||
|OSX / Windows|7.0|24|butomo1989/docker-android-arm-7.0|[](https://microbadger.com/images/butomo1989/docker-android-arm-7.0 "Get your own image badge on microbadger.com")|
|
||||
|OSX / Windows|7.1.1|25|butomo1989/docker-android-arm-7.1.1|[](https://microbadger.com/images/butomo1989/docker-android-arm-7.1.1 "Get your own image badge on microbadger.com")|
|
||||
|All |-|-|butomo1989/docker-android-real-device|[](https://microbadger.com/images/butomo1989/docker-android-real-device "Get your own image badge on microbadger.com")|
|
||||
|
||||
List of Devices
|
||||
---------------
|
||||
@@ -52,15 +59,9 @@ Type | Device Name
|
||||
Phone | Samsung Galaxy S6
|
||||
Phone | Nexus 4
|
||||
Phone | Nexus 5
|
||||
Phone | Nexus 5x
|
||||
Phone | Nexus 6
|
||||
Phone | Nexus 6P
|
||||
Phone | Nexus One
|
||||
Phone | Nexus S
|
||||
Tablet | Pixel C
|
||||
Tablet | Nexus 7
|
||||
Tablet | Nexus 9
|
||||
Tablet | Nexus 10
|
||||
|
||||
Requirements
|
||||
------------
|
||||
@@ -107,9 +108,6 @@ docker run --privileged -d -p 6080:6080 -p 5554:5554 -p 5555:5555 -p 4723:4723 -
|
||||
|
||||
### Connect to Selenium Grid
|
||||
|
||||
![][selenium grid]
|
||||
![][devices are connected with selenium grid]
|
||||
|
||||
It is also possible to connect appium server that run inside docker-android with selenium grid by passing following environment variables:
|
||||
|
||||
- CONNECT\_TO\_GRID=True
|
||||
@@ -118,8 +116,12 @@ It is also possible to connect appium server that run inside docker-android with
|
||||
- SELENIUM_HOST="\<host\_ip\_address>"
|
||||
- SELENIUM_PORT=\<port\_number>
|
||||
|
||||
To run tests for mobile browser, following parameter can be passed:
|
||||
|
||||
- MOBILE\_WEB\_TEST=True
|
||||
|
||||
```bash
|
||||
docker run --privileged -d --rm -p 6080:6080 -p 4723:4723 -p 5554:5554 -p 5555:5555 -e DEVICE="Samsung Galaxy S6" -e APPIUM=True -e CONNECT_TO_GRID=True -e APPIUM_HOST="127.0.0.1" -e APPIUM_PORT=4723 -e SELENIUM_HOST="172.17.0.1" -e SELENIUM_PORT=4444 --name android-container butomo1989/docker-android-x86-7.1.1
|
||||
docker run --privileged -d -p 6080:6080 -p 4723:4723 -p 5554:5554 -p 5555:5555 -e DEVICE="Samsung Galaxy S6" -e APPIUM=True -e CONNECT_TO_GRID=True -e APPIUM_HOST="127.0.0.1" -e APPIUM_PORT=4723 -e SELENIUM_HOST="172.17.0.1" -e SELENIUM_PORT=4444 -e MOBILE_WEB_TEST=True --name android-container butomo1989/docker-android-x86-7.1.1
|
||||
```
|
||||
|
||||
### Share Volume
|
||||
@@ -127,9 +129,40 @@ docker run --privileged -d --rm -p 6080:6080 -p 4723:4723 -p 5554:5554 -p 5555:5
|
||||
If you want to use appium to test UI of your android application, you need to share volume where the APK is located to folder ***/root/tmp***.
|
||||
|
||||
```bash
|
||||
docker run --privileged -it --rm -p 6080:6080 -p 4723:4723 -p 5554:5554 -p 5555:5555 -v $PWD/example/sample_apk:/root/tmp -e DEVICE="Nexus 5" -e APPIUM=True -e CONNECT_TO_GRID=True -e APPIUM_HOST="127.0.0.1" -e APPIUM_PORT=4723 -e SELENIUM_HOST="172.17.0.1" -e SELENIUM_PORT=4444 --name android-container butomo1989/docker-android-x86-7.1.1
|
||||
docker run --privileged -d -p 6080:6080 -p 4723:4723 -p 5554:5554 -p 5555:5555 -v $PWD/example/sample_apk:/root/tmp -e DEVICE="Nexus 5" -e APPIUM=True -e CONNECT_TO_GRID=True -e APPIUM_HOST="127.0.0.1" -e APPIUM_PORT=4723 -e SELENIUM_HOST="172.17.0.1" -e SELENIUM_PORT=4444 --name android-container butomo1989/docker-android-x86-7.1.1
|
||||
```
|
||||
|
||||
### Video Recording
|
||||
|
||||
You can deactivate auto_record by changing the value to "False" in docker-compose file. e.g. change value to "False" in this [line].
|
||||
|
||||
### Docker-Compose
|
||||
|
||||
![][compose]
|
||||
|
||||
There is [example of compose file] to run complete selenium grid and docker-android container as nodes. [docker-compose] version [1.13.0] or higher is required to be able to execute that compose file.
|
||||
|
||||
```bash
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
Build Android project
|
||||
---------------------
|
||||
|
||||
docker-android can be used for building Android project and executing its unit test. This following steps will illustrate how to build Android project:
|
||||
|
||||
1. Clone [this sample test project](https://github.com/googlesamples/android-testing).
|
||||
|
||||
```bash
|
||||
git clone git@github.com:googlesamples/android-testing.git
|
||||
```
|
||||
|
||||
2. Build the project
|
||||
|
||||
```bash
|
||||
docker run -it --rm -v $PWD/android-testing/ui/espresso/BasicSample:/root/tmp butomo1989/docker-android-x86-7.1.1 tmp/gradlew build
|
||||
```
|
||||
|
||||
Control android emulator outside container
|
||||
------------------------------------------
|
||||
|
||||
@@ -179,6 +212,78 @@ SMS Simulation
|
||||
|
||||
![][sms]
|
||||
|
||||
How to use docker-android in VMWare or Parallels Desktop
|
||||
---------------
|
||||
The following instructions are used for OS X. You'll need [docker-machine-parallels](https://github.com/Parallels/docker-machine-parallels) to create a virtual machine (vm) with tiny core linux for running docker images. After that, you may start the vm you created for VMWare Fusion or Parallels Desktop and run a docker container inside this vm. If you're going to use the android docker of emulator with x86 processor, setup this vm for nested virtualization and kvm support before you run a docker container.
|
||||
|
||||
1. Install docker-machine-parallels via Homebrew:
|
||||
```bash
|
||||
$ brew install docker-machine-parallels
|
||||
```
|
||||
|
||||
2. Create a virtual machine for running docker images based on the virtual machine tool you use
|
||||
|
||||
Create a virtual machine of VMWare Fusion
|
||||
```bash
|
||||
$ docker-machine create --driver=vmwarefusion vmware-dev
|
||||
```
|
||||
|
||||
Create a virtual machine of Parallels Desktop
|
||||
```bash
|
||||
$ docker-machine create --driver=parallels prl-dev
|
||||
```
|
||||
|
||||
This utility `docker-machine-parallels` will fetch boot2docker.iso to create a vm of VMWare fusion or Parallels Desktop. When the vm is created, you'll see it's booted with VMWare fusion or Parallels Desktop where the network of vm is set to NAT and one IP is assigned. You'll be able to connect to vnc service inside the docker image through that IP. Say it's `10.211.55.3` and we'll use it later.
|
||||
|
||||
3. Setup the virtual machine for nested virtualization support
|
||||
|
||||
Shutdown the vm by running the command below in the boot2docker vm before you setup it.
|
||||
```bash
|
||||
# shutdown -h now
|
||||
```
|
||||
|
||||
If you use VMWare Fusion, go to menu bar > Vitual Machine > Settings > Processors and Memory, expand Advanced options, and select `Enable hypervisor applications in this virtual machine`.
|
||||
|
||||
[]
|
||||
|
||||
If you use Parallels Desktop, open settings screen of that vm and go to `CPU & Memory` under `hardware` tab, expand Advanced settings and select `Enable nested virtualization`.
|
||||
|
||||
[]
|
||||
|
||||
4. Enable kvm inside virtual machine
|
||||
Run as an account other than root to install kvm packages using tce-load.
|
||||
```bash
|
||||
# su docker
|
||||
$ tce-load -wi kvm
|
||||
```
|
||||
|
||||
Run as root to load kvm module after kvm packages install.
|
||||
```bash
|
||||
$ sudo modprobe kvm_intel
|
||||
```
|
||||
|
||||
Check if the kvm device is loaded.
|
||||
```bash
|
||||
$ ls /dev/kvm
|
||||
```
|
||||
|
||||
Check if your CPU supports hardware virtualization now
|
||||
```bash
|
||||
$ egrep -c '(vmx|svm)' /proc/cpuinfo
|
||||
```
|
||||
|
||||
If **0** it means that your CPU doesn't support hardware virtualization.
|
||||
|
||||
If **1** or more it does - but you still need to make sure that virtualization is enabled in the BIOS.
|
||||
|
||||
5. You may now run a docker container
|
||||
Let's run a docker image for an emulator with x86 processor.
|
||||
```bash
|
||||
docker run --privileged -d -p 6080:6080 -p 5554:5554 -p 5555:5555 -e DEVICE="Samsung Galaxy S6" --name android-container butomo1989/docker-android-x86-7.1.1
|
||||
```
|
||||
|
||||
When the services inside this docker container are running, connect to http://10.211.55.3:6080/vnc.html (the IP we got when the docker machine was created) and login. The emulator with x86 processor should be running on screen.
|
||||
|
||||
Troubleshooting
|
||||
---------------
|
||||
All logs inside container are stored under folder **/var/log/supervisor**. you can print out log file by using **docker exec**. Example:
|
||||
@@ -187,10 +292,21 @@ All logs inside container are stored under folder **/var/log/supervisor**. you c
|
||||
docker exec -it android-container tail -f /var/log/supervisor/docker-android.stdout.log
|
||||
```
|
||||
|
||||
Special Thanks
|
||||
--------------
|
||||
- [Gian Christanto] for creating a great logo!
|
||||
|
||||
[appium]: <https://appium.io>
|
||||
[docker android samsung]: <images/docker_android_samsung.png>
|
||||
[docker android nexus]: <images/docker_android_nexus.png>
|
||||
[selenium grid]: <images/selenium_grid.png>
|
||||
[devices are connected with selenium grid]: <images/connected_with_grid.png>
|
||||
[espresso]: <https://google.github.io/android-testing-support-library/docs/espresso/>
|
||||
[robotium]: <https://github.com/RobotiumTech/robotium>
|
||||
[emulator samsung]: <images/emulator_samsung_galaxy_s6.png>
|
||||
[emulator nexus]: <images/emulator_nexus_5.png>
|
||||
[real device]: <images/real_device.png>
|
||||
[compose]: <images/compose.png>
|
||||
[line]: <https://github.com/butomo1989/docker-android/blob/master/docker-compose.yml#L29>
|
||||
[example of compose file]: <docker-compose.yml>
|
||||
[docker-compose]: <https://docs.docker.com/compose/install/>
|
||||
[1.13.0]: <https://github.com/docker/compose/releases/tag/1.13.0>
|
||||
[adb_connection]: <images/adb_connection.png>
|
||||
[sms]: <images/SMS.png>
|
||||
[gian christanto]: <https://www.linkedin.com/in/gian-christanto-0b398b131/>
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
# Note: It requires docker-compose 1.13.0
|
||||
#
|
||||
# Usage: docker-compose up -d
|
||||
version: "2.2"
|
||||
|
||||
services:
|
||||
# Selenium hub
|
||||
selenium_hub:
|
||||
image: selenium/hub:3.11.0-bismuth
|
||||
ports:
|
||||
- "4444:4444"
|
||||
|
||||
# Real devices
|
||||
real_device:
|
||||
image: butomo1989/docker-android-real-device
|
||||
privileged: true
|
||||
depends_on:
|
||||
- selenium_hub
|
||||
ports:
|
||||
- 6080:6080
|
||||
volumes:
|
||||
- ./video-real-device:/tmp/video
|
||||
- /dev/bus/usb:/dev/bus/usb
|
||||
- ~/.android:/root/.android
|
||||
environment:
|
||||
- CONNECT_TO_GRID=True
|
||||
- APPIUM=true
|
||||
- SELENIUM_HOST=selenium_hub
|
||||
- AUTO_RECORD=True
|
||||
- BROWSER_NAME=chrome
|
||||
|
||||
# Docker-Android for Android application testing
|
||||
nexus_7.1.1:
|
||||
image: butomo1989/docker-android-x86-7.1.1
|
||||
privileged: true
|
||||
# Increase scale number if needed
|
||||
scale: 1
|
||||
depends_on:
|
||||
- selenium_hub
|
||||
- real_device
|
||||
ports:
|
||||
- 6080
|
||||
# Change path of apk that you want to test. I use sample_apk that I provide in folder "example"
|
||||
volumes:
|
||||
- $PWD/example/sample_apk:/root/tmp
|
||||
- ./video-nexus_7.1.1:/tmp/video
|
||||
environment:
|
||||
- DEVICE=Nexus 5
|
||||
- CONNECT_TO_GRID=True
|
||||
- APPIUM=true
|
||||
- SELENIUM_HOST=selenium_hub
|
||||
- AUTO_RECORD=True
|
||||
|
||||
# Docker-Android for mobile website testing with chrome browser
|
||||
# Chrome browser exists only for version 7.0 and 7.1.1
|
||||
samsung_galaxy_web_7.1.1:
|
||||
image: butomo1989/docker-android-x86-7.1.1
|
||||
privileged: true
|
||||
# Increase scale number if needed
|
||||
scale: 1
|
||||
depends_on:
|
||||
- selenium_hub
|
||||
- real_device
|
||||
ports:
|
||||
- 6080
|
||||
volumes:
|
||||
- ./video-samsung_7.1.1:/tmp/video
|
||||
environment:
|
||||
- DEVICE=Samsung Galaxy S6
|
||||
- CONNECT_TO_GRID=True
|
||||
- APPIUM=true
|
||||
- SELENIUM_HOST=selenium_hub
|
||||
- MOBILE_WEB_TEST=True
|
||||
- AUTO_RECORD=True
|
||||
|
||||
# Docker-Android for mobile website testing with default browser
|
||||
# Default browser exists only for version 5.0.1, 5.1.1 and 6.0
|
||||
samsung_galaxy_web_5.1.1:
|
||||
image: butomo1989/docker-android-x86-5.1.1
|
||||
privileged: true
|
||||
# Increase scale number if needed
|
||||
scale: 1
|
||||
depends_on:
|
||||
- selenium_hub
|
||||
- real_device
|
||||
ports:
|
||||
- 6080
|
||||
volumes:
|
||||
- ./video-samsung_5.1.1:/tmp/video
|
||||
environment:
|
||||
- DEVICE=Samsung Galaxy S6
|
||||
- CONNECT_TO_GRID=True
|
||||
- APPIUM=true
|
||||
- SELENIUM_HOST=selenium_hub
|
||||
- MOBILE_WEB_TEST=True
|
||||
- AUTO_RECORD=True
|
||||
@@ -0,0 +1,146 @@
|
||||
FROM appium/appium:1.7.2-p1
|
||||
|
||||
LABEL maintainer "Budi Utomo <budi.ut.1989@gmail.com>"
|
||||
|
||||
#=============
|
||||
# Set WORKDIR
|
||||
#=============
|
||||
WORKDIR /root
|
||||
|
||||
#==================
|
||||
# General Packages
|
||||
#------------------
|
||||
# xterm
|
||||
# Terminal emulator
|
||||
# supervisor
|
||||
# Process manager
|
||||
# socat
|
||||
# Port forwarder
|
||||
#------------------
|
||||
# NoVNC Packages
|
||||
#------------------
|
||||
# x11vnc
|
||||
# VNC server for X display
|
||||
# openbox
|
||||
# Windows manager
|
||||
# menu
|
||||
# Debian menu
|
||||
# python-numpy
|
||||
# Numpy, For faster performance: https://github.com/novnc/websockify/issues/77
|
||||
# net-tools
|
||||
# Netstat
|
||||
#------------------
|
||||
# Video Recording
|
||||
#------------------
|
||||
# ffmpeg
|
||||
# Video recorder
|
||||
# jq
|
||||
# Sed for JSON data
|
||||
#==================
|
||||
RUN apt-get -qqy update && apt-get -qqy install --no-install-recommends \
|
||||
xterm \
|
||||
supervisor \
|
||||
socat \
|
||||
x11vnc \
|
||||
openbox \
|
||||
menu \
|
||||
python-numpy \
|
||||
net-tools \
|
||||
ffmpeg \
|
||||
jq \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
#=======
|
||||
# noVNC
|
||||
# Use same commit id that docker-selenium uses
|
||||
# https://github.com/elgalu/docker-selenium/blob/236b861177bd2917d864e52291114b1f5e4540d7/Dockerfile#L412-L413
|
||||
#=======
|
||||
ENV NOVNC_SHA="b403cb92fb8de82d04f305b4f14fa978003890d7" \
|
||||
WEBSOCKIFY_SHA="558a6439f14b0d85a31145541745e25c255d576b"
|
||||
RUN wget -nv -O noVNC.zip "https://github.com/kanaka/noVNC/archive/${NOVNC_SHA}.zip" \
|
||||
&& unzip -x noVNC.zip \
|
||||
&& rm noVNC.zip \
|
||||
&& mv noVNC-${NOVNC_SHA} noVNC \
|
||||
&& wget -nv -O websockify.zip "https://github.com/kanaka/websockify/archive/${WEBSOCKIFY_SHA}.zip" \
|
||||
&& unzip -x websockify.zip \
|
||||
&& mv websockify-${WEBSOCKIFY_SHA} ./noVNC/utils/websockify \
|
||||
&& rm websockify.zip \
|
||||
&& ln noVNC/vnc_auto.html noVNC/index.html
|
||||
|
||||
#======================
|
||||
# Install SDK packages
|
||||
#======================
|
||||
ARG ANDROID_VERSION=5.0.1
|
||||
ARG API_LEVEL=21
|
||||
ARG PROCESSOR=x86
|
||||
ARG SYS_IMG=x86_64
|
||||
ARG IMG_TYPE=google_apis
|
||||
ARG BROWSER=android
|
||||
ENV ANDROID_VERSION=$ANDROID_VERSION \
|
||||
API_LEVEL=$API_LEVEL \
|
||||
PROCESSOR=$PROCESSOR \
|
||||
SYS_IMG=$SYS_IMG \
|
||||
IMG_TYPE=$IMG_TYPE \
|
||||
BROWSER=$BROWSER
|
||||
ENV PATH ${PATH}:${ANDROID_HOME}/build-tools
|
||||
RUN echo y | sdkmanager "platforms;android-${API_LEVEL}" && \
|
||||
echo y | sdkmanager "system-images;android-${API_LEVEL};${IMG_TYPE};${SYS_IMG}" && \
|
||||
echo y | sdkmanager "emulator"
|
||||
RUN rm ${ANDROID_HOME}/tools/emulator \
|
||||
&& ln -s ${ANDROID_HOME}/emulator/emulator64-${PROCESSOR} ${ANDROID_HOME}/tools/emulator
|
||||
ENV LD_LIBRARY_PATH=$ANDROID_HOME/emulator/lib64:$ANDROID_HOME/emulator/lib64/qt/lib
|
||||
|
||||
#==============================================
|
||||
# Download chrome driver v2.26
|
||||
# to be able to use chrome browser in emulator
|
||||
# Issue: https://github.com/butomo1989/docker-android/commit/6406504f944dae73d0a0c5d8e71a17a47dff9b33
|
||||
#==============================================
|
||||
RUN wget -nv -O chrome.zip "https://chromedriver.storage.googleapis.com/2.26/chromedriver_linux64.zip" \
|
||||
&& unzip -x chrome.zip \
|
||||
&& rm chrome.zip
|
||||
|
||||
#================================================
|
||||
# noVNC Default Configurations
|
||||
# These Configurations can be changed through -e
|
||||
#================================================
|
||||
ENV DISPLAY=:0 \
|
||||
SCREEN=0 \
|
||||
SCREEN_WIDTH=1600 \
|
||||
SCREEN_HEIGHT=900 \
|
||||
SCREEN_DEPTH=16 \
|
||||
LOCAL_PORT=5900 \
|
||||
TARGET_PORT=6080 \
|
||||
TIMEOUT=1 \
|
||||
VIDEO_PATH=/tmp/video \
|
||||
LOG_PATH=/var/log/supervisor
|
||||
|
||||
#===============
|
||||
# Expose Ports
|
||||
#---------------
|
||||
# 4723
|
||||
# Appium port
|
||||
# 6080
|
||||
# noVNC port
|
||||
# 5554
|
||||
# Emulator port
|
||||
# 5555
|
||||
# ADB connection port
|
||||
#===============
|
||||
EXPOSE 4723 6080 5554 5555
|
||||
|
||||
#======================
|
||||
# Add Emulator Devices
|
||||
#======================
|
||||
COPY devices /root/devices
|
||||
|
||||
#===================
|
||||
# Run docker-appium
|
||||
#===================
|
||||
COPY src /root/src
|
||||
COPY supervisord.conf /root/
|
||||
RUN chmod -R +x /root/src && chmod +x /root/supervisord.conf
|
||||
|
||||
HEALTHCHECK --interval=2s --timeout=40s --retries=1 \
|
||||
CMD adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done'
|
||||
|
||||
CMD /usr/bin/supervisord --configuration supervisord.conf
|
||||
@@ -1,6 +1,6 @@
|
||||
FROM ubuntu:16.04
|
||||
FROM appium/appium:1.7.2-p1
|
||||
|
||||
ENV DEBIAN_FRONTEND noninteractive
|
||||
LABEL maintainer "Budi Utomo <budi.ut.1989@gmail.com>"
|
||||
|
||||
#=============
|
||||
# Set WORKDIR
|
||||
@@ -10,27 +10,15 @@ WORKDIR /root
|
||||
#==================
|
||||
# General Packages
|
||||
#------------------
|
||||
# wget
|
||||
# Network downloader
|
||||
# unzip
|
||||
# Unzip zip file
|
||||
# curl
|
||||
# Transfer data from or to a server
|
||||
# xterm
|
||||
# Terminal emulator
|
||||
# supervisor
|
||||
# Process manager
|
||||
# openjdk-8-jdk
|
||||
# Java
|
||||
# libqt5webkit5
|
||||
# Web content engine (Fix issue in Android)
|
||||
# socat
|
||||
# Port forwarder
|
||||
#------------------
|
||||
# NoVNC Packages
|
||||
#------------------
|
||||
# xvfb
|
||||
# X virtual framebuffer
|
||||
# x11vnc
|
||||
# VNC server for X display
|
||||
# openbox
|
||||
@@ -42,6 +30,13 @@ WORKDIR /root
|
||||
# net-tools
|
||||
# Netstat
|
||||
#------------------
|
||||
# Video Recording
|
||||
#------------------
|
||||
# ffmpeg
|
||||
# Video recorder
|
||||
# jq
|
||||
# Sed for JSON data
|
||||
#------------------
|
||||
# KVM Package
|
||||
# for emulator x86
|
||||
# https://help.ubuntu.com/community/KVM/Installation
|
||||
@@ -52,20 +47,16 @@ WORKDIR /root
|
||||
# bridge-utils
|
||||
#==================
|
||||
RUN apt-get -qqy update && apt-get -qqy install --no-install-recommends \
|
||||
wget \
|
||||
unzip \
|
||||
curl \
|
||||
xterm \
|
||||
supervisor \
|
||||
openjdk-8-jdk \
|
||||
libqt5webkit5 \
|
||||
socat \
|
||||
xvfb \
|
||||
x11vnc \
|
||||
openbox \
|
||||
menu \
|
||||
python-numpy \
|
||||
net-tools \
|
||||
ffmpeg \
|
||||
jq \
|
||||
qemu-kvm \
|
||||
libvirt-bin \
|
||||
ubuntu-vm-builder \
|
||||
@@ -89,49 +80,38 @@ RUN wget -nv -O noVNC.zip "https://github.com/kanaka/noVNC/archive/${NOVNC_SHA}
|
||||
&& rm websockify.zip \
|
||||
&& ln noVNC/vnc_auto.html noVNC/index.html
|
||||
|
||||
#=====================
|
||||
# Install Android SDK
|
||||
#=====================
|
||||
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/jre
|
||||
ENV PATH ${PATH}:${JAVA_HOME}/bin
|
||||
|
||||
ENV SDK_VERSION=25.2.3 \
|
||||
ANDROID_HOME=/root
|
||||
RUN wget -nv -O android.zip https://dl.google.com/android/repository/tools_r${SDK_VERSION}-linux.zip \
|
||||
&& unzip android.zip && rm android.zip
|
||||
ENV PATH ${PATH}:${ANDROID_HOME}/tools
|
||||
RUN echo y | android update sdk --no-ui -a --filter platform-tools
|
||||
ENV PATH ${PATH}:${ANDROID_HOME}/platform-tools
|
||||
|
||||
#====================================
|
||||
# Install latest nodejs, npm, appium
|
||||
#====================================
|
||||
RUN curl -sL https://deb.nodesource.com/setup_7.x | bash - \
|
||||
&& apt-get -qqy update && apt-get -qqy install nodejs && rm -rf /var/lib/apt/lists/*
|
||||
ENV APPIUM_VERSION 1.6.3
|
||||
RUN npm install -g appium@$APPIUM_VERSION && npm cache clean
|
||||
|
||||
#======================
|
||||
# Install SDK packages
|
||||
#======================
|
||||
ARG ANDROID_VERSION=5.0.1
|
||||
ARG BUILD_TOOL=21.1.2
|
||||
ARG API_LEVEL=21
|
||||
ARG PROCESSOR=x86
|
||||
ARG SYS_IMG=x86_64
|
||||
ARG IMG_TYPE=google_apis
|
||||
ARG BROWSER=android
|
||||
ENV ANDROID_VERSION=$ANDROID_VERSION \
|
||||
BUILD_TOOL=$BUILD_TOOL \
|
||||
API_LEVEL=$API_LEVEL \
|
||||
PROCESSOR=$PROCESSOR \
|
||||
SYS_IMG=$SYS_IMG \
|
||||
IMG_TYPE=$IMG_TYPE
|
||||
RUN echo y | android update sdk --no-ui -a --filter build-tools-${BUILD_TOOL}
|
||||
IMG_TYPE=$IMG_TYPE \
|
||||
BROWSER=$BROWSER
|
||||
ENV PATH ${PATH}:${ANDROID_HOME}/build-tools
|
||||
|
||||
RUN echo y | sdkmanager "platforms;android-${API_LEVEL}" && \
|
||||
echo y | sdkmanager "system-images;android-${API_LEVEL};${IMG_TYPE};${SYS_IMG}" && \
|
||||
echo y | sdkmanager "emulator"
|
||||
RUN rm ${ANDROID_HOME}/tools/emulator \
|
||||
&& ln -s ${ANDROID_HOME}/tools/emulator64-${PROCESSOR} ${ANDROID_HOME}/tools/emulator
|
||||
RUN echo y | android update sdk --no-ui -a -t android-${API_LEVEL},sys-img-${SYS_IMG}-${IMG_TYPE}-${API_LEVEL}
|
||||
&& ln -s ${ANDROID_HOME}/emulator/emulator64-${PROCESSOR} ${ANDROID_HOME}/tools/emulator
|
||||
ENV LD_LIBRARY_PATH=$ANDROID_HOME/emulator/lib64:$ANDROID_HOME/emulator/lib64/qt/lib
|
||||
|
||||
|
||||
#==============================================
|
||||
# Download chrome driver v2.26
|
||||
# to be able to use chrome browser in emulator
|
||||
# Issue: https://github.com/butomo1989/docker-android/commit/6406504f944dae73d0a0c5d8e71a17a47dff9b33
|
||||
#==============================================
|
||||
RUN wget -nv -O chrome.zip "https://chromedriver.storage.googleapis.com/2.26/chromedriver_linux64.zip" \
|
||||
&& unzip -x chrome.zip \
|
||||
&& rm chrome.zip
|
||||
|
||||
#================================================
|
||||
# noVNC Default Configurations
|
||||
@@ -145,6 +125,7 @@ ENV DISPLAY=:0 \
|
||||
LOCAL_PORT=5900 \
|
||||
TARGET_PORT=6080 \
|
||||
TIMEOUT=1 \
|
||||
VIDEO_PATH=/tmp/video \
|
||||
LOG_PATH=/var/log/supervisor
|
||||
|
||||
#===============
|
||||
@@ -172,4 +153,8 @@ COPY devices /root/devices
|
||||
COPY src /root/src
|
||||
COPY supervisord.conf /root/
|
||||
RUN chmod -R +x /root/src && chmod +x /root/supervisord.conf
|
||||
|
||||
HEALTHCHECK --interval=2s --timeout=40s --retries=1 \
|
||||
CMD adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done'
|
||||
|
||||
CMD /usr/bin/supervisord --configuration supervisord.conf
|
||||
@@ -0,0 +1,111 @@
|
||||
FROM appium/appium:1.7.2-p1
|
||||
|
||||
LABEL maintainer "Budi Utomo <budi.ut.1989@gmail.com>"
|
||||
|
||||
#=============
|
||||
# Set WORKDIR
|
||||
#=============
|
||||
WORKDIR /root
|
||||
|
||||
#==================
|
||||
# General Packages
|
||||
#------------------
|
||||
# xterm
|
||||
# Terminal emulator
|
||||
# supervisor
|
||||
# Process manager
|
||||
# socat
|
||||
# Port forwarder
|
||||
#------------------
|
||||
# NoVNC Packages
|
||||
#------------------
|
||||
# x11vnc
|
||||
# VNC server for X display
|
||||
# openbox
|
||||
# Windows manager
|
||||
# menu
|
||||
# Debian menu
|
||||
# python-numpy
|
||||
# Numpy, For faster performance: https://github.com/novnc/websockify/issues/77
|
||||
# net-tools
|
||||
# Netstat
|
||||
#------------------
|
||||
# Video Recording
|
||||
#------------------
|
||||
# ffmpeg
|
||||
# Video recorder
|
||||
# jq
|
||||
# Sed for JSON data
|
||||
#==================
|
||||
RUN apt-get -qqy update && apt-get -qqy install --no-install-recommends \
|
||||
xterm \
|
||||
supervisor \
|
||||
socat \
|
||||
x11vnc \
|
||||
openbox \
|
||||
menu \
|
||||
python-numpy \
|
||||
net-tools \
|
||||
ffmpeg \
|
||||
jq \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
#=======
|
||||
# noVNC
|
||||
# Use same commit id that docker-selenium uses
|
||||
# https://github.com/elgalu/docker-selenium/blob/236b861177bd2917d864e52291114b1f5e4540d7/Dockerfile#L412-L413
|
||||
#=======
|
||||
ENV NOVNC_SHA="b403cb92fb8de82d04f305b4f14fa978003890d7" \
|
||||
WEBSOCKIFY_SHA="558a6439f14b0d85a31145541745e25c255d576b"
|
||||
RUN wget -nv -O noVNC.zip "https://github.com/kanaka/noVNC/archive/${NOVNC_SHA}.zip" \
|
||||
&& unzip -x noVNC.zip \
|
||||
&& rm noVNC.zip \
|
||||
&& mv noVNC-${NOVNC_SHA} noVNC \
|
||||
&& wget -nv -O websockify.zip "https://github.com/kanaka/websockify/archive/${WEBSOCKIFY_SHA}.zip" \
|
||||
&& unzip -x websockify.zip \
|
||||
&& mv websockify-${WEBSOCKIFY_SHA} ./noVNC/utils/websockify \
|
||||
&& rm websockify.zip \
|
||||
&& ln noVNC/vnc_auto.html noVNC/index.html
|
||||
|
||||
#================================================
|
||||
# noVNC Default Configurations
|
||||
# These Configurations can be changed through -e
|
||||
#================================================
|
||||
ENV DISPLAY=:0 \
|
||||
SCREEN=0 \
|
||||
SCREEN_WIDTH=1600 \
|
||||
SCREEN_HEIGHT=900 \
|
||||
SCREEN_DEPTH=16 \
|
||||
LOCAL_PORT=5900 \
|
||||
TARGET_PORT=6080 \
|
||||
TIMEOUT=1 \
|
||||
VIDEO_PATH=/tmp/video \
|
||||
LOG_PATH=/var/log/supervisor
|
||||
|
||||
#=========================
|
||||
# Set default variables
|
||||
#=========================
|
||||
ENV REAL_DEVICE=True
|
||||
ENV BROWSER=android
|
||||
|
||||
#===============
|
||||
# Expose Ports
|
||||
#---------------
|
||||
# 4723
|
||||
# Appium port
|
||||
# 6080
|
||||
# noVNC port
|
||||
# 5555
|
||||
# ADB connection port
|
||||
#===============
|
||||
EXPOSE 4723 6080 5555
|
||||
|
||||
#===================
|
||||
# Run docker-appium
|
||||
#===================
|
||||
COPY sm/asm.jar /root/
|
||||
COPY src /root/src
|
||||
COPY supervisord.conf /root/
|
||||
RUN chmod -R +x /root/src && chmod +x /root/supervisord.conf
|
||||
|
||||
CMD /usr/bin/supervisord --configuration supervisord.conf
|
||||
@@ -9,10 +9,12 @@ class SimpleAndroidUITests(unittest.TestCase):
|
||||
desired_caps = {
|
||||
'platformName': 'Android',
|
||||
'deviceName': 'Android Emulator',
|
||||
'automationName': 'UIAutomator2',
|
||||
'app': '/root/tmp/sample_apk_debug.apk',
|
||||
'avd': 'samsung_galaxy_s6_7.1.1'
|
||||
'browserName': 'android',
|
||||
'avd': 'nexus_5_7.1.1'
|
||||
}
|
||||
self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
|
||||
self.driver = webdriver.Remote('http://127.0.0.1:4444/wd/hub', desired_caps)
|
||||
|
||||
def tearDown(self):
|
||||
self.driver.quit()
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import unittest
|
||||
|
||||
from time import sleep
|
||||
|
||||
from appium import webdriver
|
||||
|
||||
|
||||
@@ -13,12 +15,24 @@ class MSiteChromeAndroidUITests(unittest.TestCase):
|
||||
'deviceName': 'Android Emulator',
|
||||
'appPackage': 'com.android.chrome',
|
||||
'appActivity': 'com.google.android.apps.chrome.Main',
|
||||
'avd': 'samsung_galaxy_s6_7.1.1'
|
||||
'browserName': 'chrome'
|
||||
}
|
||||
self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
|
||||
self.driver = webdriver.Remote('http://127.0.0.1:4444/wd/hub', desired_caps)
|
||||
|
||||
def test_open_url(self):
|
||||
self.driver.get('http://targeturl.com')
|
||||
self.driver.get('http://google.com')
|
||||
|
||||
# Handle Welcome Home
|
||||
self.driver.switch_to.context('NATIVE_APP')
|
||||
self.driver.find_element_by_id('terms_accept').click()
|
||||
self.driver.find_element_by_id('negative_button').click()
|
||||
|
||||
# Search for Github
|
||||
self.driver.switch_to.context('CHROMIUM')
|
||||
search = self.driver.find_element_by_name('q')
|
||||
search.send_keys('butomo1989 docker-android')
|
||||
search.submit()
|
||||
sleep(2)
|
||||
|
||||
def tearDown(self):
|
||||
self.driver.quit()
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import unittest
|
||||
|
||||
from time import sleep
|
||||
|
||||
from appium import webdriver
|
||||
|
||||
|
||||
@@ -13,12 +15,17 @@ class MSiteDefaultBrowserAndroidUITests(unittest.TestCase):
|
||||
'deviceName': 'Android Emulator',
|
||||
'appPackage': 'com.android.browser',
|
||||
'appActivity': 'com.android.browser.BrowserActivity',
|
||||
'avd': 'samsung_galaxy_s6_6.0'
|
||||
'browserName': 'browser'
|
||||
}
|
||||
self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
|
||||
self.driver = webdriver.Remote('http://127.0.0.1:4444/wd/hub', desired_caps)
|
||||
|
||||
def test_open_url(self):
|
||||
self.driver.get('http://targeturl.com')
|
||||
self.driver.get('http://google.com')
|
||||
|
||||
search = self.driver.find_element_by_name('q')
|
||||
search.send_keys('butomo1989 docker-android')
|
||||
search.submit()
|
||||
sleep(2)
|
||||
|
||||
def tearDown(self):
|
||||
self.driver.quit()
|
||||
|
||||
|
After Width: | Height: | Size: 75 KiB |
|
Before Width: | Height: | Size: 448 KiB |
|
Before Width: | Height: | Size: 150 KiB |
|
Before Width: | Height: | Size: 244 KiB |
|
After Width: | Height: | Size: 146 KiB |
|
After Width: | Height: | Size: 229 KiB |
|
After Width: | Height: | Size: 54 KiB |
|
After Width: | Height: | Size: 261 KiB |
|
After Width: | Height: | Size: 183 KiB |
|
Before Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 341 KiB |
@@ -2,7 +2,6 @@
|
||||
# Bash version should >= 4 to be able to run this script.
|
||||
|
||||
IMAGE="butomo1989/docker-android"
|
||||
LATEST_BUILD_TOOL=25.0.2
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
read -p "Task (test|build|push|all) : " TASK
|
||||
@@ -93,8 +92,60 @@ get_android_versions
|
||||
get_processors
|
||||
|
||||
function test() {
|
||||
(export ANDROID_HOME=/root && export ANDROID_VERSION=5.0.1 && export API_LEVEL=21 \
|
||||
&& export PROCESSOR=x86 && export SYS_IMG=x86_64 && export IMG_TYPE=google_apis && nosetests -v)
|
||||
# Prepare needed parameter to run tests
|
||||
test_android_version=7.1.1
|
||||
test_api_level=25
|
||||
test_processor=x86
|
||||
test_sys_img=x86_64
|
||||
test_img_type=google_apis
|
||||
test_browser=chrome
|
||||
test_image=test_img
|
||||
test_container=test_con
|
||||
|
||||
# Run e2e tests
|
||||
# E2E tests must be run only for linux OS / x86 image to reduce duration of test execution
|
||||
if [ "$(uname -s)" == 'Linux' ] && [ "$E2E" = true ]; then
|
||||
echo "----BUILD TEST IMAGE----"
|
||||
docker build -t $test_image --build-arg ANDROID_VERSION=$test_android_version \
|
||||
--build-arg API_LEVEL=$test_api_level --build-arg PROCESSOR=$test_processor --build-arg SYS_IMG=$test_sys_img \
|
||||
--build-arg IMG_TYPE=$test_img_type --build-arg BROWSER=$test_browser -f docker/Emulator_x86 .
|
||||
|
||||
echo "----REMOVE OLD TEST CONTAINER----"
|
||||
docker kill $test_container && docker rm $test_container
|
||||
|
||||
echo "----PREPARE CONTAINER----"
|
||||
docker run --privileged -d -p 4723:4723 -p 6080:6080 -e APPIUM=True -e DEVICE="Samsung Galaxy S6" --name $test_container $test_image
|
||||
docker cp example/sample_apk $test_container:/root/tmp
|
||||
attempt=0
|
||||
while [ ${attempt} -le 10 ]; do
|
||||
attempt=$(($attempt + 1))
|
||||
output=$(docker ps | grep healthy | grep test_con | wc -l)
|
||||
if [[ "$output" == 1 ]]; then
|
||||
echo "Emulator is ready."
|
||||
break
|
||||
else
|
||||
echo "Waiting 10 seconds for emulator to be ready (attempt: $attempt)"
|
||||
sleep 10
|
||||
fi
|
||||
|
||||
if [[ $attempt == 10 ]]; then
|
||||
echo "Failed!"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
echo "----RUN E2E TESTS----"
|
||||
nosetests src/tests/e2e -v
|
||||
|
||||
echo "----REMOVE TEST CONTAINER----"
|
||||
docker kill $test_container && docker rm $test_container
|
||||
fi
|
||||
|
||||
# Run unit tests (After e2e test to get coverage result)
|
||||
echo "----UNIT TESTS----"
|
||||
(export ANDROID_HOME=/root && export ANDROID_VERSION=$test_android_version && export API_LEVEL=$test_api_level \
|
||||
&& export PROCESSOR=$test_processor && export SYS_IMG=$test_sys_img && export IMG_TYPE=$test_img_type \
|
||||
&& nosetests src/tests/unit -v)
|
||||
}
|
||||
|
||||
function build() {
|
||||
@@ -103,12 +154,24 @@ function build() {
|
||||
|
||||
# Build docker image(s)
|
||||
for p in "${processors[@]}"; do
|
||||
if [ "$p" == "x86" ]; then
|
||||
FILE_NAME=docker/Emulator_x86
|
||||
else
|
||||
FILE_NAME=docker/Emulator_arm
|
||||
fi
|
||||
|
||||
for v in "${versions[@]}"; do
|
||||
# Find image type
|
||||
# Find image type and default web browser
|
||||
if [ "$v" == "5.0.1" ] || [ "$v" == "5.1.1" ]; then
|
||||
IMG_TYPE=android
|
||||
IMG_TYPE=default
|
||||
BROWSER=browser
|
||||
elif [ "$v" == "6.0" ]; then
|
||||
# It is because there is no ARM EABI v7a System Image for 6.0
|
||||
IMG_TYPE=google_apis
|
||||
BROWSER=browser
|
||||
else
|
||||
IMG_TYPE=google_apis
|
||||
BROWSER=chrome
|
||||
fi
|
||||
echo "[BUILD] IMAGE TYPE: $IMG_TYPE"
|
||||
level=${list_of_levels[$v]}
|
||||
@@ -118,12 +181,11 @@ function build() {
|
||||
image_version="$IMAGE-$p-$v:$RELEASE"
|
||||
image_latest="$IMAGE-$p-$v:latest"
|
||||
echo "[BUILD] Image name: $image_version and $image_latest"
|
||||
docker build -t $image_version --build-arg ANDROID_VERSION=$v --build-arg BUILD_TOOL=$LATEST_BUILD_TOOL \
|
||||
--build-arg API_LEVEL=$level --build-arg PROCESSOR=$p --build-arg SYS_IMG=$sys_img \
|
||||
--build-arg IMG_TYPE=$IMG_TYPE .
|
||||
docker build -t $image_latest --build-arg ANDROID_VERSION=$v --build-arg BUILD_TOOL=$LATEST_BUILD_TOOL \
|
||||
--build-arg API_LEVEL=$level --build-arg PROCESSOR=$p --build-arg SYS_IMG=$sys_img \
|
||||
--build-arg IMG_TYPE=$IMG_TYPE .
|
||||
echo "[BUILD] Dockerfile: $FILE_NAME"
|
||||
docker build -t $image_version --build-arg ANDROID_VERSION=$v --build-arg API_LEVEL=$level \
|
||||
--build-arg PROCESSOR=$p --build-arg SYS_IMG=$sys_img --build-arg IMG_TYPE=$IMG_TYPE \
|
||||
--build-arg BROWSER=$BROWSER -f $FILE_NAME .
|
||||
docker tag $image_version $image_latest
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
read -p "Task (build|push|all) : " TASK
|
||||
else
|
||||
TASK=$1
|
||||
fi
|
||||
|
||||
if [ -z "$2" ]; then
|
||||
read -p "Release version: " RELEASE
|
||||
else
|
||||
RELEASE=$2
|
||||
fi
|
||||
|
||||
IMAGE="butomo1989/docker-android"
|
||||
FILE_NAME=docker/Real_device
|
||||
|
||||
image_version="$IMAGE-real-device:$RELEASE"
|
||||
image_latest="$IMAGE-real-device:latest"
|
||||
|
||||
function build() {
|
||||
echo "[BUILD] Image name: $image_version and $image_latest"
|
||||
echo "[BUILD] Dockerfile: $FILE_NAME"
|
||||
docker build -t $image_version -f $FILE_NAME .
|
||||
docker tag $image_version $image_latest
|
||||
}
|
||||
|
||||
function push() {
|
||||
echo "[PUSH] Image name: $image_version and $image_latest"
|
||||
docker push $image_version
|
||||
docker push $image_latest
|
||||
}
|
||||
|
||||
case $TASK in
|
||||
build)
|
||||
build
|
||||
;;
|
||||
push)
|
||||
push
|
||||
;;
|
||||
all)
|
||||
build
|
||||
push
|
||||
;;
|
||||
*)
|
||||
echo "Invalid environment! Valid options: test, build, push, all"
|
||||
;;
|
||||
esac
|
||||
@@ -1,3 +1,5 @@
|
||||
selenium==3.3.1
|
||||
Appium-Python-Client==0.24
|
||||
coverage==4.2
|
||||
mock==2.0.0
|
||||
nose==1.3.7
|
||||
|
||||
@@ -2,5 +2,6 @@ import os
|
||||
|
||||
ROOT = '/root'
|
||||
WORKDIR = os.path.dirname(__file__)
|
||||
CHROME_DRIVER = os.path.join(ROOT, 'chromedriver')
|
||||
CONFIG_FILE = os.path.join(WORKDIR, 'nodeconfig.json')
|
||||
LOGGING_FILE = os.path.join(WORKDIR, 'logging.conf')
|
||||
|
||||
@@ -5,13 +5,23 @@ import logging
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
from src import CONFIG_FILE, ROOT
|
||||
from src import CHROME_DRIVER, CONFIG_FILE, ROOT
|
||||
from src import log
|
||||
|
||||
log.init()
|
||||
logger = logging.getLogger('app')
|
||||
|
||||
|
||||
def symlink_force(target, link_name):
|
||||
try:
|
||||
os.symlink(target, link_name)
|
||||
except OSError as e:
|
||||
import errno
|
||||
if e.errno == errno.EEXIST:
|
||||
os.remove(link_name)
|
||||
os.symlink(target, link_name)
|
||||
|
||||
|
||||
def get_or_raise(env: str) -> str:
|
||||
"""
|
||||
Check if needed environment variables are given.
|
||||
@@ -26,7 +36,7 @@ def get_or_raise(env: str) -> str:
|
||||
return env_value
|
||||
|
||||
|
||||
def str_to_bool(str: str) -> bool:
|
||||
def convert_str_to_bool(str: str) -> bool:
|
||||
"""
|
||||
Convert string to boolean.
|
||||
|
||||
@@ -61,22 +71,9 @@ def prepare_avd(device: str, avd_name: str):
|
||||
:param device: Device name
|
||||
:param avd_name: Name of android virtual device / emulator
|
||||
"""
|
||||
cmd = 'echo no | android create avd -f -n {name} -t android-{api} -b {img_type}{sys_img}'.format(
|
||||
name=avd_name, api=API_LEVEL, img_type='google_apis/' if IMG_TYPE == 'google_apis' else '',
|
||||
sys_img=SYS_IMG)
|
||||
|
||||
# Link emulator skins
|
||||
skin_rsc_path = os.path.join(ROOT, 'devices', 'skins')
|
||||
logger.info('Skin ressource path: {rsc}'.format(rsc=skin_rsc_path))
|
||||
skin_dst_path = os.path.join(ANDROID_HOME, 'platforms', 'android-{api}'.format(api=API_LEVEL), 'skins')
|
||||
logger.info('Skin destination path: {dst}'.format(dst=skin_dst_path))
|
||||
for s in os.listdir(skin_rsc_path):
|
||||
os.symlink(os.path.join(skin_rsc_path, s), os.path.join(skin_dst_path, s))
|
||||
|
||||
# Hardware and its skin
|
||||
device_name_bash = device.replace(' ', '\ ')
|
||||
skin_name = device.replace(' ', '_').lower()
|
||||
logger.info('Device name in bash: {db}, Skin name: {skin}'.format(db=device_name_bash, skin=skin_name))
|
||||
|
||||
# For custom hardware profile
|
||||
profile_dst_path = os.path.join(ROOT, '.android', 'devices.xml')
|
||||
@@ -85,12 +82,21 @@ def prepare_avd(device: str, avd_name: str):
|
||||
profile_src_path = os.path.join(ROOT, 'devices', 'profiles', '{profile}.xml'.format(profile=skin_name))
|
||||
logger.info('Hardware profile resource path: {rsc}'.format(rsc=profile_src_path))
|
||||
logger.info('Hardware profile destination path: {dst}'.format(dst=profile_dst_path))
|
||||
os.symlink(profile_src_path, profile_dst_path)
|
||||
symlink_force(profile_src_path, profile_dst_path)
|
||||
|
||||
# Append command
|
||||
cmd += ' -d {device} -s {skin}'.format(device=device_name_bash, skin=skin_name)
|
||||
logger.info('AVD creation command: {cmd}'.format(cmd=cmd))
|
||||
subprocess.check_call(cmd, shell=True)
|
||||
avd_path = '/'.join([ANDROID_HOME, 'android_emulator'])
|
||||
creation_cmd = 'avdmanager create avd -f -n {name} -b {img_type}/{sys_img} -k "system-images;android-{api_lvl};' \
|
||||
'{img_type};{sys_img}" -d {device} -p {path}'.format(name=avd_name, img_type=IMG_TYPE, sys_img=SYS_IMG,
|
||||
api_lvl=API_LEVEL, device=device_name_bash,
|
||||
path=avd_path)
|
||||
logger.info('Command to create avd: {command}'.format(command=creation_cmd))
|
||||
subprocess.check_call(creation_cmd, shell=True)
|
||||
|
||||
skin_path = '/'.join([ANDROID_HOME, 'devices', 'skins', skin_name])
|
||||
config_path = '/'.join([avd_path, 'config.ini'])
|
||||
with open(config_path, 'a') as file:
|
||||
file.write('skin.path={sp}'.format(sp=skin_path))
|
||||
logger.info('Skin was added in config.ini')
|
||||
|
||||
|
||||
def appium_run(avd_name: str):
|
||||
@@ -101,23 +107,31 @@ def appium_run(avd_name: str):
|
||||
"""
|
||||
cmd = 'appium'
|
||||
|
||||
grid_connect = str_to_bool(str(os.getenv('CONNECT_TO_GRID', False)))
|
||||
default_web_browser = os.getenv('BROWSER')
|
||||
if default_web_browser == 'chrome':
|
||||
cmd += ' --chromedriver-executable {driver}'.format(driver=CHROME_DRIVER)
|
||||
|
||||
grid_connect = convert_str_to_bool(str(os.getenv('CONNECT_TO_GRID', False)))
|
||||
logger.info('Connect to selenium grid? {connect}'.format(connect=grid_connect))
|
||||
if grid_connect:
|
||||
local_ip = os.popen('ifconfig eth0 | grep \'inet addr:\' | cut -d: -f2 | awk \'{ print $1}\'').read().strip()
|
||||
try:
|
||||
appium_host = os.getenv('APPIUM_HOST', '127.0.0.1')
|
||||
mobile_web_test = convert_str_to_bool(str(os.getenv('MOBILE_WEB_TEST', False)))
|
||||
appium_host = os.getenv('APPIUM_HOST', local_ip)
|
||||
appium_port = int(os.getenv('APPIUM_PORT', 4723))
|
||||
selenium_host = os.getenv('SELENIUM_HOST', '172.17.0.1')
|
||||
selenium_port = int(os.getenv('SELENIUM_PORT', 4444))
|
||||
create_node_config(avd_name, appium_host, appium_port, selenium_host, selenium_port)
|
||||
browser_name = default_web_browser if mobile_web_test else 'android'
|
||||
create_node_config(avd_name, browser_name, appium_host, appium_port, selenium_host, selenium_port)
|
||||
cmd += ' --nodeconfig {file}'.format(file=CONFIG_FILE)
|
||||
except ValueError as v_err:
|
||||
logger.error(v_err)
|
||||
titel = 'Appium Server'
|
||||
subprocess.check_call('xterm -T "{titel}" -n "{titel}" -e \"{cmd}\"'.format(titel=titel, cmd=cmd), shell=True)
|
||||
title = 'Appium Server'
|
||||
subprocess.check_call('xterm -T "{title}" -n "{title}" -e \"{cmd}\"'.format(title=title, cmd=cmd), shell=True)
|
||||
|
||||
|
||||
def create_node_config(avd_name: str, appium_host: str, appium_port: int, selenium_host: str, selenium_port: int):
|
||||
def create_node_config(avd_name: str, browser_name: str, appium_host: str, appium_port: int, selenium_host: str,
|
||||
selenium_port: int):
|
||||
"""
|
||||
Create custom node config file in json format to be able to connect with selenium server.
|
||||
|
||||
@@ -133,7 +147,8 @@ def create_node_config(avd_name: str, appium_host: str, appium_port: int, seleni
|
||||
'platform': 'Android',
|
||||
'platformName': 'Android',
|
||||
'version': ANDROID_VERSION,
|
||||
'browserName': avd_name,
|
||||
'browserName': browser_name,
|
||||
'deviceName': avd_name,
|
||||
'maxInstances': 1,
|
||||
}
|
||||
],
|
||||
@@ -148,7 +163,8 @@ def create_node_config(avd_name: str, appium_host: str, appium_port: int, seleni
|
||||
'register': True,
|
||||
'registerCycle': 5000,
|
||||
'hubHost': selenium_host,
|
||||
'hubPort': selenium_port
|
||||
'hubPort': selenium_port,
|
||||
'unregisterIfStillDownAfter': 120000
|
||||
}
|
||||
}
|
||||
logger.info('Appium node config: {config}'.format(config=config))
|
||||
@@ -166,11 +182,12 @@ def run():
|
||||
|
||||
logger.info('Preparing emulator...')
|
||||
prepare_avd(device, avd_name)
|
||||
|
||||
logger.info('Run emulator...')
|
||||
cmd = 'emulator -avd {name}'.format(name=avd_name)
|
||||
cmd = 'emulator -avd {name} -gpu off'.format(name=avd_name)
|
||||
subprocess.Popen(cmd.split())
|
||||
|
||||
appium = str_to_bool(str(os.getenv('APPIUM', False)))
|
||||
appium = convert_str_to_bool(str(os.getenv('APPIUM', False)))
|
||||
if appium:
|
||||
logger.info('Run appium server...')
|
||||
appium_run(avd_name)
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ -z $REAL_DEVICE ]; then
|
||||
python3 -m src.app
|
||||
else
|
||||
CMD="appium"
|
||||
if [ ! -z "$CONNECT_TO_GRID" ]; then
|
||||
NODE_CONFIG_JSON="/root/src/nodeconfig.json"
|
||||
/root/generate_config.sh $NODE_CONFIG_JSON
|
||||
CMD+=" --nodeconfig $NODE_CONFIG_JSON"
|
||||
fi
|
||||
$CMD
|
||||
fi
|
||||
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ -z "$REAL_DEVICE"]; then
|
||||
echo "Container is using android emulator"
|
||||
else
|
||||
echo "Starting android screen mirro..."
|
||||
java -jar /root/asm.jar $ANDROID_HOME
|
||||
fi
|
||||
@@ -0,0 +1,47 @@
|
||||
#!/bin/bash
|
||||
|
||||
function start() {
|
||||
mkdir -p $VIDEO_PATH
|
||||
name="$(date '+%d_%m_%Y_%H_%M_%S').mp4"
|
||||
echo "Start video recording"
|
||||
ffmpeg -video_size 1599x899 -framerate 15 -f x11grab -i $DISPLAY $VIDEO_PATH/$name -y
|
||||
}
|
||||
|
||||
function stop() {
|
||||
echo "Stop video recording"
|
||||
kill $(ps -ef | grep [f]fmpeg | awk '{print $2}')
|
||||
}
|
||||
|
||||
function auto_record() {
|
||||
echo "Auto record: $AUTO_RECORD"
|
||||
sleep 6
|
||||
|
||||
while [ $AUTO_RECORD == "True" ]; do
|
||||
# Check if there is test running
|
||||
no_test=true
|
||||
while $no_test; do
|
||||
task=$(curl -s localhost:4723/wd/hub/sessions | jq -r '.value')
|
||||
if [ "$task" == "" ] || [ "$task" == "[]" ]; then
|
||||
sleep .5
|
||||
else
|
||||
start &
|
||||
no_test=false
|
||||
fi
|
||||
done
|
||||
|
||||
# Check if test is finished
|
||||
while [ $no_test == false ]; do
|
||||
task=$(curl -s localhost:4723/wd/hub/sessions | jq -r '.value')
|
||||
if [ "$task" == "" ] || [ "$task" == "[]" ]; then
|
||||
stop
|
||||
no_test=true
|
||||
else
|
||||
sleep .5
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
echo "Auto recording is disabled!"
|
||||
}
|
||||
|
||||
$@
|
||||
@@ -1,54 +0,0 @@
|
||||
"""Unit test to test app."""
|
||||
import os
|
||||
from unittest import TestCase
|
||||
|
||||
import mock
|
||||
|
||||
from src import app
|
||||
|
||||
|
||||
class TestApp(TestCase):
|
||||
"""Unit test class to test other methods in the app."""
|
||||
|
||||
def test_valid_env(self):
|
||||
key = 'ENV_1'
|
||||
os.environ[key] = 'test'
|
||||
app.get_or_raise(key)
|
||||
del os.environ[key]
|
||||
|
||||
def test_invalid_env(self):
|
||||
with self.assertRaises(RuntimeError):
|
||||
app.get_or_raise('ENV_2')
|
||||
|
||||
def test_valid_bool(self):
|
||||
self.assertEqual(app.str_to_bool('True'), True)
|
||||
self.assertEqual(app.str_to_bool('t'), True)
|
||||
self.assertEqual(app.str_to_bool('1'), True)
|
||||
self.assertEqual(app.str_to_bool('YES'), True)
|
||||
|
||||
def test_invalid_bool(self):
|
||||
self.assertEqual(app.str_to_bool(''), False)
|
||||
self.assertEqual(app.str_to_bool('test'), False)
|
||||
|
||||
def test_invalid_format(self):
|
||||
self.assertEqual(app.str_to_bool(True), None)
|
||||
|
||||
@mock.patch('src.app.prepare_avd')
|
||||
@mock.patch('subprocess.Popen')
|
||||
def test_run_with_appium(self, mocked_avd, mocked_subprocess):
|
||||
with mock.patch('src.app.appium_run') as mocked_appium:
|
||||
os.environ['APPIUM'] = str(True)
|
||||
app.run()
|
||||
self.assertTrue(mocked_avd.called)
|
||||
self.assertTrue(mocked_subprocess.called)
|
||||
self.assertTrue(mocked_appium.called)
|
||||
|
||||
@mock.patch('src.app.prepare_avd')
|
||||
@mock.patch('subprocess.Popen')
|
||||
def test_run_withhout_appium(self, mocked_avd, mocked_subprocess):
|
||||
with mock.patch('src.app.appium_run') as mocked_appium:
|
||||
os.environ['APPIUM'] = str(False)
|
||||
app.run()
|
||||
self.assertTrue(mocked_avd.called)
|
||||
self.assertTrue(mocked_subprocess.called)
|
||||
self.assertFalse(mocked_appium.called)
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
"""e2e test to test sample android application inside docker-android"""
|
||||
from unittest import TestCase
|
||||
|
||||
from appium import webdriver
|
||||
|
||||
|
||||
class TestE2EAndroidApk(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
desired_caps = {
|
||||
'platformName': 'Android',
|
||||
'deviceName': 'Android Emulator',
|
||||
'automationName': 'UIAutomator2',
|
||||
'app': '/root/tmp/sample_apk_debug.apk'
|
||||
}
|
||||
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
|
||||
|
||||
def test_calculation(self):
|
||||
text_fields = self.driver.find_elements_by_class_name('android.widget.EditText')
|
||||
text_fields[0].send_keys(4)
|
||||
text_fields[1].send_keys(6)
|
||||
|
||||
btn_calculate = self.driver.find_element_by_class_name('android.widget.Button')
|
||||
btn_calculate.click()
|
||||
|
||||
self.assertEqual('10', text_fields[2].text)
|
||||
|
||||
def tearDown(self):
|
||||
self.driver.quit()
|
||||
@@ -0,0 +1,34 @@
|
||||
"""e2e test to test chrome application inside docker-android"""
|
||||
from unittest import TestCase
|
||||
|
||||
from appium import webdriver
|
||||
|
||||
|
||||
class TestE2EChrome(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
desired_caps = {
|
||||
'platformName': 'Android',
|
||||
'deviceName': 'Android Emulator',
|
||||
'appPackage': 'com.android.chrome',
|
||||
'appActivity': 'com.google.android.apps.chrome.Main',
|
||||
'browserName': 'chrome'
|
||||
}
|
||||
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
|
||||
|
||||
def test_open_url(self):
|
||||
self.driver.get('http://google.com')
|
||||
|
||||
# Handle Welcome Home
|
||||
self.driver.switch_to.context('NATIVE_APP')
|
||||
self.driver.find_element_by_id('terms_accept').click()
|
||||
self.driver.find_element_by_id('negative_button').click()
|
||||
|
||||
# Search for Github
|
||||
self.driver.switch_to.context('CHROMIUM')
|
||||
search = self.driver.find_element_by_name('q')
|
||||
search.send_keys('butomo1989 docker-android')
|
||||
search.submit()
|
||||
|
||||
def tearDown(self):
|
||||
self.driver.quit()
|
||||
@@ -1,42 +0,0 @@
|
||||
"""Unit test for android virtual device creation.py."""
|
||||
import os
|
||||
from unittest import TestCase
|
||||
|
||||
import mock
|
||||
|
||||
from src import app
|
||||
|
||||
|
||||
@mock.patch('subprocess.check_call')
|
||||
@mock.patch('os.symlink')
|
||||
class TestAvd(TestCase):
|
||||
"""Unit test class to test method create_avd."""
|
||||
|
||||
def setUp(self):
|
||||
self.avd_name = 'test_avd'
|
||||
|
||||
def test_nexus_avd_as_default(self, mocked_suprocess, mocked_sys_link):
|
||||
with mock.patch('os.listdir') as mocked_list_dir:
|
||||
mocked_list_dir.return_value = ['file1', 'file2']
|
||||
self.assertFalse(mocked_list_dir.called)
|
||||
self.assertFalse(mocked_sys_link.called)
|
||||
self.assertFalse(mocked_suprocess.called)
|
||||
app.prepare_avd('Nexus 5', self.avd_name)
|
||||
self.assertTrue(mocked_list_dir.called)
|
||||
self.assertTrue(mocked_sys_link.called)
|
||||
self.assertTrue(mocked_suprocess.called)
|
||||
|
||||
def test_samsung_avd(self, mocked_suprocess, mocked_sys_link):
|
||||
with mock.patch('os.listdir') as mocked_list_dir:
|
||||
mocked_list_dir.return_value = ['file1', 'file2']
|
||||
self.assertFalse(mocked_list_dir.called)
|
||||
self.assertFalse(mocked_sys_link.called)
|
||||
self.assertFalse(mocked_suprocess.called)
|
||||
app.prepare_avd('Samsung Galaxy S6', self.avd_name)
|
||||
self.assertTrue(mocked_list_dir.called)
|
||||
self.assertTrue(mocked_sys_link.called)
|
||||
self.assertTrue(mocked_suprocess.called)
|
||||
|
||||
def tearDown(self):
|
||||
if os.getenv('DEVICE'):
|
||||
del os.environ['DEVICE']
|
||||
@@ -0,0 +1,73 @@
|
||||
"""Unit test to test app."""
|
||||
import os
|
||||
from unittest import TestCase
|
||||
|
||||
import mock
|
||||
|
||||
from src import app
|
||||
|
||||
|
||||
class TestApp(TestCase):
|
||||
"""Unit test class to test other methods in the app."""
|
||||
|
||||
@classmethod
|
||||
def test_symlink(self):
|
||||
res = os.path.join('testFile1.txt')
|
||||
dest = os.path.join('link_testFile1.txt')
|
||||
open(res, 'a').close()
|
||||
app.symlink_force(res, dest)
|
||||
os.remove(res)
|
||||
os.remove(dest)
|
||||
|
||||
@classmethod
|
||||
def test_symlink_already_exist(self):
|
||||
res = os.path.join('testFile1.txt')
|
||||
dest = os.path.join('link_testFile1.txt')
|
||||
open(res, 'a').close()
|
||||
open(dest, 'a').close()
|
||||
app.symlink_force(res, dest)
|
||||
os.remove(res)
|
||||
os.remove(dest)
|
||||
|
||||
def test_valid_env(self):
|
||||
key = 'ENV_1'
|
||||
os.environ[key] = 'test'
|
||||
app.get_or_raise(key)
|
||||
del os.environ[key]
|
||||
|
||||
def test_invalid_env(self):
|
||||
with self.assertRaises(RuntimeError):
|
||||
app.get_or_raise('ENV_2')
|
||||
|
||||
def test_valid_bool(self):
|
||||
self.assertEqual(app.convert_str_to_bool('True'), True)
|
||||
self.assertEqual(app.convert_str_to_bool('t'), True)
|
||||
self.assertEqual(app.convert_str_to_bool('1'), True)
|
||||
self.assertEqual(app.convert_str_to_bool('YES'), True)
|
||||
|
||||
def test_invalid_bool(self):
|
||||
self.assertEqual(app.convert_str_to_bool(''), False)
|
||||
self.assertEqual(app.convert_str_to_bool('test'), False)
|
||||
|
||||
def test_invalid_format(self):
|
||||
self.assertEqual(app.convert_str_to_bool(True), None)
|
||||
|
||||
@mock.patch('src.app.prepare_avd')
|
||||
@mock.patch('subprocess.Popen')
|
||||
def test_run_with_appium(self, mocked_avd, mocked_subprocess):
|
||||
with mock.patch('src.app.appium_run') as mocked_appium:
|
||||
os.environ['APPIUM'] = str(True)
|
||||
app.run()
|
||||
self.assertTrue(mocked_avd.called)
|
||||
self.assertTrue(mocked_subprocess.called)
|
||||
self.assertTrue(mocked_appium.called)
|
||||
|
||||
@mock.patch('src.app.prepare_avd')
|
||||
@mock.patch('subprocess.Popen')
|
||||
def test_run_withhout_appium(self, mocked_avd, mocked_subprocess):
|
||||
with mock.patch('src.app.appium_run') as mocked_appium:
|
||||
os.environ['APPIUM'] = str(False)
|
||||
app.run()
|
||||
self.assertTrue(mocked_avd.called)
|
||||
self.assertTrue(mocked_subprocess.called)
|
||||
self.assertFalse(mocked_appium.called)
|
||||
@@ -14,6 +14,14 @@ class TestAppium(TestCase):
|
||||
os.environ['CONNECT_TO_GRID'] = str(True)
|
||||
self.avd_name = 'test_avd'
|
||||
|
||||
@mock.patch('subprocess.check_call')
|
||||
def test_chrome_driver(self, mocked_subprocess):
|
||||
os.environ['CONNECT_TO_GRID'] = str(False)
|
||||
os.environ['BROWSER'] = 'chrome'
|
||||
self.assertFalse(mocked_subprocess.called)
|
||||
app.appium_run(self.avd_name)
|
||||
self.assertTrue(mocked_subprocess.called)
|
||||
|
||||
@mock.patch('subprocess.check_call')
|
||||
def test_without_selenium_grid(self, mocked_subprocess):
|
||||
os.environ['CONNECT_TO_GRID'] = str(False)
|
||||
@@ -21,30 +29,36 @@ class TestAppium(TestCase):
|
||||
app.appium_run(self.avd_name)
|
||||
self.assertTrue(mocked_subprocess.called)
|
||||
|
||||
@mock.patch('os.popen')
|
||||
@mock.patch('subprocess.check_call')
|
||||
def test_with_selenium_grid(self, mocked_subprocess):
|
||||
def test_with_selenium_grid(self, mocked_os, mocked_subprocess):
|
||||
with mock.patch('src.app.create_node_config') as mocked_config:
|
||||
self.assertFalse(mocked_config.called)
|
||||
self.assertFalse(mocked_os.called)
|
||||
self.assertFalse(mocked_subprocess.called)
|
||||
app.appium_run(self.avd_name)
|
||||
self.assertTrue(mocked_config.called)
|
||||
self.assertTrue(mocked_os.called)
|
||||
self.assertTrue(mocked_subprocess.called)
|
||||
|
||||
@mock.patch('os.popen')
|
||||
@mock.patch('subprocess.check_call')
|
||||
def test_invalid_integer(self, mocked_subprocess):
|
||||
def test_invalid_integer(self, mocked_os, mocked_subprocess):
|
||||
os.environ['APPIUM_PORT'] = 'test'
|
||||
with mock.patch('src.app.create_node_config') as mocked_config:
|
||||
self.assertFalse(mocked_config.called)
|
||||
self.assertFalse(mocked_os.called)
|
||||
self.assertFalse(mocked_subprocess.called)
|
||||
app.appium_run(self.avd_name)
|
||||
self.assertFalse(mocked_config.called)
|
||||
self.assertTrue(mocked_os.called)
|
||||
self.assertTrue(mocked_subprocess.called)
|
||||
self.assertRaises(ValueError)
|
||||
|
||||
def test_config_creation(self):
|
||||
from src import CONFIG_FILE
|
||||
self.assertFalse(os.path.exists(CONFIG_FILE))
|
||||
app.create_node_config('test', '127.0.0.1', 4723, '127.0.0.1', 4444)
|
||||
app.create_node_config('test', 'android', '127.0.0.1', 4723, '127.0.0.1', 4444)
|
||||
self.assertTrue(os.path.exists(CONFIG_FILE))
|
||||
os.remove(CONFIG_FILE)
|
||||
|
||||
@@ -52,3 +66,5 @@ class TestAppium(TestCase):
|
||||
del os.environ['CONNECT_TO_GRID']
|
||||
if os.getenv('APPIUM_PORT'):
|
||||
del os.environ['APPIUM_PORT']
|
||||
if os.getenv('BROWSER'):
|
||||
del os.environ['BROWSER']
|
||||
@@ -0,0 +1,38 @@
|
||||
"""Unit test for android virtual device creation.py."""
|
||||
import os
|
||||
from unittest import TestCase
|
||||
|
||||
import mock
|
||||
|
||||
from src import app
|
||||
|
||||
|
||||
@mock.patch('subprocess.check_call')
|
||||
class TestAvd(TestCase):
|
||||
"""Unit test class to test method create_avd."""
|
||||
|
||||
def setUp(self):
|
||||
self.avd_name = 'test_avd'
|
||||
|
||||
@mock.patch("builtins.open", create=True)
|
||||
def test_nexus_avd_as_default(self, mocked_suprocess, mocked_open):
|
||||
self.assertFalse(mocked_suprocess.called)
|
||||
self.assertFalse(mocked_open.called)
|
||||
app.prepare_avd('Nexus 5', self.avd_name)
|
||||
self.assertTrue(mocked_suprocess.called)
|
||||
self.assertTrue(mocked_open.called)
|
||||
|
||||
@mock.patch('os.symlink')
|
||||
@mock.patch("builtins.open", create=True)
|
||||
def test_samsung_avd(self, mocked_suprocess, mocked_sys_link, mocked_open):
|
||||
self.assertFalse(mocked_sys_link.called)
|
||||
self.assertFalse(mocked_suprocess.called)
|
||||
self.assertFalse(mocked_open.called)
|
||||
app.prepare_avd('Samsung Galaxy S6', self.avd_name)
|
||||
self.assertTrue(mocked_sys_link.called)
|
||||
self.assertTrue(mocked_suprocess.called)
|
||||
self.assertTrue(mocked_open.called)
|
||||
|
||||
def tearDown(self):
|
||||
if os.getenv('DEVICE'):
|
||||
del os.environ['DEVICE']
|
||||
@@ -2,33 +2,56 @@
|
||||
nodaemon=true
|
||||
logfile=%(ENV_LOG_PATH)s/supervisord.log
|
||||
childlogdir=%(ENV_LOG_PATH)s
|
||||
priority=1
|
||||
|
||||
[program:xvfb]
|
||||
command=/usr/bin/Xvfb %(ENV_DISPLAY)s -screen %(ENV_SCREEN)s %(ENV_SCREEN_WIDTH)sx%(ENV_SCREEN_HEIGHT)sx%(ENV_SCREEN_DEPTH)s
|
||||
stdout_logfile=%(ENV_LOG_PATH)s/xvfb.stdout.log
|
||||
stderr_logfile=%(ENV_LOG_PATH)s/xvfb.stderr.log
|
||||
priority=1
|
||||
|
||||
[program:openbox]
|
||||
command=/usr/bin/openbox-session
|
||||
stdout_logfile=%(ENV_LOG_PATH)s/openbox.stdout.log
|
||||
stderr_logfile=%(ENV_LOG_PATH)s/openbox.stderr.log
|
||||
priority=2
|
||||
|
||||
[program:x11vnc]
|
||||
command=/usr/bin/x11vnc -display %(ENV_DISPLAY)s -nopw -forever -shared
|
||||
stdout_logfile=%(ENV_LOG_PATH)s/x11vnc.stdout.log
|
||||
stderr_logfile=%(ENV_LOG_PATH)s/x11vnc.stderr.log
|
||||
priority=2
|
||||
|
||||
[program:novnc]
|
||||
command=./noVNC/utils/launch.sh --vnc localhost:%(ENV_LOCAL_PORT)s --listen %(ENV_TARGET_PORT)s
|
||||
stdout_logfile=%(ENV_LOG_PATH)s/novnc.stdout.log
|
||||
stderr_logfile=%(ENV_LOG_PATH)s/novnc.stderr.log
|
||||
priority=2
|
||||
|
||||
[program:port-forward]
|
||||
command=./src/port_forward.sh
|
||||
autorestart=false
|
||||
priority=1
|
||||
|
||||
;startsecs to fix "not expected" error. see: https://github.com/Supervisor/supervisor/issues/212#issuecomment-47933372
|
||||
[program:android-screen-mirror]
|
||||
command=./src/asm.sh
|
||||
autorestart=false
|
||||
startsecs=0
|
||||
stdout_logfile=%(ENV_LOG_PATH)s/android-screen-mirror.stdout.log
|
||||
stderr_logfile=%(ENV_LOG_PATH)s/android-screen-mirror.stderr.log
|
||||
priority=3
|
||||
|
||||
[program:docker-appium]
|
||||
command=python3 -m src.app
|
||||
command=./src/appium.sh
|
||||
autorestart=false
|
||||
stdout_logfile=%(ENV_LOG_PATH)s/docker-android.stdout.log
|
||||
stderr_logfile=%(ENV_LOG_PATH)s/docker-android.stderr.log
|
||||
priority=4
|
||||
|
||||
[program:auto-recording]
|
||||
command=./src/record.sh auto_record
|
||||
autorestart=false
|
||||
stdout_logfile=%(ENV_LOG_PATH)s/video-recording.stdout.log
|
||||
stderr_logfile=%(ENV_LOG_PATH)s/video-recording.stderr.log
|
||||
priority=4
|
||||
|
||||
@@ -5,10 +5,15 @@ if [ -z "$TRAVIS_TAG" ]; then
|
||||
echo "UNIT TEST ONLY"
|
||||
bash release.sh test all all 0.1
|
||||
else
|
||||
echo "Log in to docker hub"
|
||||
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
|
||||
echo "[Version: $ANDROID_VERSION] RUN UNIT TEST, BUILD DOCKER IMAGES AND PUSH THOSE TO DOCKER HUB"
|
||||
bash release.sh all $ANDROID_VERSION all $TRAVIS_TAG
|
||||
if [ ! -z "$ANDROID_VERSION" ]; then
|
||||
echo "Log in to docker hub"
|
||||
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
|
||||
echo "[Version: $ANDROID_VERSION] RUN UNIT TEST, BUILD DOCKER IMAGES AND PUSH THOSE TO DOCKER HUB"
|
||||
bash release.sh all $ANDROID_VERSION all $TRAVIS_TAG
|
||||
elif [ ! -z "$REAL_DEVICE" ]; then
|
||||
echo "[SUPPORT FOR REAL DEVICE: BUILD DOCKER IMAGES AND PUSH THOSE TO DOCKER HUB ]"
|
||||
bash release_real.sh all $TRAVIS_TAG
|
||||
fi
|
||||
echo "Log out of docker hub"
|
||||
docker logout
|
||||
fi
|
||||
|
||||