|
| 1 | +""" |
| 2 | +Test for android error activity. |
| 3 | +
|
| 4 | +Verify that: |
| 5 | + - If error happens error activity is displayed (debug mode). |
| 6 | + - Stack trace of the error is printed in console. |
| 7 | + - No error activity in release builds. |
| 8 | +""" |
| 9 | + |
| 10 | +import os |
| 11 | + |
| 12 | +from core.base_class.BaseClass import BaseClass |
| 13 | +from core.device.emulator import Emulator |
| 14 | +from core.device.helpers.adb import Adb |
| 15 | +from core.osutils.folder import Folder |
| 16 | +from core.settings.settings import ANDROID_RUNTIME_PATH, ANDROID_KEYSTORE_PATH, ANDROID_KEYSTORE_PASS, \ |
| 17 | + ANDROID_KEYSTORE_ALIAS, ANDROID_KEYSTORE_ALIAS_PASS, EMULATOR_ID |
| 18 | +from core.tns.replace_helper import ReplaceHelper |
| 19 | +from core.tns.tns import Tns |
| 20 | + |
| 21 | + |
| 22 | +class AndroidErrorActivityTests(BaseClass): |
| 23 | + @classmethod |
| 24 | + def setUpClass(cls): |
| 25 | + logfile = os.path.join('out', cls.__name__ + '.txt') |
| 26 | + BaseClass.setUpClass(logfile) |
| 27 | + Emulator.stop() |
| 28 | + Emulator.ensure_available() |
| 29 | + Folder.cleanup(cls.app_name) |
| 30 | + |
| 31 | + Tns.create_app(cls.app_name, |
| 32 | + attributes={'--template': os.path.join('data', 'apps', 'livesync-hello-world.tgz')}, |
| 33 | + update_modules=True) |
| 34 | + Tns.platform_add_android(attributes={'--path': cls.app_name, '--frameworkPath': ANDROID_RUNTIME_PATH}) |
| 35 | + |
| 36 | + # Break the app to test error activity |
| 37 | + file_change = ['app/app.js', 'application.start("main-page");', 'throw new Error("Kill the app!");'] |
| 38 | + ReplaceHelper.replace(cls.app_name, file_change=file_change) |
| 39 | + |
| 40 | + def setUp(self): |
| 41 | + BaseClass.setUp(self) |
| 42 | + |
| 43 | + def tearDown(self): |
| 44 | + Tns.kill() |
| 45 | + BaseClass.tearDown(self) |
| 46 | + |
| 47 | + @classmethod |
| 48 | + def tearDownClass(cls): |
| 49 | + BaseClass.tearDownClass() |
| 50 | + Emulator.stop() |
| 51 | + |
| 52 | + def test_200_error_activity_shown_on_error(self): |
| 53 | + log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False, |
| 54 | + assert_success=False) |
| 55 | + strings = ['Project successfully built', |
| 56 | + 'Successfully installed on device with identifier', EMULATOR_ID, |
| 57 | + 'Successfully synced application', |
| 58 | + 'Error: Kill the app!'] |
| 59 | + Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10) |
| 60 | + |
| 61 | + assert Adb.wait_for_text(device_id=EMULATOR_ID, text="Exception"), "Error activity not found!" |
| 62 | + assert Adb.wait_for_text(device_id=EMULATOR_ID, text="Logcat"), "Error activity not found!" |
| 63 | + assert Adb.wait_for_text(device_id=EMULATOR_ID, text="Error: Kill the app!"), "Error activity not found!" |
| 64 | + |
| 65 | + def test_400_no_error_activity_in_release_builds(self): |
| 66 | + log = Tns.run_android(attributes={'--path': self.app_name, |
| 67 | + '--device': EMULATOR_ID, |
| 68 | + '--keyStorePath': ANDROID_KEYSTORE_PATH, |
| 69 | + '--keyStorePassword': ANDROID_KEYSTORE_PASS, |
| 70 | + '--keyStoreAlias': ANDROID_KEYSTORE_ALIAS, |
| 71 | + '--keyStoreAliasPassword': ANDROID_KEYSTORE_ALIAS_PASS, |
| 72 | + '--release': ''}, wait=False, assert_success=False) |
| 73 | + strings = ['Project successfully built', 'Successfully installed on device with identifier', EMULATOR_ID] |
| 74 | + Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10) |
| 75 | + |
| 76 | + error = Adb.wait_for_text(device_id=EMULATOR_ID, text="Exception") |
| 77 | + assert not error, "Error activity found in release build!" |
0 commit comments