mirror of
https://github.com/budtmo/docker-android.git
synced 2026-07-29 19:00:34 +00:00
Enable to use avd skins
This commit is contained in:
+8
-3
@@ -28,8 +28,7 @@ def get_api_level(android_version):
|
||||
|
||||
item_info = item.split('-')
|
||||
api_version = re.search('%s(.*)%s' % ('API', ','), item_info[1]).group(1).strip()
|
||||
logger.info(
|
||||
'API level: {api}'.format(api=api_version))
|
||||
logger.info('API level: {api}'.format(api=api_version))
|
||||
else:
|
||||
raise RuntimeError('List of packages is empty!')
|
||||
|
||||
@@ -64,12 +63,16 @@ def install_package(android_path, emulator_file, api_level, sys_img):
|
||||
subprocess.check_call('xterm -e \"{cmd}\"'.format(cmd=cmd), shell=True)
|
||||
|
||||
|
||||
def create_avd(android_path, avd_name, api_level):
|
||||
def create_avd(android_path, device, skin, avd_name, api_level):
|
||||
"""
|
||||
Create android virtual device.
|
||||
|
||||
:param android_path: location where android SDK is installed
|
||||
:type android_path: str
|
||||
:param device: name of device
|
||||
:type device: str
|
||||
:param skin: emulator skin that want to be used
|
||||
:type skin: str
|
||||
:param avd_name: desire name
|
||||
:type avd_name: str
|
||||
:param api_level: api level
|
||||
@@ -83,6 +86,8 @@ def create_avd(android_path, avd_name, api_level):
|
||||
|
||||
# Create android emulator
|
||||
cmd = 'echo no | android create avd -f -n {name} -t android-{api}'.format(name=avd_name, api=api_level)
|
||||
if device and skin:
|
||||
cmd += ' -d {device} -s {skin}'.format(device=device.replace(' ', '\ '), skin=skin)
|
||||
logger.info('Emulator creation command : {cmd}'.format(cmd=cmd))
|
||||
subprocess.check_call('xterm -e \"{cmd}\"'.format(cmd=cmd), shell=True)
|
||||
|
||||
|
||||
+7
-3
@@ -30,14 +30,18 @@ def start():
|
||||
emulator_file = 'emulator64-x86' if emulator_type == TYPE_X86 else 'emulator64-arm'
|
||||
logger.info('Emulator file: {file}'.format(file=emulator_file))
|
||||
api_level = android.get_api_level(android_version)
|
||||
sys_img = 'x86' if emulator_type == TYPE_X86 else 'armeabi-v7a'
|
||||
sys_img = 'x86_64' if emulator_type == TYPE_X86 else 'armeabi-v7a'
|
||||
logger.info('System image: {sys_img}'.format(sys_img=sys_img))
|
||||
android.install_package(android_path, emulator_file, api_level, sys_img)
|
||||
|
||||
# Create android virtual device
|
||||
avd_name = 'emulator_{version}'.format(version=android_version)
|
||||
device_name = os.getenv('DEVICE', 'Nexus 5')
|
||||
logger.info('Device: {device}'.format(device=device_name))
|
||||
skin_name = device_name.replace(' ', '_').lower()
|
||||
logger.info('Skin: {skin}'.format(skin=skin_name))
|
||||
avd_name = '{device}_{version}'.format(device=skin_name, version=android_version)
|
||||
logger.info('AVD name: {avd}'.format(avd=avd_name))
|
||||
android.create_avd(android_path, avd_name, api_level)
|
||||
android.create_avd(android_path, device_name, skin_name, avd_name, api_level)
|
||||
|
||||
# Run appium server
|
||||
appium.run(connect_to_grid, avd_name, android_version)
|
||||
|
||||
@@ -11,7 +11,9 @@ class TestAvd(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.android_path = '/root'
|
||||
self.avd_name = 'test'
|
||||
self.device = 'Nexus\ 5'
|
||||
self.skin = 'nexus_5'
|
||||
self.avd_name = 'nexus_5_5.0'
|
||||
self.api_level = 21
|
||||
|
||||
@mock.patch('os.symlink')
|
||||
@@ -22,7 +24,7 @@ class TestAvd(TestCase):
|
||||
self.assertFalse(mocked_list_dir.called)
|
||||
self.assertFalse(mocked_sys_link.called)
|
||||
self.assertFalse(mocked_suprocess.called)
|
||||
android.create_avd(self.android_path, self.avd_name, self.api_level)
|
||||
android.create_avd(self.android_path, self.device, self.skin, self.avd_name, self.api_level)
|
||||
self.assertTrue(mocked_list_dir.called)
|
||||
self.assertTrue(mocked_sys_link.called)
|
||||
self.assertTrue(mocked_suprocess.called)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"""Unit test for appium.py."""
|
||||
from unittest import TestCase
|
||||
|
||||
import os
|
||||
from unittest import TestCase
|
||||
|
||||
import mock
|
||||
|
||||
|
||||
Reference in New Issue
Block a user