Merge pull request #8 from andrcuns/appium_host_for_scale_support

Support docker-compose scale when connecting to selenium hub
This commit is contained in:
budi utomo 2017-05-24 23:36:39 +02:00 committed by GitHub
commit 151e3a8d6f
9 changed files with 77 additions and 13 deletions

View file

@ -117,6 +117,12 @@ It is also possible to connect appium server that run inside docker-android with
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 --name android-container butomo1989/docker-android-x86-7.1.1
```
To run tests for mobile browser, following parameter can be passed:
- MOBILE\_WEB\_TEST=True
Check [README.md](/example/compose/README.md) on how to run complete selenium grid using docker-compose
### 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***.

View file

@ -110,12 +110,14 @@ 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
IMG_TYPE=$IMG_TYPE \
BROWSER=$BROWSER
RUN echo y | android update sdk --no-ui -a --filter build-tools-${BUILD_TOOL}
ENV PATH ${PATH}:${ANDROID_HOME}/build-tools

View file

@ -123,12 +123,14 @@ 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
IMG_TYPE=$IMG_TYPE \
BROWSER=$BROWSER
RUN echo y | android update sdk --no-ui -a --filter build-tools-${BUILD_TOOL}
ENV PATH ${PATH}:${ANDROID_HOME}/build-tools

16
example/compose/README.md Normal file
View file

@ -0,0 +1,16 @@
[docker-compose.yml](/example/compose/docker-compose.yml) file for setting up selenium grid.
-----------------------------------------------------
Example compose file which can be used to set up selenium grid hub with emulator nodes connected to it
![](/images/compose_selenium_grid.png)
Requirements
============
docker-compose
for `scale:` option docker-compose v1.13.0 and newer is required
Quick Start
===========
```bash
docker-compose up
```

View file

@ -0,0 +1,31 @@
version: "2.2"
services:
hub:
image: selenium/hub:3.4.0
ports:
- "4444:4444"
node_samsung_7.1.1:
image: butomo1989/docker-android-x86-7.1.1
privileged: true
scale: 2
ports:
- 6080
environment:
- DEVICE=Samsung Galaxy S6
- CONNECT_TO_GRID=True
- APPIUM=true
- SELENIUM_HOST=hub
node_nexus_web_7.1.1:
image: butomo1989/docker-android-x86-7.1.1
privileged: true
scale: 2
ports:
- 6080
environment:
- DEVICE=Nexus 5
- CONNECT_TO_GRID=True
- APPIUM=true
- SELENIUM_HOST=hub
- MOBILE_WEB_TEST=True

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

View file

@ -110,11 +110,13 @@ function build() {
fi
for v in "${versions[@]}"; do
# Find image type
if [ "$v" == "5.0.1" ] || [ "$v" == "5.1.1" ]; then
# Find image type and default web browser
if [ "$v" == "5.0.1" ] || [ "$v" == "5.1.1" ] || [ "$v" == "6.0" ]; then
IMG_TYPE=android
BROWSER=browser
else
IMG_TYPE=google_apis
BROWSER=chrome
fi
echo "[BUILD] IMAGE TYPE: $IMG_TYPE"
level=${list_of_levels[$v]}
@ -127,10 +129,10 @@ function build() {
echo "[BUILD] Dockerfile: $FILE_NAME"
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 -f $FILE_NAME .
--build-arg IMG_TYPE=$IMG_TYPE --build-arg BROWSER=$BROWSER -f $FILE_NAME .
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 -f $FILE_NAME .
--build-arg IMG_TYPE=$IMG_TYPE --build-arg BROWSER=$BROWSER -f $FILE_NAME .
done
done
}

View file

@ -100,24 +100,28 @@ def appium_run(avd_name: str):
:param avd_name: Name of android virtual device / emulator
"""
cmd = 'appium'
local_ip = os.popen('ifconfig eth0 | grep \'inet addr:\' | cut -d: -f2 | awk \'{ print $1}\'').read().strip()
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:
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)))
default_web_browser = os.getenv('BROWSER')
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 +137,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,
}
],

View file

@ -44,7 +44,7 @@ class TestAppium(TestCase):
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)