Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
e325706d17 | ||
|
|
3679a9bd48 | ||
|
|
666489987b | ||
|
|
b785d70389 | ||
|
|
f1663eb05e | ||
|
|
e46800e322 | ||
|
|
d2843d7260 | ||
|
|
67726cf735 | ||
|
|
e59c28ebd8 | ||
|
|
7ce3cfba96 | ||
|
|
63e64d219b | ||
|
|
2ef82e3894 |
@@ -10,6 +10,14 @@ 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
|
||||
|
||||
script: bash travis.sh
|
||||
|
||||
after_success:
|
||||
|
||||
@@ -3,29 +3,31 @@ Docker-Android
|
||||
|
||||
[](https://travis-ci.org/butomo1989/docker-android)
|
||||
[](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)
|
||||
|
||||
Android in docker solution with noVNC supported
|
||||
Docker-Android is a docker image built to be used for everything related to mobile website testing and Android project.
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
Docker is installed in your system.
|
||||
Samsung Device | Google Device
|
||||
:---------------------------:|:---------------------------:
|
||||
![][docker android samsung] | ![][docker android nexus]
|
||||
|
||||
Purpose
|
||||
-------
|
||||
|
||||
1. Build android project / application and run unit test
|
||||
2. Run UI Test for mobile website with appium framework
|
||||
3. Run UI Test for mobile application with different frameworks (appium, espresso, etc.)
|
||||
4. Simulate Short Message Service (SMS)
|
||||
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
|
||||
|
||||
Features
|
||||
--------
|
||||
Advantages compare with other docker-android projects
|
||||
-----------------------------------------------------
|
||||
|
||||
1. Android emulator with different devices
|
||||
2. latest build-tool (version 25.0.2)
|
||||
3. noVNC to see what happen inside docker container
|
||||
4. Appium server for automation test framework and it is able to connect with selenium grid
|
||||
1. noVNC to see what happen inside docker container
|
||||
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. Open source with more features coming (monkey test, support real devices with screen mirroring and video recording)
|
||||
|
||||
List of Docker images
|
||||
---------------------
|
||||
@@ -35,31 +37,49 @@ List of Docker images
|
||||
|Linux|5.0.1|21|butomo1989/docker-android-x86-5.0.1|[](https://microbadger.com/images/butomo1989/docker-android-x86-5.0.1 "Get your own image badge on microbadger.com")|
|
||||
|Linux|5.1.1|22|butomo1989/docker-android-x86-5.1.1|[](https://microbadger.com/images/butomo1989/docker-android-x86-5.1.1 "Get your own image badge on microbadger.com")|
|
||||
|Linux|6.0|23|butomo1989/docker-android-x86-6.0|[](https://microbadger.com/images/butomo1989/docker-android-x86-6.0 "Get your own image badge on microbadger.com")|
|
||||
|Linux|7.0|24|*TODO* because still have a Bug||
|
||||
|Linux|7.1.1|25|*TODO* because still have a Bug||
|
||||
|Linux|7.0|24|butomo1989/docker-android-x86-7.0|[](https://microbadger.com/images/butomo1989/docker-android-x86-7.0 "Get your own image badge on microbadger.com")|
|
||||
|Linux|7.1.1|25|butomo1989/docker-android-x86-7.1.1|[](https://microbadger.com/images/butomo1989/docker-android-x86-7.1.1 "Get your own image badge on microbadger.com")|
|
||||
|OSX / Windows|5.0.1|21|butomo1989/docker-android-arm-5.0.1|[](https://microbadger.com/images/butomo1989/docker-android-arm-5.0.1 "Get your own image badge on microbadger.com")|
|
||||
|OSX / Windows|5.1.1|22|butomo1989/docker-android-arm-5.1.1|[](https://microbadger.com/images/butomo1989/docker-android-arm-5.1.1 "Get your own image badge on microbadger.com")|
|
||||
|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|*TODO* because still have a Bug||
|
||||
|OSX / Windows|7.1.1|25|*TODO* because still have a Bug||
|
||||
|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")|
|
||||
|
||||
List of Devices
|
||||
---------------
|
||||
|
||||
Type | Device Name
|
||||
----- | -----
|
||||
Phone | Samsung Galaxy S6
|
||||
Phone | Nexus 4
|
||||
Phone | Nexus 5
|
||||
Phone | Nexus One
|
||||
Phone | Nexus S
|
||||
Tablet | Nexus 7
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
Docker is installed in your system.
|
||||
|
||||
Quick Start
|
||||
-----------
|
||||
|
||||
1. Enable **Virtualization** under **System Setup** in **BIOS**. (It is only for Ubuntu OS. If you use different OS, you can skip this step).
|
||||
1. Run docker-android
|
||||
|
||||
2. Run docker-android
|
||||
- For ***Linux OS***, please use image name that contains "x86"
|
||||
|
||||
```bash
|
||||
docker run --privileged -d -p 6080:6080 -p 4723:4723 -p 5554:5554 -p 5555:5555 -e DEVICE="Samsung Galaxy S6" -e APPIUM=False --name android-container butomo1989/docker-android-x86-5.0.1
|
||||
```
|
||||
```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
|
||||
```
|
||||
|
||||
**Optional arguments**
|
||||
- For ***OSX*** and ***Windows OS***, please use image name that contains "arm"
|
||||
|
||||
-v <android_project_or_apk>:/root : You need to share volume or apk file if for example you want to build the android project inside docker container or you want to run UI test by using appium.
|
||||
-e APPIUM=True: If you want to use appium as UI test framework to test mobile website or android application
|
||||
```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-arm-7.1.1
|
||||
```
|
||||
|
||||
3. Verify the ip address of docker-machine.
|
||||
2. Verify the ip address of docker host.
|
||||
|
||||
- For OSX, you can find out by using following command:
|
||||
|
||||
@@ -69,45 +89,53 @@ Quick Start
|
||||
|
||||
- For different OS, localhost should work.
|
||||
|
||||
4. Open ***http://docker-machine-ip-address:6080*** from web browser.
|
||||
3. Open ***http://docker-host-ip-address:6080*** from web browser.
|
||||
|
||||
![][noVNC]
|
||||
Run Appium Server
|
||||
-----------------
|
||||
|
||||
Appium is automation test framework to test mobile website and mobile application, including android. To be able to use appium, you need to run appium-server. You run appium server inside docker-android container by ***opening port 4723*** and ***passing an environment variable APPIUM=TRUE***.
|
||||
|
||||
Connect to Selenium Grid
|
||||
------------------------
|
||||
```bash
|
||||
docker run --privileged -d -p 6080:6080 -p 5554:5554 -p 5555:5555 -p 4723:4723 -e DEVICE="Samsung Galaxy S6" -e APPIUM=True --name android-container butomo1989/docker-android-x86-7.1.1
|
||||
```
|
||||
|
||||
This feature can be used only if you set **APPIUM=True** in environment variable.
|
||||
### Connect to Selenium Grid
|
||||
|
||||
**Arguments**
|
||||
It is also possible to connect appium server that run inside docker-android with selenium grid by passing following environment variables:
|
||||
|
||||
-e CONNECT_TO_GRID=True : to connect appium server to your selenium grid.
|
||||
-e APPIUM_HOST="<host_ip_address>": where / on which instance appium server is running. Default value: 127.0.0.1
|
||||
-e APPIUM_PORT=<port_number>: which port appium server is running. Default port: 4723
|
||||
-e SELENIUM_HOST="<host_ip_address>": where / on which instance selenium grid is running. Default value: 172.17.0.1
|
||||
-e SELENIUM_PORT=<port_number>: which port selenium grid is running. default port: 4444
|
||||
- CONNECT\_TO\_GRID=True
|
||||
- APPIUM_HOST="\<host\_ip\_address>"
|
||||
- APPIUM_PORT=\<port\_number>
|
||||
- SELENIUM_HOST="\<host\_ip\_address>"
|
||||
- SELENIUM_PORT=\<port\_number>
|
||||
|
||||
![][connect to grid 1] ![][connect to grid 2]
|
||||
To run tests for mobile browser, following parameter can be passed:
|
||||
|
||||
List of Devices
|
||||
---------------
|
||||
- MOBILE\_WEB\_TEST=True
|
||||
|
||||
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
|
||||
```bash
|
||||
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
|
||||
```
|
||||
|
||||
![][galaxy s6] ![][nexus 5]
|
||||
### Share Volume
|
||||
|
||||
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 -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
|
||||
```
|
||||
|
||||
### Docker-Compose
|
||||
|
||||
![][compose]
|
||||
![][connected_devices]
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
Control android emulator outside container
|
||||
------------------------------------------
|
||||
@@ -154,7 +182,7 @@ SMS Simulation
|
||||
docker exec -it android-container adb emu sms send <phone_number> <message>
|
||||
```
|
||||
|
||||
3. You can also integrate it inside project using [adblib].
|
||||
3. You can also integrate it inside project using adb library.
|
||||
|
||||
![][sms]
|
||||
|
||||
@@ -163,14 +191,18 @@ Troubleshooting
|
||||
All logs inside container are stored under folder **/var/log/supervisor**. you can print out log file by using **docker exec**. Example:
|
||||
|
||||
```bash
|
||||
docker exec -it android-container tail -f /var/log/supervisor/docker-appium.stdout.log
|
||||
docker exec -it android-container tail -f /var/log/supervisor/docker-android.stdout.log
|
||||
```
|
||||
|
||||
[noVNC]: <images/noVNC.png> "login with noVNC to see what happen inside container"
|
||||
[connect to grid 1]: <images/appium_with_selenium_grid_01.png>
|
||||
[connect to grid 2]: <images/appium_with_selenium_grid_02.png>
|
||||
[galaxy s6]: <images/run_under_galaxy_s6.png>
|
||||
[nexus 5]: <images/run_under_nexus_5.png>
|
||||
[appium]: <https://appium.io>
|
||||
[espresso]: <https://google.github.io/android-testing-support-library/docs/espresso/>
|
||||
[robotium]: <https://github.com/RobotiumTech/robotium>
|
||||
[docker android samsung]: <images/docker_android_samsung.png>
|
||||
[docker android nexus]: <images/docker_android_nexus.png>
|
||||
[compose]: <images/compose.png>
|
||||
[connected_devices]: <images/connected_devices.png>
|
||||
[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>
|
||||
[adblib]: <https://github.com/tananaev/adblib>
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
# 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.4.0
|
||||
ports:
|
||||
- "4444:4444"
|
||||
|
||||
# Docker-Android for Android application testing
|
||||
nexus_7.1.1:
|
||||
image: butomo1989/docker-android-x86-7.1.1
|
||||
privileged: true
|
||||
# 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
|
||||
# Increase scale number if needed
|
||||
scale: 1
|
||||
ports:
|
||||
- 6080
|
||||
environment:
|
||||
- DEVICE=Nexus 5
|
||||
- CONNECT_TO_GRID=True
|
||||
- APPIUM=true
|
||||
- SELENIUM_HOST=selenium_hub
|
||||
|
||||
# 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
|
||||
ports:
|
||||
- 6080
|
||||
environment:
|
||||
- DEVICE=Samsung Galaxy S6
|
||||
- CONNECT_TO_GRID=True
|
||||
- APPIUM=true
|
||||
- SELENIUM_HOST=selenium_hub
|
||||
- MOBILE_WEB_TEST=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
|
||||
ports:
|
||||
- 6080
|
||||
environment:
|
||||
- DEVICE=Samsung Galaxy S6
|
||||
- CONNECT_TO_GRID=True
|
||||
- APPIUM=true
|
||||
- SELENIUM_HOST=selenium_hub
|
||||
- MOBILE_WEB_TEST=True
|
||||
@@ -0,0 +1,134 @@
|
||||
FROM appium/appium:1.6.6-beta-p0
|
||||
|
||||
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
|
||||
#==================
|
||||
RUN apt-get -qqy update && apt-get -qqy install --no-install-recommends \
|
||||
xterm \
|
||||
supervisor \
|
||||
socat \
|
||||
x11vnc \
|
||||
openbox \
|
||||
menu \
|
||||
python-numpy \
|
||||
net-tools \
|
||||
&& 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 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}
|
||||
|
||||
#==============================================
|
||||
# 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 \
|
||||
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.6.6-beta-p0
|
||||
|
||||
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
|
||||
@@ -51,16 +39,10 @@ WORKDIR /root
|
||||
# ubuntu-vm-builder
|
||||
# bridge-utils
|
||||
#==================
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
wget \
|
||||
unzip \
|
||||
curl \
|
||||
RUN apt-get -qqy update && apt-get -qqy install --no-install-recommends \
|
||||
xterm \
|
||||
supervisor \
|
||||
openjdk-8-jdk \
|
||||
libqt5webkit5 \
|
||||
socat \
|
||||
xvfb \
|
||||
x11vnc \
|
||||
openbox \
|
||||
menu \
|
||||
@@ -79,57 +61,45 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
#=======
|
||||
ENV NOVNC_SHA="b403cb92fb8de82d04f305b4f14fa978003890d7" \
|
||||
WEBSOCKIFY_SHA="558a6439f14b0d85a31145541745e25c255d576b"
|
||||
RUN wget -O noVNC.zip "https://github.com/kanaka/noVNC/archive/${NOVNC_SHA}.zip" \
|
||||
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 -O websockify.zip "https://github.com/kanaka/websockify/archive/${WEBSOCKIFY_SHA}.zip" \
|
||||
&& 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 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 -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 update && apt-get install -y 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
|
||||
RUN echo y | android update sdk --no-ui -a --filter build-tools-${BUILD_TOOL}
|
||||
SYS_IMG=$SYS_IMG \
|
||||
IMG_TYPE=$IMG_TYPE \
|
||||
BROWSER=$BROWSER
|
||||
ENV PATH ${PATH}:${ANDROID_HOME}/build-tools
|
||||
|
||||
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}-android-${API_LEVEL}
|
||||
RUN echo y | android update sdk --no-ui -a -t android-${API_LEVEL},sys-img-${SYS_IMG}-${IMG_TYPE}-${API_LEVEL}
|
||||
|
||||
#==============================================
|
||||
# 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
|
||||
@@ -170,4 +140,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 @@
|
||||
# TODO
|
||||
@@ -1,7 +1,7 @@
|
||||
Docker-Android-Appium Sample
|
||||
----------------------------
|
||||
Docker-Android Sample UITests with Appium
|
||||
-----------------------------------------
|
||||
|
||||
Example UI test to use docker-appium.
|
||||
Example UI test with [Appium] to use docker-android.
|
||||
|
||||
Requirements
|
||||
============
|
||||
@@ -12,3 +12,5 @@ Quick Start
|
||||
===========
|
||||
1. pip install -r requirements.txt
|
||||
2. python app_simple.py
|
||||
|
||||
[Appium]: <https://appium.io>
|
||||
|
||||
@@ -9,10 +9,12 @@ class SimpleAndroidUITests(unittest.TestCase):
|
||||
desired_caps = {
|
||||
'platformName': 'Android',
|
||||
'deviceName': 'Android Emulator',
|
||||
'app': '/root/sample_apk_debug.apk',
|
||||
'avd': 'nexus_5_5.0'
|
||||
'automationName': 'UIAutomator2',
|
||||
'app': '/root/tmp/sample_apk_debug.apk',
|
||||
'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()
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import unittest
|
||||
|
||||
from time import sleep
|
||||
|
||||
from appium import webdriver
|
||||
|
||||
|
||||
class MSiteChromeAndroidUITests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
||||
# Default google chrome does not exist for android < 6.0
|
||||
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://127.0.0.1:4444/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()
|
||||
sleep(2)
|
||||
|
||||
def tearDown(self):
|
||||
self.driver.quit()
|
||||
|
||||
if __name__ == '__main__':
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(MSiteChromeAndroidUITests)
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
||||
@@ -1,22 +1,31 @@
|
||||
import unittest
|
||||
|
||||
from time import sleep
|
||||
|
||||
from appium import webdriver
|
||||
|
||||
|
||||
class MSiteDefaultBrowserAndroidUITests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
||||
# Default browser does not exist for android >= 6.0
|
||||
desired_caps = {
|
||||
'platformName': 'Android',
|
||||
'deviceName': 'Android Emulator',
|
||||
'appPackage': 'com.android.browser',
|
||||
'appActivity': 'com.android.browser.BrowserActivity',
|
||||
'avd': 'nexus_5_5.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()
|
||||
|
||||
|
Before Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 78 KiB |
|
Before Width: | Height: | Size: 66 KiB |
|
After Width: | Height: | Size: 131 KiB |
|
After Width: | Height: | Size: 607 KiB |
|
After Width: | Height: | Size: 150 KiB |
|
After Width: | Height: | Size: 244 KiB |
|
Before Width: | Height: | Size: 51 KiB |
|
Before Width: | Height: | Size: 311 KiB |
|
Before Width: | Height: | Size: 240 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
|
||||
@@ -11,7 +10,7 @@ else
|
||||
fi
|
||||
|
||||
if [ -z "$2" ]; then
|
||||
read -p "Android version (5.0.1|5.1.1|6.0|all): " ANDROID_VERSION
|
||||
read -p "Android version (5.0.1|5.1.1|6.0|7.0|7.1.1|all): " ANDROID_VERSION
|
||||
else
|
||||
ANDROID_VERSION=$2
|
||||
fi
|
||||
@@ -32,6 +31,8 @@ declare -A list_of_levels=(
|
||||
[5.0.1]=21
|
||||
[5.1.1]=22
|
||||
[6.0]=23
|
||||
[7.0]=24
|
||||
[7.1.1]=25
|
||||
)
|
||||
|
||||
declare -A list_of_processors=(
|
||||
@@ -91,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 && 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() {
|
||||
@@ -101,7 +154,26 @@ 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 and default web browser
|
||||
if [ "$v" == "5.0.1" ] || [ "$v" == "5.1.1" ]; then
|
||||
IMG_TYPE=android
|
||||
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]}
|
||||
echo "[BUILD] API Level: $level"
|
||||
sys_img=${list_of_processors[$p]}
|
||||
@@ -109,10 +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 .
|
||||
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 .
|
||||
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
|
||||
}
|
||||
|
||||
@@ -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,7 +5,7 @@ import logging
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
from src import CONFIG_FILE, ROOT
|
||||
from src import CONFIG_FILE, ROOT, CHROME_DRIVER
|
||||
from src import log
|
||||
|
||||
log.init()
|
||||
@@ -26,7 +26,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.
|
||||
|
||||
@@ -44,12 +44,14 @@ ANDROID_VERSION = get_or_raise('ANDROID_VERSION')
|
||||
API_LEVEL = get_or_raise('API_LEVEL')
|
||||
PROCESSOR = get_or_raise('PROCESSOR')
|
||||
SYS_IMG = get_or_raise('SYS_IMG')
|
||||
IMG_TYPE = get_or_raise('IMG_TYPE')
|
||||
|
||||
logger.info('Android version: {version} \n'
|
||||
'API level: {level} \n'
|
||||
'Processor: {processor} \n'
|
||||
'System image: {img}'.format(version=ANDROID_VERSION, level=API_LEVEL, processor=PROCESSOR,
|
||||
img=SYS_IMG))
|
||||
'System image: {img} \n'
|
||||
'Image type: {img_type}'.format(version=ANDROID_VERSION, level=API_LEVEL, processor=PROCESSOR,
|
||||
img=SYS_IMG, img_type=IMG_TYPE))
|
||||
|
||||
|
||||
def prepare_avd(device: str, avd_name: str):
|
||||
@@ -59,8 +61,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 {sys_img}'.format(
|
||||
name=avd_name, api=API_LEVEL, sys_img=SYS_IMG)
|
||||
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')
|
||||
@@ -98,23 +101,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.
|
||||
|
||||
@@ -130,7 +141,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,
|
||||
}
|
||||
],
|
||||
@@ -145,7 +157,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))
|
||||
@@ -167,7 +180,7 @@ def run():
|
||||
cmd = 'emulator -avd {name}'.format(name=avd_name)
|
||||
subprocess.Popen(cmd.split())
|
||||
|
||||
appium = str_to_bool(str(os.getenv('APPIUM', True)))
|
||||
appium = convert_str_to_bool(str(os.getenv('APPIUM', False)))
|
||||
if appium:
|
||||
logger.info('Run appium server...')
|
||||
appium_run(avd_name)
|
||||
|
||||
@@ -1,53 +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:
|
||||
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()
|
||||
@@ -0,0 +1,54 @@
|
||||
"""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.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']
|
||||
@@ -30,5 +30,5 @@ autorestart=false
|
||||
[program:docker-appium]
|
||||
command=python3 -m src.app
|
||||
autorestart=false
|
||||
stdout_logfile=%(ENV_LOG_PATH)s/docker-appium.stdout.log
|
||||
stderr_logfile=%(ENV_LOG_PATH)s/docker-appium.stderr.log
|
||||
stdout_logfile=%(ENV_LOG_PATH)s/docker-android.stdout.log
|
||||
stderr_logfile=%(ENV_LOG_PATH)s/docker-android.stderr.log
|
||||
|
||||
@@ -7,8 +7,8 @@ if [ -z "$TRAVIS_TAG" ]; then
|
||||
else
|
||||
echo "Log in to docker hub"
|
||||
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
|
||||
echo "RUN UNIT TEST, BUILD DOCKER IMAGES AND PUSH THOSE TO DOCKER HUB"
|
||||
bash release.sh all all all $TRAVIS_TAG
|
||||
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
|
||||
echo "Log out of docker hub"
|
||||
docker logout
|
||||
fi
|
||||
|
||||