Automated all steps from PR #12

This commit is contained in:
butomo1989 2017-06-14 15:06:01 +02:00
parent 65df456066
commit 0e578710f3
5 changed files with 17 additions and 29 deletions

View file

@ -99,11 +99,6 @@ Appium is automation test framework to test mobile website and mobile applicatio
```bash ```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 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 ### Connect to Selenium Grid
@ -211,4 +206,3 @@ docker exec -it android-container tail -f /var/log/supervisor/docker-android.std
[1.13.0]: <https://github.com/docker/compose/releases/tag/1.13.0> [1.13.0]: <https://github.com/docker/compose/releases/tag/1.13.0>
[adb_connection]: <images/adb_connection.png> [adb_connection]: <images/adb_connection.png>
[sms]: <images/SMS.png> [sms]: <images/SMS.png>
[chromedriver]: <https://chromedriver.storage.googleapis.com/index.html>

View file

@ -2,7 +2,6 @@
# Bash version should >= 4 to be able to run this script. # Bash version should >= 4 to be able to run this script.
IMAGE="butomo1989/docker-android" IMAGE="butomo1989/docker-android"
LATEST_BUILD_TOOL=25.0.3
if [ -z "$1" ]; then if [ -z "$1" ]; then
read -p "Task (test|build|push|all) : " TASK read -p "Task (test|build|push|all) : " TASK
@ -99,6 +98,7 @@ function test() {
test_processor=x86 test_processor=x86
test_sys_img=x86_64 test_sys_img=x86_64
test_img_type=google_apis test_img_type=google_apis
test_browser=chrome
test_image=test_img test_image=test_img
test_container=test_con test_container=test_con
@ -107,9 +107,8 @@ function test() {
if [ "$(uname -s)" == 'Linux' ] && [ "$E2E" = true ]; then if [ "$(uname -s)" == 'Linux' ] && [ "$E2E" = true ]; then
echo "----BUILD TEST IMAGE----" echo "----BUILD TEST IMAGE----"
docker build -t $test_image --build-arg ANDROID_VERSION=$test_android_version \ 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 API_LEVEL=$test_api_level --build-arg PROCESSOR=$test_processor --build-arg SYS_IMG=$test_sys_img \
--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 .
--build-arg IMG_TYPE=$test_img_type -f docker/Emulator_x86 .
echo "----REMOVE OLD TEST CONTAINER----" echo "----REMOVE OLD TEST CONTAINER----"
docker kill $test_container && docker rm $test_container docker kill $test_container && docker rm $test_container
@ -183,9 +182,9 @@ 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"
echo "[BUILD] Dockerfile: $FILE_NAME" echo "[BUILD] Dockerfile: $FILE_NAME"
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 API_LEVEL=$level \
--build-arg API_LEVEL=$level --build-arg PROCESSOR=$p --build-arg SYS_IMG=$sys_img \ --build-arg PROCESSOR=$p --build-arg SYS_IMG=$sys_img --build-arg IMG_TYPE=$IMG_TYPE \
--build-arg IMG_TYPE=$IMG_TYPE --build-arg BROWSER=$BROWSER -f $FILE_NAME . --build-arg BROWSER=$BROWSER -f $FILE_NAME .
docker tag $image_version $image_latest docker tag $image_version $image_latest
done done
done done

View file

@ -2,5 +2,6 @@ import os
ROOT = '/root' ROOT = '/root'
WORKDIR = os.path.dirname(__file__) WORKDIR = os.path.dirname(__file__)
CHROME_DRIVER = os.path.join(ROOT, 'chromedriver')
CONFIG_FILE = os.path.join(WORKDIR, 'nodeconfig.json') CONFIG_FILE = os.path.join(WORKDIR, 'nodeconfig.json')
LOGGING_FILE = os.path.join(WORKDIR, 'logging.conf') LOGGING_FILE = os.path.join(WORKDIR, 'logging.conf')

View file

@ -5,7 +5,7 @@ import logging
import os import os
import subprocess import subprocess
from src import CONFIG_FILE, ROOT from src import CONFIG_FILE, ROOT, CHROME_DRIVER
from src import log from src import log
log.init() log.init()
@ -100,18 +100,17 @@ def appium_run(avd_name: str):
:param avd_name: Name of android virtual device / emulator :param avd_name: Name of android virtual device / emulator
""" """
cmd = 'appium' 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) default_web_browser = os.getenv('BROWSER')
if chromedriver_executable: if default_web_browser == 'chrome':
cmd += ' --chromedriver-executable {executable}'.format(executable=chromedriver_executable) cmd += ' --chromedriver-executable {driver}'.format(driver=CHROME_DRIVER)
grid_connect = convert_str_to_bool(str(os.getenv('CONNECT_TO_GRID', False))) grid_connect = convert_str_to_bool(str(os.getenv('CONNECT_TO_GRID', False)))
logger.info('Connect to selenium grid? {connect}'.format(connect=grid_connect)) logger.info('Connect to selenium grid? {connect}'.format(connect=grid_connect))
if grid_connect: if grid_connect:
local_ip = os.popen('ifconfig eth0 | grep \'inet addr:\' | cut -d: -f2 | awk \'{ print $1}\'').read().strip()
try: try:
mobile_web_test = convert_str_to_bool(str(os.getenv('MOBILE_WEB_TEST', False))) 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_host = os.getenv('APPIUM_HOST', local_ip)
appium_port = int(os.getenv('APPIUM_PORT', 4723)) appium_port = int(os.getenv('APPIUM_PORT', 4723))
selenium_host = os.getenv('SELENIUM_HOST', '172.17.0.1') selenium_host = os.getenv('SELENIUM_HOST', '172.17.0.1')

View file

@ -12,28 +12,21 @@ class TestAppium(TestCase):
def setUp(self): def setUp(self):
os.environ['CONNECT_TO_GRID'] = str(True) os.environ['CONNECT_TO_GRID'] = str(True)
os.environ['CHROMEDRIVER_EXECUTABLE'] = str(False)
self.avd_name = 'test_avd' self.avd_name = 'test_avd'
@mock.patch('os.popen')
@mock.patch('subprocess.check_call') @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['CONNECT_TO_GRID'] = str(False)
os.environ['CHROMEDRIVER_EXECUTABLE'] = '/root/chromedriver' os.environ['BROWSER'] = 'chrome'
self.assertFalse(mocked_os.called)
self.assertFalse(mocked_subprocess.called) self.assertFalse(mocked_subprocess.called)
app.appium_run(self.avd_name) app.appium_run(self.avd_name)
self.assertTrue(mocked_os.called)
self.assertTrue(mocked_subprocess.called) self.assertTrue(mocked_subprocess.called)
@mock.patch('os.popen')
@mock.patch('subprocess.check_call') @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) os.environ['CONNECT_TO_GRID'] = str(False)
self.assertFalse(mocked_os.called)
self.assertFalse(mocked_subprocess.called) self.assertFalse(mocked_subprocess.called)
app.appium_run(self.avd_name) app.appium_run(self.avd_name)
self.assertTrue(mocked_os.called)
self.assertTrue(mocked_subprocess.called) self.assertTrue(mocked_subprocess.called)
@mock.patch('os.popen') @mock.patch('os.popen')
@ -73,3 +66,5 @@ class TestAppium(TestCase):
del os.environ['CONNECT_TO_GRID'] del os.environ['CONNECT_TO_GRID']
if os.getenv('APPIUM_PORT'): if os.getenv('APPIUM_PORT'):
del os.environ['APPIUM_PORT'] del os.environ['APPIUM_PORT']
if os.getenv('BROWSER'):
del os.environ['BROWSER']