Skip to content

Commit

Permalink
Automated all steps from PR #12
Browse files Browse the repository at this point in the history
  • Loading branch information
budtmo committed Jun 14, 2017
1 parent 65df456 commit 0e57871
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 29 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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>
[adb_connection]: <images/adb_connection.png>
[sms]: <images/SMS.png>
[chromedriver]: <https://chromedriver.storage.googleapis.com/index.html>
13 changes: 6 additions & 7 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

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')
11 changes: 5 additions & 6 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import subprocess

from src import CONFIG_FILE, ROOT
from src import CONFIG_FILE, ROOT, CHROME_DRIVER
from src import log

log.init()
Expand Down Expand Up @@ -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')
Expand Down
15 changes: 5 additions & 10 deletions src/tests/unit/test_appium.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -73,3 +66,5 @@ def tearDown(self):
del os.environ['CONNECT_TO_GRID']
if os.getenv('APPIUM_PORT'):
del os.environ['APPIUM_PORT']
if os.getenv('BROWSER'):
del os.environ['BROWSER']

0 comments on commit 0e57871

Please sign in to comment.