diff --git a/README.md b/README.md index 86a7497..7157da9 100644 --- a/README.md +++ b/README.md @@ -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***. 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..beba2be 100755 --- a/release.sh +++ b/release.sh @@ -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 } diff --git a/src/app.py b/src/app.py index f5b8fbc..6553598 100644 --- a/src/app.py +++ b/src/app.py @@ -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, } ], diff --git a/src/tests/test_appium.py b/src/tests/test_appium.py index ccc1910..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', '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)