Enable Samsung Galaxy S6

This commit is contained in:
butomo1989
2017-03-16 16:33:26 +01:00
parent 045191439a
commit 135c3e32f1
144 changed files with 703 additions and 84 deletions
+1
View File
@@ -1,5 +1,6 @@
import os
ROOT = '/root'
WORKDIR = os.path.dirname(__file__)
CONFIG_FILE = os.path.join(WORKDIR, 'nodeconfig.json')
LOGGING_FILE = os.path.join(WORKDIR, 'logging.conf')
+56 -47
View File
@@ -14,6 +14,34 @@ TYPE_X86_64 = 'x86_64'
API_LEVEL_ANDROID_5 = 21
def get_available_sdk_packages():
"""
Get list of available sdk packages.
:return: List of available packages.
:rtype: bytearray
"""
logger.info('List of Android SDK: ')
output_str = subprocess.check_output('android list sdk'.split())
logger.info(output_str)
return [output.strip() for output in output_str.split('\n')] if output_str else None
def get_item_position(keyword, items):
"""
Get position of item in array by given keyword.
:return: item position
:rtype: int
"""
pos = 0
for p, v in enumerate(items):
if keyword in v:
pos = p
break # Get the first item that match with keyword
return pos
def get_api_level(android_version):
"""
Get api level of android version.
@@ -72,7 +100,7 @@ def install_package(android_path, emulator_file, api_level, sys_img):
titel=titel, cmd=cmd), shell=True)
def create_avd(android_path, device, skin, avd_name, sys_img, api_level):
def create_avd(android_path, device, avd_name, api_level):
"""
Create android virtual device.
@@ -80,62 +108,43 @@ def create_avd(android_path, device, skin, avd_name, sys_img, api_level):
: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 sys_img: system image
:type sys_img: str
:param api_level: api level
:type api_level: str
"""
# Bug: cannot use skin for system image x86 with android version < 5.0
if sys_img == TYPE_X86:
cmd = 'echo no | android create avd -f -n {name} -t android-{api}'.format(name=avd_name, api=api_level)
else:
# Create android emulator
cmd = 'echo no | android create avd -f -n {name} -t android-{api}'.format(name=avd_name, api=api_level)
if device != 'emulator':
# Link emulator skins
skins_rsc = os.path.join(android_path, 'skins')
skins_dst = os.path.join(android_path, 'platforms', 'android-{api}'.format(api=api_level), 'skins')
from src import ROOT
skin_rsc_path = os.path.join(ROOT, 'devices', 'skins')
logger.info('Skin ressource path: {rsc}'.format(rsc=skin_rsc_path))
for provider in os.listdir(skins_rsc):
provider_devices = os.path.join(skins_rsc, provider)
for device in os.listdir(provider_devices):
os.symlink(os.path.join(provider_devices, device), os.path.join(skins_dst, device))
skin_dst_path = os.path.join(android_path, 'platforms', 'android-{api}'.format(api=api_level), 'skins')
logger.info('Skin destination path: {dst}'.format(dst=skin_dst_path))
# 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)
for s in os.listdir(skin_rsc_path):
os.symlink(os.path.join(skin_rsc_path, s), os.path.join(skin_dst_path, s))
# Hardware and its skin
device_name_bash = device.replace(' ', '\ ')
skin_name = device.replace(' ', '_').lower()
logger.info('device name in bash: {db}, skin name: {skin}'.format(db=device_name_bash, skin=skin_name))
# For custom hardware profile
profile_dst_path = os.path.join(ROOT, '.android', 'devices.xml')
if 'samsung' in device.lower():
# profile file name = skin name
profile_src_path = os.path.join(ROOT, 'devices', 'profiles', '{profile}.xml'.format(profile=skin_name))
logger.info('Hardware profile resource path: {rsc}'.format(rsc=profile_src_path))
logger.info('Hardware profile destination path: {dst}'.format(dst=profile_dst_path))
os.symlink(profile_src_path, profile_dst_path)
# append command
cmd += ' -d {device} -s {skin}'.format(device=device_name_bash, skin=skin_name)
logger.info('AVD creation command: {cmd}'.format(cmd=cmd))
titel = 'AVD creation process'
subprocess.check_call('xterm -T "{titel}" -n "{titel}" -e \"{cmd}\"'.format(
titel=titel, cmd=cmd), shell=True)
def get_available_sdk_packages():
"""
Get list of available sdk packages.
:return: List of available packages.
:rtype: bytearray
"""
logger.info('List of Android SDK: ')
output_str = subprocess.check_output('android list sdk'.split())
logger.info(output_str)
return [output.strip() for output in output_str.split('\n')] if output_str else None
def get_item_position(keyword, items):
"""
Get position of item in array by given keyword.
:return: item position
:rtype: int
"""
pos = 0
for p, v in enumerate(items):
if keyword in v:
pos = p
break # Get the first item that match with keyword
return pos
+24 -18
View File
@@ -11,42 +11,48 @@ def start():
Installation of needed sdk package, creation of android emulator and execution of appium server.
"""
# Get all needed environment variables
# Android SDK path
android_path = os.getenv('ANDROID_HOME', '/root')
logger.info('Android path: {path}'.format(path=android_path))
emulator_type = os.getenv('EMULATOR_TYPE', android.TYPE_ARMEABI).lower()
logger.info('Emulator type: {type}'.format(type=emulator_type))
# Emulator informations
emu_type = os.getenv('EMULATOR_TYPE', android.TYPE_ARMEABI).lower()
emu_type = android.TYPE_ARMEABI if emu_type not in [android.TYPE_ARMEABI, android.TYPE_X86] else \
emu_type
logger.info('Emulator type: {type}'.format(type=emu_type))
emu_file = 'emulator64-x86' if emu_type == android.TYPE_X86 else 'emulator64-arm'
logger.info('Emulator file: {file}'.format(file=emu_file))
# Device name
device = os.getenv('DEVICE', 'Nexus 5')
# Android version
android_version = os.getenv('ANDROID_VERSION', '4.2.2')
logger.info('Android version: {version}'.format(version=android_version))
# Selenium grid connection
connect_to_grid = str_to_bool(str(os.getenv('CONNECT_TO_GRID', False)))
logger.info('Connect to selenium grid? {input}'.format(input=connect_to_grid))
# Install needed sdk packages
emulator_type = android.TYPE_ARMEABI if emulator_type not in [android.TYPE_ARMEABI, android.TYPE_X86] else \
emulator_type
emulator_file = 'emulator64-x86' if emulator_type == android.TYPE_X86 else 'emulator64-arm'
logger.info('Emulator file: {file}'.format(file=emulator_file))
# Install android sdk package
api_level = android.get_api_level(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))
if emulator_type == android.TYPE_X86:
# Bug: cannot use skin for system image x86 with android version < 5.0
if emu_type == android.TYPE_X86:
if int(api_level) < android.API_LEVEL_ANDROID_5:
sys_img = android.TYPE_X86
skin_name = 'emulator'
device = 'emulator'
else:
sys_img = android.TYPE_X86_64
else:
sys_img = '{type}-v7a'.format(type=android.TYPE_ARMEABI)
logger.info('System image: {sys_img}'.format(sys_img=sys_img))
android.install_package(android_path, emulator_file, api_level, sys_img)
android.install_package(android_path, emu_file, api_level, sys_img)
# Create android virtual device
avd_name = '{device}_{version}'.format(device=skin_name, version=android_version)
logger.info('Device: {device}'.format(device=device))
avd_name = '{device}_{version}'.format(device=device.replace(' ', '_').lower(), version=android_version)
logger.info('AVD name: {avd}'.format(avd=avd_name))
android.create_avd(android_path, device_name, skin_name, avd_name, sys_img, api_level)
android.create_avd(android_path, device, avd_name, api_level)
# Run appium server
appium.run(connect_to_grid, avd_name, android_version)
+17 -10
View File
@@ -6,36 +6,43 @@ import mock
from src import android
@mock.patch('os.symlink')
@mock.patch('subprocess.check_call')
@mock.patch('os.symlink')
class TestAvd(TestCase):
"""Unit test class to test method create_avd."""
def setUp(self):
self.android_path = '/root'
self.device = 'Nexus\ 5'
self.skin = 'nexus_5'
self.avd_name = 'nexus_5_5.0'
self.avd_name = 'test_avd'
self.api_level = 21
def test_avd_creation_x86_64(self, mocked_sys_link, mocked_suprocess):
def test_nexus_avd(self, mocked_suprocess, mocked_sys_link):
with mock.patch('os.listdir') as mocked_list_dir:
mocked_list_dir.return_value = ['file1', 'file2']
self.assertFalse(mocked_list_dir.called)
self.assertFalse(mocked_sys_link.called)
self.assertFalse(mocked_suprocess.called)
android.create_avd(self.android_path, self.device, self.skin, self.avd_name, android.TYPE_X86_64,
self.api_level)
android.create_avd(self.android_path, 'Nexus 5', self.avd_name, self.api_level)
self.assertTrue(mocked_list_dir.called)
self.assertTrue(mocked_sys_link.called)
self.assertTrue(mocked_suprocess.called)
def test_avd_creation_x86(self, mocked_sys_link, mocked_suprocess):
def test_samsung_avd(self, mocked_suprocess, mocked_sys_link):
with mock.patch('os.listdir') as mocked_list_dir:
mocked_list_dir.return_value = ['file1', 'file2']
self.assertFalse(mocked_list_dir.called)
self.assertFalse(mocked_sys_link.called)
self.assertFalse(mocked_suprocess.called)
android.create_avd(self.android_path, self.device, self.skin, self.avd_name, android.TYPE_X86,
self.api_level)
android.create_avd(self.android_path, 'Samsung Galaxy S6', self.avd_name, self.api_level)
self.assertTrue(mocked_list_dir.called)
self.assertTrue(mocked_sys_link.called)
self.assertTrue(mocked_suprocess.called)
def test_default_avd(self, mocked_suprocess, mocked_sys_link):
with mock.patch('os.listdir') as mocked_list_dir:
mocked_list_dir.return_value = ['file1', 'file2']
self.assertFalse(mocked_list_dir.called)
self.assertFalse(mocked_sys_link.called)
self.assertFalse(mocked_suprocess.called)
android.create_avd(self.android_path, 'emulator', self.avd_name, self.api_level)
self.assertFalse(mocked_list_dir.called)