diff --git a/README.md b/README.md index eefc6f4..651878f 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,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***. diff --git a/docker/Emulator_arm b/docker/Emulator_arm index cc459f8..6fee916 100644 --- a/docker/Emulator_arm +++ b/docker/Emulator_arm @@ -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 diff --git a/docker/Emulator_x86 b/docker/Emulator_x86 index 8b70015..b5291f9 100644 --- a/docker/Emulator_x86 +++ b/docker/Emulator_x86 @@ -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 diff --git a/example/compose/README.md b/example/compose/README.md new file mode 100644 index 0000000..e258264 --- /dev/null +++ b/example/compose/README.md @@ -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 +``` diff --git a/example/compose/docker-compose.yml b/example/compose/docker-compose.yml new file mode 100644 index 0000000..dfdc33e --- /dev/null +++ b/example/compose/docker-compose.yml @@ -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 diff --git a/images/compose_selenium_grid.png b/images/compose_selenium_grid.png new file mode 100644 index 0000000..f078b61 Binary files /dev/null and b/images/compose_selenium_grid.png differ diff --git a/release.sh b/release.sh index c709bb6..c6f8237 100755 --- a/release.sh +++ b/release.sh @@ -110,11 +110,16 @@ function build() { 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 + BROWSER=browser + elif [ "$v" == "6.0" ]; then + 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]} @@ -127,10 +132,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 } diff --git a/src/app.py b/src/app.py index a609c1e..1d4c927 100644 --- a/src/app.py +++ b/src/app.py @@ -106,11 +106,13 @@ def appium_run(avd_name: str): logger.info('Connect to selenium grid? {connect}'.format(connect=grid_connect)) if grid_connect: try: + mobile_web_test = 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)) - browser_name = os.getenv('BROWSER', 'Chrome') + 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: diff --git a/src/tests/test_appium.py b/src/tests/test_appium.py index 1e9b85e..9579bc0 100644 --- a/src/tests/test_appium.py +++ b/src/tests/test_appium.py @@ -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', 'Chrome', '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)