Skip to content

Commit 43329bc

Browse files
committed
Add tests for error activity
- Add tests for error activity - Add tests for NativeScript/nativescript-cli#2818 - Enhancements in test_200_tns_run_android_break_and_fix_app
1 parent 3d3fe06 commit 43329bc

File tree

2 files changed

+81
-2
lines changed

2 files changed

+81
-2
lines changed
+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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!"

tests/emulator/run_android_tests.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,13 @@ def test_200_tns_run_android_break_and_fix_app(self):
213213
app_js_new_path = os.path.join(TEST_RUN_HOME, 'app.js')
214214
File.copy(src=app_js_original_path, dest=app_js_new_path)
215215
File.remove(file_path=app_js_original_path)
216-
strings = ['Successfully synced application', EMULATOR_ID]
216+
verify_app_crash_adb_message = 'has died'
217+
strings = ['Successfully synced application', EMULATOR_ID, verify_app_crash_adb_message]
217218
Tns.wait_for_log(log_file=log, string_list=strings, timeout=30, check_interval=10)
218219

219220
File.copy(src=app_js_new_path, dest=app_js_original_path)
220-
strings = ['Successfully synced application', 'app.js', EMULATOR_ID]
221+
verify_app_loaded = 'JS: Page loaded'
222+
strings = ['Successfully synced application', 'app.js', EMULATOR_ID, verify_app_loaded]
221223
Tns.wait_for_log(log_file=log, string_list=strings, timeout=30, check_interval=10)
222224

223225
# Verify app looks correct inside emulator

0 commit comments

Comments
 (0)