3
3
"""
4
4
# pylint: disable=invalid-name
5
5
import os
6
+ import json
6
7
7
8
from core .base_test .tns_test import TnsTest
8
9
from core .utils .assertions import Assert
19
20
PLATFORM_ANDROID_APK_DEBUG_PATH = os .path .join ('platforms' , 'android' , 'app' , 'build' , 'outputs' , 'apk' , 'debug' )
20
21
APP_NAME = AppName .DEFAULT
21
22
APK_DEBUG_PATH = os .path .join (TEST_RUN_HOME , APP_NAME , PLATFORM_ANDROID_APK_DEBUG_PATH , "app-debug.apk" )
23
+ ANALYTICS_FILE = os .path .join (TEST_RUN_HOME , APP_NAME , 'platforms' , 'android' , 'analytics' , 'build-statistics.json' )
22
24
23
25
24
26
class AndroidRuntimePluginTests (TnsTest ):
@@ -39,6 +41,14 @@ def tearDownClass(cls):
39
41
TnsTest .tearDownClass ()
40
42
Folder .clean (os .path .join (TEST_RUN_HOME , APP_NAME ))
41
43
44
+ @staticmethod
45
+ def assert_kotlin_is_working (emulator ):
46
+ assert File .exists (APK_DEBUG_PATH )
47
+ assert File .is_file_in_zip (APK_DEBUG_PATH , os .path .join ("kotlin" )), "Kotlin is not working!"
48
+ Device .click (emulator , text = "TAP" , case_sensitive = True )
49
+ error_message = "Kotlin code is not executed correctly! Logs: "
50
+ assert "Kotlin is here!" in Adb .get_logcat (emulator .id ), error_message + Adb .get_logcat (emulator .id )
51
+
42
52
def test_308_native_package_in_plugin_include_gradle_with_compile (self ):
43
53
"""
44
54
Test native packages in plugin could be used with compile in include gradle
@@ -334,17 +344,8 @@ def test_451_support_external_buildscript_config_in_plugin(self):
334
344
Tns .plugin_add (plugin_path , path = APP_NAME , verify = False )
335
345
336
346
Tns .build_android (os .path .join (TEST_RUN_HOME , APP_NAME ), verify = True )
337
-
338
347
Tns .plugin_remove ("sample-plugin-2" , verify = False , path = APP_NAME )
339
348
340
- @staticmethod
341
- def assert_kotlin_is_working (emulator ):
342
- assert File .exists (APK_DEBUG_PATH )
343
- assert File .is_file_in_zip (APK_DEBUG_PATH , os .path .join ("kotlin" )), "Kotlin is not working!"
344
- Device .click (emulator , text = "TAP" , case_sensitive = True )
345
- error_message = "Kotlin code is not executed correctly! Logs: "
346
- assert "Kotlin is here!" in Adb .get_logcat (emulator .id ), error_message + Adb .get_logcat (emulator .id )
347
-
348
349
def test_452_support_gradle_properties_for_enable_Kotlin_with_jar (self ):
349
350
"""
350
351
Support gradle.properties file for enable Kotlin
@@ -371,22 +372,75 @@ def test_452_support_gradle_properties_for_enable_Kotlin_with_jar(self):
371
372
strings = ['Project successfully built' ,
372
373
'Successfully installed on device with identifier' , self .emulator .id ,
373
374
'Successfully synced application' ]
374
-
375
375
test_result = Wait .until (lambda : all (string in File .read (log .log_file ) for string in strings ), timeout = 300 ,
376
376
period = 5 )
377
377
messages = "App with Kotlin enabled and kotlin jar not build correctly! Logs: "
378
378
assert test_result , messages + File .read (log .log_file )
379
379
380
380
self .assert_kotlin_is_working (self .emulator )
381
+ with open (ANALYTICS_FILE , "r" ) as read_file :
382
+ data = json .load (read_file )
383
+ error_message = "kotlinUsage->hasKotlinRuntimeClasses is not set to True! Analytics is not correct!"
384
+ assert data ["kotlinUsage" ]["hasKotlinRuntimeClasses" ] is True , error_message
385
+ error_message = "kotlinUsage->hasUseKotlinPropertyInApp is not set to True! Analytics is not correct!"
386
+ assert data ["kotlinUsage" ]["hasUseKotlinPropertyInApp" ] is True , error_message
387
+
388
+ def test_453_support_Kotlin_with_jar_without_use_kotlin (self ):
389
+ """
390
+ Support gradle.properties file for enable Kotlin
391
+ https://github.com/NativeScript/android-runtime/issues/1459
392
+ https://github.com/NativeScript/android-runtime/issues/1463
393
+ """
394
+
395
+ source_app_gradle = os .path .join (TEST_RUN_HOME , 'assets' , 'runtime' , 'android' , 'files' ,
396
+ 'android-runtime-1463-1459' , 'analytics' , 'gradle.properties' )
397
+ target_app_gradle = os .path .join (TEST_RUN_HOME , APP_NAME , 'app' , 'App_Resources' , 'Android' )
398
+ File .copy (source = source_app_gradle , target = target_app_gradle , backup_files = True )
399
+ source_app_gradle = os .path .join (TEST_RUN_HOME , 'assets' , 'runtime' , 'android' , 'files' ,
400
+ 'android-runtime-1463-1459' , 'test-jar-1.0-SNAPSHOT.jar' )
401
+ target_app_gradle = os .path .join (TEST_RUN_HOME , APP_NAME , 'app' , 'App_Resources' , 'Android' , 'libs' )
402
+ Folder .create (target_app_gradle )
403
+ Tns .build_android (os .path .join (TEST_RUN_HOME , APP_NAME ), verify = True )
404
+
405
+ with open (ANALYTICS_FILE , "r" ) as read_file :
406
+ data = json .load (read_file )
407
+ error_message = "kotlinUsage->hasKotlinRuntimeClasses is not set to False! Analytics is not correct!"
408
+ assert data ["kotlinUsage" ]["hasKotlinRuntimeClasses" ] is False , error_message
409
+ error_message = "kotlinUsage->hasUseKotlinPropertyInApp is not set to False! Analytics is not correct!"
410
+ assert data ["kotlinUsage" ]["hasUseKotlinPropertyInApp" ] is False , error_message
411
+
412
+ File .copy (source = source_app_gradle , target = target_app_gradle , backup_files = True )
413
+ # Not working https://github.com/NativeScript/android-runtime/issues/1522
414
+ # Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME), verify=True).output
415
+ log = Tns .run_android (APP_NAME , device = self .emulator .id , wait = False , verify = False )
416
+ source_js = os .path .join (TEST_RUN_HOME , 'assets' , 'runtime' , 'android' , 'files' , 'android-runtime-1463-1459' ,
417
+ 'main-view-model.js' )
418
+ target_js = os .path .join (TEST_RUN_HOME , APP_NAME , 'app' , 'main-view-model.js' )
419
+ File .copy (source = source_js , target = target_js , backup_files = True )
420
+ log = Tns .run_android (APP_NAME , device = self .emulator .id , wait = False , verify = False )
381
421
382
- def test_453_support_gradle_properties_for_enable_Kotlin_with_kotlin_file (self ):
422
+ strings = ['Successfully synced application org.nativescript.TestApp on device ' ]
423
+ test_result = Wait .until (lambda : all (string in File .read (log .log_file ) for string in strings ), timeout = 300 ,
424
+ period = 5 )
425
+ messages = "App with Kotlin enabled and kotlin jar not build correctly! Logs: "
426
+ assert test_result , messages + File .read (log .log_file )
427
+ self .assert_kotlin_is_working (self .emulator )
428
+ with open (ANALYTICS_FILE , "r" ) as read_file :
429
+ data = json .load (read_file )
430
+ error_message = "kotlinUsage->hasKotlinRuntimeClasses is not set to True! Analytics is not correct!"
431
+ assert data ["kotlinUsage" ]["hasKotlinRuntimeClasses" ] is True , error_message
432
+ error_message = "kotlinUsage->hasUseKotlinPropertyInApp is not set to False! Analytics is not correct!"
433
+ assert data ["kotlinUsage" ]["hasUseKotlinPropertyInApp" ] is False , error_message
434
+
435
+ def test_454_support_gradle_properties_for_enable_Kotlin_with_kotlin_file (self ):
383
436
"""
384
437
Support gradle.properties file for enable Kotlin
385
438
https://github.com/NativeScript/android-runtime/issues/1459
386
439
https://github.com/NativeScript/android-runtime/issues/1463
387
440
"""
388
- Tns .platform_remove (APP_NAME , platform = Platform .ANDROID )
441
+ Tns .platform_remove (app_name = APP_NAME , platform = Platform .ANDROID )
389
442
Tns .platform_add_android (APP_NAME , framework_path = Android .FRAMEWORK_PATH )
443
+
390
444
Adb .clear_logcat (self .emulator .id )
391
445
source_app_gradle = os .path .join (TEST_RUN_HOME , 'assets' , 'runtime' , 'android' , 'files' ,
392
446
'android-runtime-1463-1459' , 'gradle.properties' )
@@ -413,15 +467,41 @@ def test_453_support_gradle_properties_for_enable_Kotlin_with_kotlin_file(self):
413
467
messages = "App with Kotlin enabled and kotlin jar not build correctly! Logs: "
414
468
assert test_result , messages + File .read (log .log_file )
415
469
self .assert_kotlin_is_working (self .emulator )
416
-
417
- def test_454_support_Kotlin_with_jar_without_use_kotlin (self ):
470
+ with open (ANALYTICS_FILE , "r" ) as read_file :
471
+ data = json .load (read_file )
472
+ error_message = "kotlinUsage->hasKotlinRuntimeClasses is not set to True! Analytics is not correct!"
473
+ assert data ["kotlinUsage" ]["hasKotlinRuntimeClasses" ] is True , error_message
474
+ error_message = "kotlinUsage->hasUseKotlinPropertyInApp is not set to True! Analytics is not correct!"
475
+ assert data ["kotlinUsage" ]["hasUseKotlinPropertyInApp" ] is True , error_message
476
+
477
+ def test_455_analytics_not_generated_when_not_set_as_property_for_enable_Kotlin_with_jar (self ):
418
478
"""
419
479
Support gradle.properties file for enable Kotlin
420
480
https://github.com/NativeScript/android-runtime/issues/1459
421
481
https://github.com/NativeScript/android-runtime/issues/1463
422
482
"""
423
- Tns .plugin_remove ("sample-plugin-2" , verify = False , path = APP_NAME )
483
+ # caused by https://github.com/NativeScript/nativescript-cli/issues/5083
484
+ kotlin_file_in_src = os .path .join (TEST_RUN_HOME , APP_NAME , 'platforms' , 'android' , 'app' , 'src' , 'main' , 'java' ,
485
+ 'com' ,
486
+ 'Test.kt' )
487
+ kotlin_file_in_build = os .path .join (TEST_RUN_HOME , APP_NAME , 'platforms' , 'android' , 'app' , 'build' , 'tmp' ,
488
+ 'kotlin-classes' , 'debug' , 'com' ,
489
+ 'Test.class' )
490
+ if File .exists (kotlin_file_in_src ):
491
+ File .delete (kotlin_file_in_src )
492
+ if File .exists (kotlin_file_in_build ):
493
+ File .delete (kotlin_file_in_build )
494
+ else :
495
+ assert False , "Temp gradle folder is missing for generated kotlin file!"
496
+
497
+ # bug ends here
498
+ if File .exists (ANALYTICS_FILE ):
499
+ File .delete (ANALYTICS_FILE )
424
500
Adb .clear_logcat (self .emulator .id )
501
+ source_app_gradle = os .path .join (TEST_RUN_HOME , 'assets' , 'runtime' , 'android' , 'files' ,
502
+ 'android-runtime-1463-1459' , 'no-analytics' , 'gradle.properties' )
503
+ target_app_gradle = os .path .join (TEST_RUN_HOME , APP_NAME , 'app' , 'App_Resources' , 'Android' )
504
+ File .copy (source = source_app_gradle , target = target_app_gradle , backup_files = True )
425
505
source_app_gradle = os .path .join (TEST_RUN_HOME , 'assets' , 'runtime' , 'android' , 'files' ,
426
506
'android-runtime-1463-1459' , 'test-jar-1.0-SNAPSHOT.jar' )
427
507
target_app_gradle = os .path .join (TEST_RUN_HOME , APP_NAME , 'app' , 'App_Resources' , 'Android' , 'libs' )
@@ -436,14 +516,44 @@ def test_454_support_Kotlin_with_jar_without_use_kotlin(self):
436
516
strings = ['Project successfully built' ,
437
517
'Successfully installed on device with identifier' , self .emulator .id ,
438
518
'Successfully synced application' ]
439
-
440
519
test_result = Wait .until (lambda : all (string in File .read (log .log_file ) for string in strings ), timeout = 300 ,
441
520
period = 5 )
442
521
messages = "App with Kotlin enabled and kotlin jar not build correctly! Logs: "
443
522
assert test_result , messages + File .read (log .log_file )
444
- self .assert_kotlin_is_working (self .emulator )
523
+ error_message = "Analytics data should NOT be generated when gatherAnalyticsData is not set!"
524
+ assert not File .exists (ANALYTICS_FILE ), error_message
445
525
446
- def test_455_gradle_hooks (self ):
526
+ def test_456_analytics_working_correct_when_property_is_set_without_Kotlin (self ):
527
+ """
528
+ Support gradle.properties file for enable Kotlin
529
+ https://github.com/NativeScript/android-runtime/issues/1459
530
+ https://github.com/NativeScript/android-runtime/issues/1463
531
+ """
532
+ Adb .clear_logcat (self .emulator .id )
533
+ source_app_gradle = os .path .join (TEST_RUN_HOME , 'assets' , 'runtime' , 'android' , 'files' ,
534
+ 'android-runtime-1463-1459' , 'analytics' , 'gradle.properties' )
535
+ target_app_gradle = os .path .join (TEST_RUN_HOME , APP_NAME , 'app' , 'App_Resources' , 'Android' )
536
+ File .copy (source = source_app_gradle , target = target_app_gradle , backup_files = True )
537
+
538
+ log = Tns .run_android (APP_NAME , device = self .emulator .id , wait = False , verify = False )
539
+
540
+ strings = ['Project successfully built' ,
541
+ 'Successfully installed on device with identifier' , self .emulator .id ,
542
+ 'Successfully synced application' ]
543
+ test_result = Wait .until (lambda : all (string in File .read (log .log_file ) for string in strings ), timeout = 300 ,
544
+ period = 5 )
545
+ messages = "App with Kotlin enabled and kotlin jar not build correctly! Logs: "
546
+ assert test_result , messages + File .read (log .log_file )
547
+ error_message = "Analytics data should be generated when gatherAnalyticsData is set!"
548
+ assert File .exists (ANALYTICS_FILE ), error_message
549
+ with open (ANALYTICS_FILE , "r" ) as read_file :
550
+ data = json .load (read_file )
551
+ error_message = "kotlinUsage->hasKotlinRuntimeClasses is not set to False! Analytics is not correct!"
552
+ assert data ["kotlinUsage" ]["hasKotlinRuntimeClasses" ] is False , error_message
553
+ error_message = "kotlinUsage->hasUseKotlinPropertyInApp is not set to False! Analytics is not correct!"
554
+ assert data ["kotlinUsage" ]["hasUseKotlinPropertyInApp" ] is False , error_message
555
+
556
+ def test_457_gradle_hooks (self ):
447
557
"""
448
558
Test gradle hooks works correctly
449
559
https://docs.nativescript.org/core-concepts/android-runtime/advanced-topics/gradle-hooks
0 commit comments