From 0e578710f35eb5a384689c9358b0a1d693d37e43 Mon Sep 17 00:00:00 2001 From: butomo1989 Date: Wed, 14 Jun 2017 15:06:01 +0200 Subject: [PATCH] Automated all steps from PR #12 --- README.md | 6 ------ release.sh | 13 ++++++------- src/__init__.py | 1 + src/app.py | 11 +++++------ src/tests/unit/test_appium.py | 15 +++++---------- 5 files changed, 17 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 4a84550..bee9c17 100644 --- a/README.md +++ b/README.md @@ -99,11 +99,6 @@ Appium is automation test framework to test mobile website and mobile applicatio ```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 ``` -It is possible to start appium with custom chromedriver executable by mounting directory with chromedriver inside container and passing an environment variable ***CHROMEDRIVER_EXECUTABLE=path_to_chromedriver*** -[chromedriver] repo contains all versions of chromedriver executable. To run web tests with Android 7.1.1 image which by default contains chrome v53, chromedriver version 2.26 has to be used. More recent chromedriver versions require chrome v54 and up. -```bash -docker run --privileged -d -p 6080:6080 -p 5554:5554 -p 5555:5555 -p 4723:4723 -v /path/to/chromedriver:/root/chromedriver -e CHROMEDRIVER_EXECUTABLE=/root/chromedriver/chromedriver -e DEVICE="Samsung Galaxy S6" -e APPIUM=True --name android-container butomo1989/docker-android-x86-7.1.1 -``` ### Connect to Selenium Grid @@ -211,4 +206,3 @@ docker exec -it android-container tail -f /var/log/supervisor/docker-android.std [1.13.0]: [adb_connection]: [sms]: -[chromedriver]: diff --git a/release.sh b/release.sh index 79464ca..f883f6a 100755 --- a/release.sh +++ b/release.sh @@ -2,7 +2,6 @@ # Bash version should >= 4 to be able to run this script. IMAGE="butomo1989/docker-android" -LATEST_BUILD_TOOL=25.0.3 if [ -z "$1" ]; then read -p "Task (test|build|push|all) : " TASK @@ -99,6 +98,7 @@ function test() { test_processor=x86 test_sys_img=x86_64 test_img_type=google_apis + test_browser=chrome test_image=test_img test_container=test_con @@ -107,9 +107,8 @@ function test() { 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 BUILD_TOOL=$LATEST_BUILD_TOOL --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 -f docker/Emulator_x86 . + --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 @@ -183,9 +182,9 @@ function build() { image_latest="$IMAGE-$p-$v:latest" echo "[BUILD] Image name: $image_version and $image_latest" 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 --build-arg BROWSER=$BROWSER -f $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 diff --git a/src/__init__.py b/src/__init__.py index c4ddef8..e2104db 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -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') diff --git a/src/app.py b/src/app.py index 1f9003c..de493a2 100644 --- a/src/app.py +++ b/src/app.py @@ -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() @@ -100,18 +100,17 @@ 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() - chromedriver_executable = os.getenv('CHROMEDRIVER_EXECUTABLE', False) - if chromedriver_executable: - cmd += ' --chromedriver-executable {executable}'.format(executable=chromedriver_executable) + 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: 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') diff --git a/src/tests/unit/test_appium.py b/src/tests/unit/test_appium.py index 97de912..87a8533 100644 --- a/src/tests/unit/test_appium.py +++ b/src/tests/unit/test_appium.py @@ -12,28 +12,21 @@ class TestAppium(TestCase): def setUp(self): os.environ['CONNECT_TO_GRID'] = str(True) - os.environ['CHROMEDRIVER_EXECUTABLE'] = str(False) self.avd_name = 'test_avd' - @mock.patch('os.popen') @mock.patch('subprocess.check_call') - def test_with_chromedriver_executable(self, mocked_os, mocked_subprocess): + def test_chrome_driver(self, mocked_subprocess): os.environ['CONNECT_TO_GRID'] = str(False) - os.environ['CHROMEDRIVER_EXECUTABLE'] = '/root/chromedriver' - self.assertFalse(mocked_os.called) + os.environ['BROWSER'] = 'chrome' self.assertFalse(mocked_subprocess.called) app.appium_run(self.avd_name) - self.assertTrue(mocked_os.called) self.assertTrue(mocked_subprocess.called) - @mock.patch('os.popen') @mock.patch('subprocess.check_call') - def test_without_selenium_grid(self, mocked_os, mocked_subprocess): + def test_without_selenium_grid(self, mocked_subprocess): os.environ['CONNECT_TO_GRID'] = str(False) - self.assertFalse(mocked_os.called) self.assertFalse(mocked_subprocess.called) app.appium_run(self.avd_name) - self.assertTrue(mocked_os.called) self.assertTrue(mocked_subprocess.called) @mock.patch('os.popen') @@ -73,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']