|
| 1 | +import os |
| 2 | + |
| 3 | +from core.device.device import Device |
| 4 | +from core.device.helpers.adb import Adb |
| 5 | +from core.settings.settings import EMULATOR_ID, EMULATOR_NAME, SIMULATOR_NAME |
| 6 | +from core.tns.tns import Tns |
| 7 | +from core.tns.tns_verifications import TnsAsserts |
| 8 | + |
| 9 | + |
| 10 | +class Helpers(object): |
| 11 | + @staticmethod |
| 12 | + def get_apk_path(app_name, config): |
| 13 | + if "debug" in config.lower(): |
| 14 | + return os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID_APK_PATH, app_name + "-debug.apk") |
| 15 | + else: |
| 16 | + return os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID_APK_PATH, app_name + "-release.apk") |
| 17 | + |
| 18 | + @staticmethod |
| 19 | + def get_ipa_path(app_name): |
| 20 | + return os.path.join(app_name, 'platforms', 'ios', 'build', 'device', app_name + '.ipa') |
| 21 | + |
| 22 | + @staticmethod |
| 23 | + def get_app_path(app_name): |
| 24 | + return os.path.join(app_name, 'platforms', 'ios', 'build', 'emulator', app_name + '.app') |
| 25 | + |
| 26 | + @staticmethod |
| 27 | + def run_android_via_adb(app_name, config, image): |
| 28 | + Tns.kill() |
| 29 | + Helpers.emulator_cleanup(app_name=app_name) |
| 30 | + Helpers.install_and_run_app(app_name=app_name, config=config) |
| 31 | + Helpers.android_screen_match(app_name=app_name, image=image) |
| 32 | + |
| 33 | + @staticmethod |
| 34 | + def emulator_cleanup(app_name): |
| 35 | + app_id = Tns.get_app_id(app_name) |
| 36 | + Adb.clear_logcat(device_id=EMULATOR_ID) |
| 37 | + Adb.stop_application(device_id=EMULATOR_ID, app_id=app_id) |
| 38 | + Adb.uninstall(app_id=app_id, device_id=EMULATOR_ID, assert_success=False) |
| 39 | + assert not Adb.is_application_running(device_id=EMULATOR_ID, app_id=app_id) |
| 40 | + |
| 41 | + @staticmethod |
| 42 | + def install_and_run_app(app_name, config): |
| 43 | + Adb.install(apk_file_path=Helpers.get_apk_path(app_name=app_name, config=config), device_id=EMULATOR_ID) |
| 44 | + Adb.start_app(device_id=EMULATOR_ID, app_id="org.nativescript." + app_name) |
| 45 | + |
| 46 | + @staticmethod |
| 47 | + def android_screen_match(app_name, image): |
| 48 | + app_id = Tns.get_app_id(app_name) |
| 49 | + Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, expected_image=image) |
| 50 | + Adb.stop_application(device_id=EMULATOR_ID, app_id=Tns.get_app_id(app_name)) |
| 51 | + assert not Adb.is_application_running(device_id=EMULATOR_ID, app_id=app_id) |
| 52 | + |
| 53 | + @staticmethod |
| 54 | + def ios_screen_match(sim_id, image): |
| 55 | + Device.screen_match(device_name=SIMULATOR_NAME, device_id=sim_id, expected_image=image) |
0 commit comments