Compare commits

..
6 Commits
Author SHA1 Message Date
butomo1989 e325706d17 Fixed android 5.0.1 and 5.1.1 2017-04-26 15:16:26 +02:00
butomo1989 3679a9bd48 Renamed log file 2017-04-26 14:19:46 +02:00
butomo1989 666489987b Use build matrix to speed up build and push processes 2017-04-26 11:42:40 +02:00
butomo1989 b785d70389 Updated README.md 2017-04-26 11:38:20 +02:00
butomo1989 f1663eb05e Renamed avd in sample UI tests 2017-04-24 15:50:18 +02:00
butomo1989 e46800e322 Cleaned up README.md 2017-04-24 14:04:16 +02:00
20 changed files with 123 additions and 77 deletions
+8
View File
@@ -10,6 +10,14 @@ services:
install: "pip install -r requirements.txt" 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 script: bash travis.sh
after_success: after_success:
+4 -2
View File
@@ -119,17 +119,19 @@ ARG BUILD_TOOL=21.1.2
ARG API_LEVEL=21 ARG API_LEVEL=21
ARG PROCESSOR=x86 ARG PROCESSOR=x86
ARG SYS_IMG=x86_64 ARG SYS_IMG=x86_64
ARG IMG_TYPE=google_apis
ENV ANDROID_VERSION=$ANDROID_VERSION \ ENV ANDROID_VERSION=$ANDROID_VERSION \
BUILD_TOOL=$BUILD_TOOL \ BUILD_TOOL=$BUILD_TOOL \
API_LEVEL=$API_LEVEL \ API_LEVEL=$API_LEVEL \
PROCESSOR=$PROCESSOR \ PROCESSOR=$PROCESSOR \
SYS_IMG=$SYS_IMG SYS_IMG=$SYS_IMG \
IMG_TYPE=$IMG_TYPE
RUN echo y | android update sdk --no-ui -a --filter build-tools-${BUILD_TOOL} RUN echo y | android update sdk --no-ui -a --filter build-tools-${BUILD_TOOL}
ENV PATH ${PATH}:${ANDROID_HOME}/build-tools ENV PATH ${PATH}:${ANDROID_HOME}/build-tools
RUN rm ${ANDROID_HOME}/tools/emulator \ RUN rm ${ANDROID_HOME}/tools/emulator \
&& ln -s ${ANDROID_HOME}/tools/emulator64-${PROCESSOR} ${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}-google_apis-${API_LEVEL} RUN echo y | android update sdk --no-ui -a -t android-${API_LEVEL},sys-img-${SYS_IMG}-${IMG_TYPE}-${API_LEVEL}
#================================================ #================================================
# noVNC Default Configurations # noVNC Default Configurations
+91 -71
View File
@@ -4,28 +4,29 @@ Docker-Android
[![Build Status](https://travis-ci.org/butomo1989/docker-android.svg?branch=master)](https://travis-ci.org/butomo1989/docker-android) [![Build Status](https://travis-ci.org/butomo1989/docker-android.svg?branch=master)](https://travis-ci.org/butomo1989/docker-android)
[![codecov](https://codecov.io/gh/butomo1989/docker-android/branch/master/graph/badge.svg)](https://codecov.io/gh/butomo1989/docker-android) [![codecov](https://codecov.io/gh/butomo1989/docker-android/branch/master/graph/badge.svg)](https://codecov.io/gh/butomo1989/docker-android)
Android in docker solution with noVNC supported Docker-Android is an android environment, an android emulator that facilitates different devices and [appium] in docker solution integrated with noVNC.
Requirements Samsung Device | Google Device
------------ :---------------------------:|:---------------------------:
![][docker android samsung] | ![][docker android nexus]
Docker is installed in your system.
Purpose Purpose
------- -------
1. Build android project / application and run unit test 1. Build android project and run unit test inside container
2. Run UI Test for mobile website with appium framework 2. Run UI Test for mobile application with different frameworks (appium, espresso, etc.)
3. Run UI Test for mobile application with different frameworks (appium, espresso, etc.) 3. Run UI Test for mobile website with appium test framework
4. Simulate Short Message Service (SMS) 4. Video recording to analyse failing test cases ***(soon)***
5. Monkey test for stress test ***(soon)***
Features Advantages compare with other docker-android projects
-------- -----------------------------------------------------
1. Android emulator with different devices 1. noVNC to see what happen inside docker container
2. latest build-tool (version 25.0.2) 2. Android emulator that facilitates different devices
3. noVNC to see what happen inside docker container 3. Able to connect with selenium grid
4. Appium server for automation test framework and it is 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)***
List of Docker images List of Docker images
--------------------- ---------------------
@@ -43,57 +44,11 @@ List of Docker images
|OSX / Windows|7.0|24|butomo1989/docker-android-arm-7.0|[![](https://images.microbadger.com/badges/image/butomo1989/docker-android-arm-7.0.svg)](https://microbadger.com/images/butomo1989/docker-android-arm-7.0 "Get your own image badge on microbadger.com")| |OSX / Windows|7.0|24|butomo1989/docker-android-arm-7.0|[![](https://images.microbadger.com/badges/image/butomo1989/docker-android-arm-7.0.svg)](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://images.microbadger.com/badges/image/butomo1989/docker-android-arm-7.1.1.svg)](https://microbadger.com/images/butomo1989/docker-android-arm-7.1.1 "Get your own image badge on microbadger.com")| |OSX / Windows|7.1.1|25|butomo1989/docker-android-arm-7.1.1|[![](https://images.microbadger.com/badges/image/butomo1989/docker-android-arm-7.1.1.svg)](https://microbadger.com/images/butomo1989/docker-android-arm-7.1.1 "Get your own image badge on microbadger.com")|
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).
2. Run docker-android
```bash
docker run --privileged -d -p 6080:6080 -p 4723:4723 -p 5554:5554 -p 5555:5555 -e DEVICE="Samsung Galaxy S6" --name android-container butomo1989/docker-android-x86-5.0.1
```
**Optional arguments**
-v <android_project_or_apk>:/root/tmp : 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
3. Verify the ip address of docker-machine.
- For OSX, you can find out by using following command:
```bash
docker-machine ip default
```
- For different OS, localhost should work.
4. Open ***http://docker-machine-ip-address:6080*** from web browser.
![][noVNC]
Connect to Selenium Grid
------------------------
This feature can be used only if you set **APPIUM=True** in environment variable.
**Arguments**
-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 1] ![][connect to grid 2]
List of Devices List of Devices
--------------- ---------------
Type | Device Name Type | Device Name
--- | --- ----- | -----
Phone | Samsung Galaxy S6 Phone | Samsung Galaxy S6
Phone | Nexus 4 Phone | Nexus 4
Phone | Nexus 5 Phone | Nexus 5
@@ -107,7 +62,73 @@ Tablet | Nexus 7
Tablet | Nexus 9 Tablet | Nexus 9
Tablet | Nexus 10 Tablet | Nexus 10
![][galaxy s6] ![][nexus 5] Requirements
------------
Docker is installed in your system.
Quick Start
-----------
1. Run docker-android
- For ***Linux OS***, please use image name that contains "x86"
```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
```
- For ***OSX*** and ***Windows OS***, please use image name that contains "arm"
```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
```
2. Verify the ip address of docker host.
- For OSX, you can find out by using following command:
```bash
docker-machine ip default
```
- For different OS, localhost should work.
3. Open ***http://docker-host-ip-address:6080*** from web browser.
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***.
```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
```
### 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
- APPIUM_HOST="\<host\_ip\_address>"
- APPIUM_PORT=\<port\_number>
- SELENIUM_HOST="\<host\_ip\_address>"
- SELENIUM_PORT=\<port\_number>
```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
```
### 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 -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
```
Control android emulator outside container Control android emulator outside container
------------------------------------------ ------------------------------------------
@@ -154,7 +175,7 @@ SMS Simulation
docker exec -it android-container adb emu sms send <phone_number> <message> 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] ![][sms]
@@ -163,14 +184,13 @@ Troubleshooting
All logs inside container are stored under folder **/var/log/supervisor**. you can print out log file by using **docker exec**. Example: All logs inside container are stored under folder **/var/log/supervisor**. you can print out log file by using **docker exec**. Example:
```bash ```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" [appium]: <https://appium.io>
[connect to grid 1]: <images/appium_with_selenium_grid_01.png> [docker android samsung]: <images/docker_android_samsung.png>
[connect to grid 2]: <images/appium_with_selenium_grid_02.png> [docker android nexus]: <images/docker_android_nexus.png>
[galaxy s6]: <images/run_under_galaxy_s6.png> [selenium grid]: <images/selenium_grid.png>
[nexus 5]: <images/run_under_nexus_5.png> [devices are connected with selenium grid]: <images/connected_with_grid.png>
[adb_connection]: <images/adb_connection.png> [adb_connection]: <images/adb_connection.png>
[sms]: <images/SMS.png> [sms]: <images/SMS.png>
[adblib]: <https://github.com/tananaev/adblib>
+1 -1
View File
@@ -10,7 +10,7 @@ class SimpleAndroidUITests(unittest.TestCase):
'platformName': 'Android', 'platformName': 'Android',
'deviceName': 'Android Emulator', 'deviceName': 'Android Emulator',
'app': '/root/tmp/sample_apk_debug.apk', 'app': '/root/tmp/sample_apk_debug.apk',
'avd': 'samsung_galaxy_s6_5.0.1' 'avd': 'samsung_galaxy_s6_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:4723/wd/hub', desired_caps)
@@ -6,12 +6,14 @@ from appium import webdriver
class MSiteChromeAndroidUITests(unittest.TestCase): class MSiteChromeAndroidUITests(unittest.TestCase):
def setUp(self): def setUp(self):
# Default google chrome does not exist for android < 6.0
desired_caps = { desired_caps = {
'platformName': 'Android', 'platformName': 'Android',
'deviceName': 'Android Emulator', 'deviceName': 'Android Emulator',
'appPackage': 'com.android.chrome', 'appPackage': 'com.android.chrome',
'appActivity': 'com.google.android.apps.chrome.Main', 'appActivity': 'com.google.android.apps.chrome.Main',
'avd': 'samsung_galaxy_s6_5.0.1' 'avd': 'samsung_galaxy_s6_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:4723/wd/hub', desired_caps)
@@ -6,12 +6,14 @@ from appium import webdriver
class MSiteDefaultBrowserAndroidUITests(unittest.TestCase): class MSiteDefaultBrowserAndroidUITests(unittest.TestCase):
def setUp(self): def setUp(self):
# Default browser does not exist for android >= 6.0
desired_caps = { desired_caps = {
'platformName': 'Android', 'platformName': 'Android',
'deviceName': 'Android Emulator', 'deviceName': 'Android Emulator',
'appPackage': 'com.android.browser', 'appPackage': 'com.android.browser',
'appActivity': 'com.android.browser.BrowserActivity', 'appActivity': 'com.android.browser.BrowserActivity',
'avd': 'samsung_galaxy_s6_5.0.1' 'avd': 'samsung_galaxy_s6_6.0'
} }
self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 311 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 240 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

+12 -3
View File
@@ -94,7 +94,7 @@ get_processors
function test() { function test() {
(export ANDROID_HOME=/root && export ANDROID_VERSION=5.0.1 && export API_LEVEL=21 \ (export ANDROID_HOME=/root && export ANDROID_VERSION=5.0.1 && export API_LEVEL=21 \
&& export PROCESSOR=x86 && export SYS_IMG=x86_64 && nosetests -v) && export PROCESSOR=x86 && export SYS_IMG=x86_64 && export IMG_TYPE=google_apis && nosetests -v)
} }
function build() { function build() {
@@ -104,6 +104,13 @@ function build() {
# Build docker image(s) # Build docker image(s)
for p in "${processors[@]}"; do for p in "${processors[@]}"; do
for v in "${versions[@]}"; do for v in "${versions[@]}"; do
# Find image type
if [ "$v" == "5.0.1" ] || [ "$v" == "5.1.1" ]; then
IMG_TYPE=android
else
IMG_TYPE=google_apis
fi
echo "[BUILD] IMAGE TYPE: $IMG_TYPE"
level=${list_of_levels[$v]} level=${list_of_levels[$v]}
echo "[BUILD] API Level: $level" echo "[BUILD] API Level: $level"
sys_img=${list_of_processors[$p]} sys_img=${list_of_processors[$p]}
@@ -112,9 +119,11 @@ function build() {
image_latest="$IMAGE-$p-$v:latest" image_latest="$IMAGE-$p-$v:latest"
echo "[BUILD] Image name: $image_version and $image_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 \ 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 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 \ 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 API_LEVEL=$level --build-arg PROCESSOR=$p --build-arg SYS_IMG=$sys_img \
--build-arg IMG_TYPE=$IMG_TYPE .
done done
done done
} }
+7 -4
View File
@@ -44,12 +44,14 @@ ANDROID_VERSION = get_or_raise('ANDROID_VERSION')
API_LEVEL = get_or_raise('API_LEVEL') API_LEVEL = get_or_raise('API_LEVEL')
PROCESSOR = get_or_raise('PROCESSOR') PROCESSOR = get_or_raise('PROCESSOR')
SYS_IMG = get_or_raise('SYS_IMG') SYS_IMG = get_or_raise('SYS_IMG')
IMG_TYPE = get_or_raise('IMG_TYPE')
logger.info('Android version: {version} \n' logger.info('Android version: {version} \n'
'API level: {level} \n' 'API level: {level} \n'
'Processor: {processor} \n' 'Processor: {processor} \n'
'System image: {img}'.format(version=ANDROID_VERSION, level=API_LEVEL, processor=PROCESSOR, 'System image: {img} \n'
img=SYS_IMG)) '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): 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 device: Device name
:param avd_name: Name of android virtual device / emulator :param avd_name: Name of android virtual device / emulator
""" """
cmd = 'echo no | android create avd -f -n {name} -t android-{api} -b google_apis/{sys_img}'.format( cmd = 'echo no | android create avd -f -n {name} -t android-{api} -b {img_type}{sys_img}'.format(
name=avd_name, api=API_LEVEL, sys_img=SYS_IMG) name=avd_name, api=API_LEVEL, img_type='google_apis/' if IMG_TYPE == 'google_apis' else '',
sys_img=SYS_IMG)
# Link emulator skins # Link emulator skins
skin_rsc_path = os.path.join(ROOT, 'devices', 'skins') skin_rsc_path = os.path.join(ROOT, 'devices', 'skins')
+2 -2
View File
@@ -30,5 +30,5 @@ autorestart=false
[program:docker-appium] [program:docker-appium]
command=python3 -m src.app command=python3 -m src.app
autorestart=false autorestart=false
stdout_logfile=%(ENV_LOG_PATH)s/docker-appium.stdout.log stdout_logfile=%(ENV_LOG_PATH)s/docker-android.stdout.log
stderr_logfile=%(ENV_LOG_PATH)s/docker-appium.stderr.log stderr_logfile=%(ENV_LOG_PATH)s/docker-android.stderr.log
+2 -2
View File
@@ -7,8 +7,8 @@ if [ -z "$TRAVIS_TAG" ]; then
else else
echo "Log in to docker hub" echo "Log in to docker hub"
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
echo "RUN UNIT TEST, BUILD DOCKER IMAGES AND PUSH THOSE TO DOCKER HUB" echo "[Version: $ANDROID_VERSION] RUN UNIT TEST, BUILD DOCKER IMAGES AND PUSH THOSE TO DOCKER HUB"
bash release.sh all all all $TRAVIS_TAG bash release.sh all $ANDROID_VERSION all $TRAVIS_TAG
echo "Log out of docker hub" echo "Log out of docker hub"
docker logout docker logout
fi fi