From a6394bcf748b1c190635cb66c6c99f45d42e3272 Mon Sep 17 00:00:00 2001 From: Ankur Agarwal Date: Tue, 21 Aug 2018 17:50:50 +0530 Subject: [PATCH] added support for custom arguments while running/creating emulator --- README.md | 7 +++++++ src/app.py | 8 ++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 24f62db..dbf2ac0 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,13 @@ To run tests for mobile browser, following parameter can be passed: ```bash 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 -e MOBILE_WEB_TEST=true --name android-container butomo1989/docker-android-x86-8.1 ``` +### Custom Emulator Arguments + +If you want to add more arguments for running emulator, you can ***pass an evnironemnt variable EMULATOR_ARGS*** while running docker command. + +```bash +docker run --privileged -d -p 6080:6080 -p 4723:4723 -p 5554:5554 -p 5555:5555 -e DEVICE="Samsung Galaxy S6" -e EMULATOR_ARGS="-no-snapshot-load -partition-size 512" -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 -e MOBILE_WEB_TEST=true --name android-container butomo1989/docker-android-x86-8.1 +``` ### Back & Restore If you want to backup/reuse the avds created with furture upgrades or for replication, run the container with two extra mounts diff --git a/src/app.py b/src/app.py index 535df1d..4d273ff 100644 --- a/src/app.py +++ b/src/app.py @@ -186,8 +186,8 @@ def run(): """Run app.""" device = os.getenv('DEVICE', 'Nexus 5') logger.info('Device: {device}'.format(device=device)) - device_id = os.getenv('DEVICE_ID', str(uuid.uuid4())) - logger.info('Device Id: {device_id}'.format(device_id=device_id)) + custom_args=os.getenv('EMULATOR_ARGS', '') + logger.info('Custom Args: {custom_args}'.format(custom_args=custom_args)) avd_name = '{device}_{version}'.format(device=device.replace(' ', '_').lower(), version=ANDROID_VERSION) logger.info('AVD name: {avd}'.format(avd=avd_name)) @@ -203,9 +203,9 @@ def run(): cfg.write('\ndisk.dataPartition.size={dp}'.format(dp=dp_size)) if is_first_run: - cmd = 'emulator/emulator @{name} -gpu off -prop emu.uuid={uuid} -verbose -wipe-data'.format(name=avd_name, uuid=device_id) + cmd = 'emulator/emulator @{name} -gpu off -verbose -wipe-data {custom_args}'.format(name=avd_name, custom_args=custom_args) else: - cmd = 'emulator/emulator @{name} -gpu off -prop emu.uuid={uuid} -verbose'.format(name=avd_name, uuid=device_id) + cmd = 'emulator/emulator @{name} -gpu off -verbose {custom_args}'.format(name=avd_name, custom_args=custom_args) appium = convert_str_to_bool(str(os.getenv('APPIUM', False))) if appium: subprocess.Popen(cmd.split())