Exemple #1
0
    def test_181_tns_run_android_console_dir(self):
        """
         Test console.dir() of different objects.
        """

        # Change main-page.js so it contains console logging
        source_js = os.path.join('data', 'console-dir', 'main-page.js')
        target_js = os.path.join(self.app_name, 'app', 'main-page.js')
        File.copy(src=source_js, dest=target_js)

        log = Tns.run_android(attributes={
            '--path': self.app_name,
            '--device': EMULATOR_ID
        },
                              wait=False,
                              assert_success=False)
        strings = [
            'Project successfully built',
            'Successfully installed on device with identifier', EMULATOR_ID,
            'Successfully synced application', "true", "false", "null",
            "undefined", "-1", "text", "==== object dump start ====",
            "name: \"John\"", "age: \"34\"", "==== object dump end ====",
            self.max_long_string
        ]

        Tns.wait_for_log(log_file=log,
                         string_list=strings,
                         timeout=180,
                         check_interval=10)
        assert self.very_long_string not in log
    def test_301_build_project_with_space_release(self):
        Tns.create_app(self.app_name_space)
        Tns.platform_add_android(
            attributes={"--path": "\"" + self.app_name_space + "\"", "--frameworkPath": ANDROID_PACKAGE})

        # Ensure ANDROID_KEYSTORE_PATH contain spaces (verification for CLI issue 2650)
        Folder.create("with space")
        base_path, file_name = os.path.split(ANDROID_KEYSTORE_PATH)
        cert_with_space_path = os.path.join("with space", file_name)
        File.copy(src=ANDROID_KEYSTORE_PATH, dest=cert_with_space_path)

        # Verify project builds
        Tns.build_android(attributes={"--path": "\"" + self.app_name_space + "\"",
                                      "--keyStorePath": "\"" + cert_with_space_path + "\"",
                                      "--keyStorePassword": ANDROID_KEYSTORE_PASS,
                                      "--keyStoreAlias": ANDROID_KEYSTORE_ALIAS,
                                      "--keyStoreAliasPassword": ANDROID_KEYSTORE_ALIAS_PASS,
                                      "--release": ""
                                      })

        output = File.read(self.app_name_space + os.sep + "package.json")
        assert app_identifier in output.lower()

        output = File.read(
            self.app_name_space + "/" + TnsAsserts.PLATFORM_ANDROID_SRC_MAIN_PATH + "AndroidManifest.xml")
        assert app_identifier in output.lower()
    def test_181_tns_run_android_console_dir(self):
        """
         Test console.dir() of different objects.
        """

        # Change main-page.js so it contains console logging
        source_js = os.path.join('data', 'console-dir', 'main-page.js')
        target_js = os.path.join(self.app_name, 'app', 'main-page.js')
        File.copy(src=source_js, dest=target_js)

        log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False,
                              assert_success=False)
        strings = ['Project successfully built',
                   'Successfully installed on device with identifier', EMULATOR_ID,
                   'Successfully synced application',
                   "true",
                   "false",
                   "null",
                   "undefined",
                   "-1",
                   "text",
                   "==== object dump start ====",
                   "name: \"John\"",
                   "age: \"34\"",
                   "==== object dump end ====",
                   self.max_long_string
                   ]

        Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10)
        assert self.very_long_string not in log
Exemple #4
0
    def test_200_prepare_additional_appresources(self):
        # prepare project
        output = Tns.prepare_ios(attributes={"--path": self.app_name})
        TnsAsserts.prepared(self.app_name,
                            platform=Platform.IOS,
                            output=output,
                            prepare=Prepare.FULL)

        # Create new files in AppResources
        File.copy(
            self.app_name +
            "/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-76.png",
            self.app_name + "/app/App_Resources/iOS/newDefault.png")

        # prepare project
        output = Tns.prepare_ios(attributes={"--path": self.app_name})
        TnsAsserts.prepared(self.app_name,
                            platform=Platform.IOS,
                            output=output,
                            prepare=Prepare.INCREMENTAL)

        # Verify XCode Project include files from App Resources folder
        output = run(
            "cat " + self.app_name +
            "/platforms/ios/TestApp.xcodeproj/project.pbxproj | grep newDefault.png"
        )
        assert "newDefault.png" in output
    def test_360_tns_run_android_with_jar_file_in_plugin(self):
        """
        App should not crash when reference .jar file in some plugin
        https://github.com/NativeScript/android-runtime/pull/905
        """

        # Add .jar file in plugin and modify the app to reference it
        custom_jar_file = os.path.join('data', 'issues', 'android-runtime-pr-905', 'customLib.jar')
        modules_widgets = os.path.join(self.app_name, 'node_modules', 'tns-core-modules-widgets', 'platforms',
                                       'android')
        File.copy(src=custom_jar_file, dest=modules_widgets)

        source = os.path.join('data', 'issues', 'android-runtime-pr-905', 'app.js')
        target = os.path.join(self.app_name, 'app', 'app.js')
        File.copy(src=source, dest=target)

        # `tns run android` and wait until app is deployed
        log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False,
                              assert_success=False)
        strings = ['Project successfully built',
                   'Successfully installed on device with identifier', EMULATOR_ID,
                   'Successfully synced application']
        Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10)

        # Verify app looks correct inside emulator
        Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID,
                            expected_image='livesync-hello-world_home')
Exemple #6
0
    def test_181_tns_run_ios_console_dir(self):
        """
         Test console.dir() of different objects.
        """

        # Change main-page.js so it contains console logging
        source_js = os.path.join('data', 'console-dir', 'main-page.js')
        target_js = os.path.join(self.app_name, 'app', 'main-page.js')
        File.copy(src=source_js, dest=target_js)

        john_obj = "==== object dump start ====\n" \
                   "name: John\n" \
                   "age: 34\n" \
                   "==== object dump end ===="

        log = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': ''}, wait=False, assert_success=False)
        strings = ['Project successfully built',
                   'Successfully installed on device with identifier', self.SIMULATOR_ID,
                   "true",
                   "false",
                   "null",
                   "undefined",
                   "-1",
                   "text",
                   self.max_long_string,
                   john_obj
                   ]

        Tns.wait_for_log(log_file=log, string_list=strings, timeout=150, check_interval=10)
        assert self.very_long_string not in log
Exemple #7
0
    def test_280_tns_run_android_console_time(self):
        # Copy the app folder (app is modified in order to get some console logs on loaded)
        source = os.path.join('data', 'apps', 'livesync-hello-world-ng', 'src')
        target = os.path.join(self.app_name, 'src')
        Folder.cleanup(target)
        Folder.copy(src=source, dst=target)

        # Replace app.component.ts to use console.time() and console.timeEnd()
        source = os.path.join('data', 'issues', 'ios-runtime-843', 'app.component.ts')
        target = os.path.join(self.app_name, 'src', 'app', 'app.component.ts')
        File.copy(src=source, dest=target)

        # `tns run android` and wait until app is deployed
        log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False,
                              assert_success=False)

        # Verify the app is running
        strings = ['Successfully synced application',
                   'Application loaded!',
                   'Home page loaded!']

        Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10, clean_log=False)

        # Verify initial state of the app
        Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID,
                            expected_image='ng-hello-world-home-white', tolerance=5.0)

        # Verify console.time() works
        console_time = ['JS: startup:']
        Tns.wait_for_log(log_file=log, string_list=console_time)
Exemple #8
0
    def test_301_build_project_with_space_release(self):
        Tns.create_app(self.app_name_space)
        Tns.platform_add_android(
            attributes={
                "--path": "\"" + self.app_name_space + "\"",
                "--frameworkPath": ANDROID_PACKAGE
            })

        # Ensure ANDROID_KEYSTORE_PATH contain spaces (verification for CLI issue 2650)
        Folder.create("with space")
        base_path, file_name = os.path.split(ANDROID_KEYSTORE_PATH)
        cert_with_space_path = os.path.join("with space", file_name)
        File.copy(src=ANDROID_KEYSTORE_PATH, dest=cert_with_space_path)

        # Verify project builds
        Tns.build_android(
            attributes={
                "--path": "\"" + self.app_name_space + "\"",
                "--keyStorePath": "\"" + cert_with_space_path + "\"",
                "--keyStorePassword": ANDROID_KEYSTORE_PASS,
                "--keyStoreAlias": ANDROID_KEYSTORE_ALIAS,
                "--keyStoreAliasPassword": ANDROID_KEYSTORE_ALIAS_PASS,
                "--release": ""
            })

        output = File.read(self.app_name_space + os.sep + "package.json")
        assert app_identifier in output.lower()

        output = File.read(self.app_name_space + "/" +
                           TnsAsserts.PLATFORM_ANDROID_SRC_MAIN_PATH +
                           "AndroidManifest.xml")
        assert app_identifier in output.lower()
    def test_210_tns_run_ios_add_remove_files_and_folders(self):
        """
        New files and folders should be synced properly.
        """

        log = Tns.run_ios(attributes={'--path': self.app_name, '--device': self.DEVICE_ID}, wait=False,
                          assert_success=False)
        strings = ['Successfully synced application', self.DEVICE_ID]
        Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10)

        # Add new files
        new_file_name = 'app2.css'
        source_file = os.path.join(self.app_name, 'app', 'app.css')
        destination_file = os.path.join(self.app_name, 'app', new_file_name)
        File.copy(source_file, destination_file)
        strings = ['Successfully transferred', new_file_name, 'Refreshing application']
        Tns.wait_for_log(log_file=log, string_list=strings)

        # Revert changes(rename file and delete file)
        # File.copy(destination_file, source_file)
        # File.remove(destination_file)
        # strings = ['Successfully transferred', new_file_name]
        # Tns.wait_for_log(log_file=log, string_list=strings)

        # Add folder
        new_folder_name = 'test2'
        source_file = os.path.join(self.app_name, 'app', 'test')
        destination_file = os.path.join(self.app_name, 'app', new_folder_name)
        Folder.copy(source_file, destination_file)
        strings = ['Successfully transferred test.txt', 'Successfully synced application']
        Tns.wait_for_log(log_file=log, string_list=strings)
    def test_210_tns_run_android_add_remove_files_and_folders(self):
        """
        New files and folders should be synced properly.
        """

        log = Tns.run_android(attributes={'--path': self.app_name, '--device': self.DEVICE_ID}, wait=False,
                              assert_success=False)
        strings = ['Successfully synced application', self.DEVICE_ID]
        Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10)

        # Add new files
        new_file_name = 'main-page2.xml'
        source_file = os.path.join(self.app_name, 'app', 'main-page.xml')
        destination_file = os.path.join(self.app_name, 'app', new_file_name)
        File.copy(source_file, destination_file)
        strings = ['Successfully transferred main-page2.xml', 'Successfully synced application', self.DEVICE_ID]
        Tns.wait_for_log(log_file=log, string_list=strings)

        # Verify new file is synced and available on device.
        error_message = 'Newly created file {0} not found on {1}'.format(new_file_name, self.DEVICE_ID)
        app_id = Tns.get_app_id(app_name=self.app_name)
        path = 'app/{0}'.format(new_file_name)
        assert Adb.path_exists(device_id=self.DEVICE_ID, package_id=app_id, path=path), error_message

        # Revert changes(rename file and delete file)
        File.copy(destination_file, source_file)
        File.remove(destination_file)
        strings = ['Successfully transferred main-page.xml', 'Successfully synced application', self.DEVICE_ID]
        Tns.wait_for_log(log_file=log, string_list=strings)

        # Verify new file is synced and available on device.
        error_message = '{0} was deleted, but still available on {1}'.format(new_file_name, self.DEVICE_ID)
        assert Adb.path_does_not_exist(device_id=self.DEVICE_ID, package_id=app_id, path=path), error_message

        # Add folder
        new_folder_name = 'feature2'
        source_file = os.path.join(self.app_name, 'app', 'feature1')
        destination_file = os.path.join(self.app_name, 'app', new_folder_name)
        Folder.copy(source_file, destination_file)
        strings = ['Successfully transferred', 'Successfully transferred', 'feature1.js', self.DEVICE_ID]
        Tns.wait_for_log(log_file=log, string_list=strings)

        # Verify new folder is synced and available on device.
        error_message = 'Newly created folder {0} not found on {1}'.format(new_folder_name, self.DEVICE_ID)
        path = 'app/{0}'.format(new_folder_name)
        assert Adb.path_exists(device_id=self.DEVICE_ID, package_id=app_id, path=path, timeout=20), error_message
        path = 'app/{0}/{1}'.format(new_folder_name, 'feature1.js')
        assert Adb.path_exists(device_id=self.DEVICE_ID, package_id=app_id, path=path, timeout=20), error_message

        # Delete folder
        Folder.cleanup(destination_file)
        strings = ['Successfully synced application', self.DEVICE_ID]
        Tns.wait_for_log(log_file=log, string_list=strings)

        # Verify new folder is deleted from device.
        error_message = 'Deleted folder {0} is still available on {1}'.format(new_folder_name, self.DEVICE_ID)
        assert Adb.path_does_not_exist(device_id=self.DEVICE_ID, package_id=app_id, path=path), error_message
Exemple #11
0
 def pack(folder, output_file):
     try:
         Folder.navigate_to(folder)
         run('npm pack', log_level=CommandLogLevel.SILENT)
         src_file = File.find_by_extension('tgz')[0]
         File.copy(src=src_file, dest=output_file)
         File.remove(src_file)
     except:
         print 'Failed to pack {0}'.format(folder)
     Folder.navigate_to(TEST_RUN_HOME, relative_from_current_folder=False)
 def pack(folder, output_file):
     try:
         Folder.navigate_to(folder)
         run('npm pack', log_level=CommandLogLevel.SILENT)
         src_file = File.find_by_extension('tgz')[0]
         File.copy(src=src_file, dest=output_file)
         File.remove(src_file)
     except:
         print 'Failed to pack {0}'.format(folder)
     Folder.navigate_to(TEST_RUN_HOME, relative_from_current_folder=False)
Exemple #13
0
    def test_008_ios_run_hmr_console_log(self):
        source_js = os.path.join('data', "issues", 'console-log-hmr', 'main-view-model.js')
        target_js = os.path.join(self.app_name, 'app', 'main-view-model.js')
        File.copy(src=source_js, dest=target_js)

        log = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': '', '--hmr': ''}, wait=False,
                                assert_success=False)
        strings = ['LOG Hello']
        Tns.wait_for_log(log_file=log, string_list=strings)

        Helpers.ios_screen_match(sim_id=self.SIMULATOR_ID, image=HelpersHMR.image_original, timeout=120)
    def test_205_build_android_app_bundle_env_snapshot(self):
        """Build app with android app bundle option with --bundle and optimisations for snapshot.
           Verify the output(app.aab) and use bundletool to deploy on device."""
        # This test will not run on windows because env.snapshot option is not available on that OS
        
        path_to_aab = os.path.join(self.app_name, "platforms", "android", "app", "build", "outputs", "bundle", "release", "app.aab")
      
        #Configure app with snapshot optimisations
        source = os.path.join('data', 'abdoid-app-bundle', 'app.gradle')
        target = os.path.join(self.app_name, 'app', 'App_Resources', 'Android', 'app.gradle' )
        File.copy(src=source, dest=target)

        source = os.path.join('data', 'abdoid-app-bundle', 'webpack.config.js')
        target = os.path.join(self.app_name, 'webpack.config.js' )
        File.copy(src=source, dest=target)

        #env.snapshot is applicable only in release build 
        output = Tns.build_android(attributes={"--path": self.app_name,
                                      "--keyStorePath": ANDROID_KEYSTORE_PATH,
                                      "--keyStorePassword": ANDROID_KEYSTORE_PASS,
                                      "--keyStoreAlias": ANDROID_KEYSTORE_ALIAS,
                                      "--keyStoreAliasPassword": ANDROID_KEYSTORE_ALIAS_PASS,
                                      "--release": "",
                                      "--aab": "",
                                      "--env.uglify": "",
                                      "--env.snapshot": "",
                                      "--bundle": ""
                                      }, assert_success=False)
        assert "The build result is located at:" in output
        assert path_to_aab in output
        assert File.exists(path_to_aab)

        #Verify app can be deployed on emulator via bundletool
        # Use bundletool to create the .apks file
        self.bundletool_build(self.bundletool_path, path_to_aab, self.path_to_apks)
        assert File.exists(self.path_to_apks)

        # Verify that the correct .so file is included in the package
        File.unzip(self.path_to_apks, os.path.join(self.app_name, 'apks'))
        File.unzip(os.path.join(self.app_name, 'apks', 'splits', 'base-x86.apk'), os.path.join(self.app_name,'base_apk'))
        assert File.exists(os.path.join(self.app_name, 'base_apk', 'lib', 'x86', 'libNativeScript.so'))

        # Deploy on device
        self.bundletool_deploy(self.bundletool_path, self.path_to_apks, device_id=EMULATOR_ID)
        
        # Start the app on device
        Adb.start_app(EMULATOR_ID, "org.nativescript.TestApp")
        
        # Verify app looks correct inside emulator
        app_started = Device.wait_for_text(device_id=EMULATOR_ID, text='TAP')
        assert app_started, 'App is not started on device'
    def test_008_android_run_hmr_console_log(self):
        source_js = os.path.join('data', "issues", 'console-log-hmr', 'main-view-model.js')
        target_js = os.path.join(self.app_name, 'app', 'main-view-model.js')
        File.copy(src=source_js, dest=target_js)

        log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID, '--hmr': ''}, wait=False,
                              assert_success=False)

        strings = ['LOG Hello']
        Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10)

        # Verify app looks correct inside emulator
        Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID,
                            expected_image=HelpersHMR.image_original)
    def test_200_prepare_additional_appresources(self):
        # prepare project
        output = Tns.prepare_ios(attributes={"--path": self.app_name})
        TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.FULL)

        # Create new files in AppResources
        File.copy(self.app_name + "/app/App_Resources/iOS/Assets.xcassets/AppIcon.appiconset/icon-76.png",
                  self.app_name + "/app/App_Resources/iOS/newDefault.png")

        # prepare project
        output = Tns.prepare_ios(attributes={"--path": self.app_name})
        TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.INCREMENTAL)

        # Verify XCode Project include files from App Resources folder
        output = run("cat " + self.app_name + "/platforms/ios/TestApp.xcodeproj/project.pbxproj | grep newDefault.png")
        assert "newDefault.png" in output
    def test_220_build_ios_with_custom_plist(self):
        # Update Info.plist
        src_file = os.path.join(TEST_RUN_HOME, 'data', 'Info.plist')
        target_file = os.path.join(TEST_RUN_HOME, self.app_name, 'app', 'App_Resources', 'iOS', 'Info.plist')
        File.remove(target_file)
        File.copy(src=src_file, dest=target_file)

        # Prepare in debug
        final_plist = os.path.join(TEST_RUN_HOME, self.app_name, 'platforms', 'ios', 'TestApp', 'TestApp-Info.plist')
        Tns.prepare_ios(attributes={"--path": self.app_name})
        assert "<string>fbXXXXXXXXX</string>" in File.read(final_plist)
        assert "<string>orgnativescriptTestApp</string>" in File.read(final_plist)

        # Prepare in release
        Tns.prepare_ios(attributes={"--path": self.app_name, '--release': ''})
        assert "<string>fbXXXXXXXXX</string>" in File.read(final_plist)
        assert "<string>orgnativescriptTestApp</string>" not in File.read(final_plist)
    def test_180_tns_run_android_console_logging(self):
        """
         Test console info, warn, error, assert, trace, time and logging of different objects.
        """

        # Change main-page.js so it contains console logging
        source_js = os.path.join('data', 'console-log', 'main-page.js')
        target_js = os.path.join(self.app_name, 'app', 'main-page.js')
        File.copy(src=source_js, dest=target_js)

        log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False,
                              assert_success=False)
        strings = ['Project successfully built',
                   'Successfully installed on device with identifier', EMULATOR_ID,
                   'Successfully synced application',
                   "true",
                   "false",
                   "null",
                   "undefined",
                   "-1",
                   "text",
                   "\"name\": \"John\",",
                   "\"age\": 34",
                   "number: -1",
                   "string: text",
                   "text -1",
                   "info",
                   "warn",
                   "error",
                   "Assertion failed:  false == true",
                   "Assertion failed:  empty string evaluates to 'false'",
                   "Trace: console.trace() called",
                   "at pageLoaded",
                   "Button(8)",
                   "-1 text {",
                   "[1, 5, 12.5, {", "\"name\": \"John\",",
                   "\"age\": 34",
                   "}, text, 42]",
                   "Time:",
                   self.max_long_string,
                   "### TEST END ###"
                   ]

        Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10, clean_log=False)
        assert "1 equals 1" not in log
        assert self.very_long_string not in log
Exemple #19
0
    def test_210_tns_run_ios_add_remove_files_and_folders(self):
        """
        New files and folders should be synced properly.
        """

        log = Tns.run_ios(attributes={
            '--path': self.app_name,
            '--device': self.DEVICE_ID
        },
                          wait=False,
                          assert_success=False)
        strings = ['Successfully synced application', self.DEVICE_ID]
        Tns.wait_for_log(log_file=log,
                         string_list=strings,
                         timeout=120,
                         check_interval=10)

        # Add new files
        new_file_name = 'app2.css'
        source_file = os.path.join(self.app_name, 'app', 'app.css')
        destination_file = os.path.join(self.app_name, 'app', new_file_name)
        File.copy(source_file, destination_file)
        strings = [
            'Successfully transferred', new_file_name, 'Refreshing application'
        ]
        Tns.wait_for_log(log_file=log, string_list=strings)

        # Revert changes(rename file and delete file)
        # File.copy(destination_file, source_file)
        # File.remove(destination_file)
        # strings = ['Successfully transferred', new_file_name]
        # Tns.wait_for_log(log_file=log, string_list=strings)

        # Add folder
        new_folder_name = 'test2'
        source_file = os.path.join(self.app_name, 'app', 'test')
        destination_file = os.path.join(self.app_name, 'app', new_folder_name)
        Folder.copy(source_file, destination_file)
        strings = [
            'Successfully transferred test.txt',
            'Successfully synced application'
        ]
        Tns.wait_for_log(log_file=log, string_list=strings)
    def copy(src, dst, only_files=False):
        """
        Copy src folder in the dst folder.
        :param only_files: If it's set to True - only the files from src folder are copied to dst folder.
        If it's set to False - src folder with all files in it are copied.
        """
        if only_files is True:
            files = os.listdir(src)

            for f in files:
                f_path = os.path.join(src, f)
                File.copy(f_path, dst)
        else:
            try:
                shutil.copytree(src, dst, symlinks=True)
            except OSError as exc:  # python >2.5
                if exc.errno == errno.ENOTDIR:
                    shutil.copy(src, dst)
                else:
                    raise
Exemple #21
0
    def copy(src, dst, only_files=False):
        """
        Copy src folder in the dst folder.
        :param only_files: If it's set to True - only the files from src folder are copied to dst folder.
        If it's set to False - src folder with all files in it are copied.
        """
        if only_files is True:
            files = os.listdir(src)

            for f in files:
                f_path = os.path.join(src, f)
                File.copy(f_path, dst)
        else:
            try:
                shutil.copytree(src, dst, symlinks=True)
            except OSError as exc:  # python >2.5
                if exc.errno == errno.ENOTDIR:
                    shutil.copy(src, dst)
                else:
                    raise
Exemple #22
0
    def test_360_tns_run_android_with_jar_file_in_plugin(self):
        """
        App should not crash when reference .jar file in some plugin
        https://github.com/NativeScript/android-runtime/pull/905
        """

        # Add .jar file in plugin and modify the app to reference it
        custom_jar_file = os.path.join('data', 'issues',
                                       'android-runtime-pr-905',
                                       'customLib.jar')
        modules_widgets = os.path.join(self.app_name, 'node_modules',
                                       'tns-core-modules-widgets', 'platforms',
                                       'android')
        File.copy(src=custom_jar_file, dest=modules_widgets)

        source = os.path.join('data', 'issues', 'android-runtime-pr-905',
                              'app.js')
        target = os.path.join(self.app_name, 'app', 'app.js')
        File.copy(src=source, dest=target)

        # `tns run android` and wait until app is deployed
        log = Tns.run_android(attributes={
            '--path': self.app_name,
            '--device': EMULATOR_ID
        },
                              wait=False,
                              assert_success=False)
        strings = [
            'Project successfully built',
            'Successfully installed on device with identifier', EMULATOR_ID,
            'Successfully synced application'
        ]
        Tns.wait_for_log(log_file=log,
                         string_list=strings,
                         timeout=180,
                         check_interval=10)

        # Verify app looks correct inside emulator
        Device.screen_match(device_name=EMULATOR_NAME,
                            device_id=EMULATOR_ID,
                            expected_image='livesync-hello-world_home')
Exemple #23
0
    def test_220_build_ios_with_custom_plist(self):
        # Update Info.plist
        src_file = os.path.join(TEST_RUN_HOME, 'data', 'Info.plist')
        target_file = os.path.join(TEST_RUN_HOME, self.app_name, 'app',
                                   'App_Resources', 'iOS', 'Info.plist')
        File.remove(target_file)
        File.copy(src=src_file, dest=target_file)

        # Prepare in debug
        final_plist = os.path.join(TEST_RUN_HOME, self.app_name, 'platforms',
                                   'ios', 'TestApp', 'TestApp-Info.plist')
        Tns.prepare_ios(attributes={"--path": self.app_name})
        assert "<string>fbXXXXXXXXX</string>" in File.read(final_plist)
        assert "<string>orgnativescriptTestApp</string>" in File.read(
            final_plist)

        # Prepare in release
        Tns.prepare_ios(attributes={"--path": self.app_name, '--release': ''})
        assert "<string>fbXXXXXXXXX</string>" in File.read(final_plist)
        assert "<string>orgnativescriptTestApp</string>" not in File.read(
            final_plist)
Exemple #24
0
    def test_300_prepare_ios_preserve_case(self):
        File.copy(
            self.app_name +
            "/node_modules/tns-core-modules/application/application-common.js",
            self.app_name +
            "/node_modules/tns-core-modules/application/New-application-common.js"
        )
        File.copy(
            self.app_name +
            "/node_modules/tns-core-modules/application/application.android.js",
            self.app_name +
            "/node_modules/tns-core-modules/application/New-application.android.js"
        )
        File.copy(
            self.app_name +
            "/node_modules/tns-core-modules/application/application.ios.js",
            self.app_name +
            "/node_modules/tns-core-modules/application/New-application.ios.js"
        )

        output = Tns.prepare_ios(attributes={"--path": self.app_name})
        TnsAsserts.prepared(self.app_name,
                            platform=Platform.IOS,
                            output=output,
                            prepare=Prepare.FULL)

        # Verify case is preserved
        path = TnsAsserts._get_ios_modules_path(self.app_name)
        assert File.exists(path + 'application/New-application-common.js')
        assert File.exists(path + 'application/New-application.js')
        assert not File.exists(path + 'application/New-application.ios.js')
Exemple #25
0
    def test_200_tns_run_android_extending_class_inside_file_containing_dots(self):
        """Test for https://github.com/NativeScript/android-runtime/issues/761"""

        # Copy the app folder (app is modified in order to get some console logs on loaded)
        source = os.path.join('data', 'apps', 'livesync-hello-world-ng', 'src')
        target = os.path.join(self.app_name, 'src')
        Folder.cleanup(target)
        Folder.copy(src=source, dst=target)
        
        source_html = os.path.join('data', 'issues', 'android-runtime-761', 'items.component.html')
        target_html = os.path.join(self.app_name, 'src', 'app', 'item', 'items.component.html')
        File.copy(src=source_html, dest=target_html)

        source_ts = os.path.join('data', 'issues', 'android-runtime-761', 'items.component.ts')
        target_ts = os.path.join(self.app_name, 'src', 'app', 'item', 'items.component.ts')
        File.copy(src=source_ts, dest=target_ts)

        source_xml = os.path.join('data', 'issues', 'android-runtime-761', 'AndroidManifest.xml')
        target_xml = os.path.join(self.app_name, 'App_Resources', 'Android', 'src', 'main', 'AndroidManifest.xml')
        File.copy(src=source_xml, dest=target_xml)

        # Verify the app is running
        log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False,
                              assert_success=False)
        strings = ['Project successfully built',
                   'Successfully installed on device with identifier', EMULATOR_ID,
                   'Successfully synced application']
        Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10)
    def test_370_tns_run_android_with_jar_and_aar_files_in_app_res(self):
        """
        App should not crash when reference .jar or/and .aar file in App_Resources/Android/libs
        https://github.com/NativeScript/android-runtime/issues/899
        """

        # Create libs/ in app/App_resources/, add .jar and .aar files in it and modify the app to reference them
        curr_folder = os.getcwd()
        Folder.navigate_to(os.path.join(self.app_name, 'app', 'App_Resources', 'Android'))
        Folder.create("libs")
        app_res_libs = os.path.join(self.app_name, 'app', 'App_Resources', 'Android', 'libs')
        Folder.navigate_to(curr_folder)

        custom_jar_file = os.path.join('data', 'issues', 'android-runtime-pr-905', 'customLib.jar')
        custom_aar_file = os.path.join('data', 'issues', 'android-runtime-899', 'mylibrary.aar')

        File.copy(src=custom_jar_file, dest=app_res_libs)
        File.copy(src=custom_aar_file, dest=app_res_libs)

        source = os.path.join('data', 'issues', 'android-runtime-899', 'app.js')
        target = os.path.join(self.app_name, 'app', 'app.js')
        File.copy(src=source, dest=target)

        # `tns run android` and wait until app is deployed
        log = Tns.run_android(attributes={'--path': self.app_name, '--device': EMULATOR_ID}, wait=False,
                              assert_success=False)
        strings = ['Project successfully built',
                   'Successfully installed on device with identifier', EMULATOR_ID,
                   'Successfully synced application']
        Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10)

        # Verify app looks correct inside emulator
        Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID,
                            expected_image='livesync-hello-world_home')
Exemple #27
0
    def test_320_build_ios_with_custom_entitlements(self):
        Tns.build_ios(attributes={"--path": self.app_name})

        # Add entitlements in app/App_Resources/iOS/app.entitlements
        source = os.path.join(TEST_RUN_HOME, 'data', 'entitlements',
                              'app.entitlements')
        target = os.path.join(self.app_name, 'app', 'App_Resources', 'iOS',
                              'app.entitlements')
        File.copy(src=source, dest=target)

        # Build again and verify entitlements are merged
        Tns.build_ios(attributes={"--path": self.app_name})
        entitlements_path = self.app_name + '/platforms/ios/' + self.app_name + '/' + self.app_name + '.entitlements'
        assert File.exists(entitlements_path), "Entitlements file is missing!"
        entitlements_content = File.read(entitlements_path)
        assert '<key>aps-environment</key>' in entitlements_content, "Entitlements file content is wrong!"
        assert '<string>development</string>' in entitlements_content, "Entitlements file content is wrong!"

        # Install plugin with entitlements, build again and verify entitlements are merged
        plugin_path = os.path.join(TEST_RUN_HOME, 'data', 'plugins',
                                   'nativescript-test-entitlements-1.0.0.tgz')
        Npm.install(package=plugin_path, option='--save', folder=self.app_name)
        Tns.build_ios(attributes={"--path": self.app_name})
        entitlements_content = File.read(entitlements_path)
        assert '<key>aps-environment</key>' in entitlements_content, "Entitlements file content is wrong!"
        assert '<string>development</string>' in entitlements_content, "Entitlements file content is wrong!"
        assert '<key>inter-app-audio</key>' in entitlements_content, "Entitlements file content is wrong!"
        assert '<true/>' in entitlements_content, "Entitlements file content is wrong!"

        # Build in release, for device (provision without entitlements)
        output = Tns.build_ios(attributes={
            "--path": self.app_name,
            "--forDevice": "",
            "--release": ""
        },
                               assert_success=False)
        assert "Provisioning profile " in output
        assert "doesn't include the aps-environment and inter-app-audio entitlements" in output
Exemple #28
0
    def test_180_tns_run_android_console_logging(self):
        """
         Test console info, warn, error, assert, trace, time and logging of different objects.
        """

        # Change main-page.js so it contains console logging
        source_js = os.path.join('data', 'console-log', 'main-page.js')
        target_js = os.path.join(self.app_name, 'app', 'main-page.js')
        File.copy(src=source_js, dest=target_js)

        log = Tns.run_android(attributes={
            '--path': self.app_name,
            '--device': EMULATOR_ID
        },
                              wait=False,
                              assert_success=False)
        strings = [
            'Project successfully built',
            'Successfully installed on device with identifier', EMULATOR_ID,
            'Successfully synced application', "true", "false", "null",
            "undefined", "-1", "text", "\"name\": \"John\",", "\"age\": 34",
            "number: -1", "string: text", "text -1", "info", "warn", "error",
            "Assertion failed:  false == true",
            "Assertion failed:  empty string evaluates to 'false'",
            "Trace: console.trace() called", "at pageLoaded", "Button(8)",
            "-1 text {", "[1, 5, 12.5, {", "\"name\": \"John\",",
            "\"age\": 34", "}, text, 42]", "Time:", self.max_long_string,
            "### TEST END ###"
        ]

        Tns.wait_for_log(log_file=log,
                         string_list=strings,
                         timeout=180,
                         check_interval=10,
                         clean_log=False)
        assert "1 equals 1" not in log
        assert self.very_long_string not in log
Exemple #29
0
    def test_008_android_run_hmr_console_log(self):
        source_js = os.path.join('data', "issues", 'console-log-hmr',
                                 'main-view-model.js')
        target_js = os.path.join(self.app_name, 'app', 'main-view-model.js')
        File.copy(src=source_js, dest=target_js)

        log = Tns.run_android(attributes={
            '--path': self.app_name,
            '--device': EMULATOR_ID,
            '--hmr': ''
        },
                              wait=False,
                              assert_success=False)

        strings = ['LOG Hello']
        Tns.wait_for_log(log_file=log,
                         string_list=strings,
                         timeout=120,
                         check_interval=10)

        # Verify app looks correct inside emulator
        Device.screen_match(device_name=EMULATOR_NAME,
                            device_id=EMULATOR_ID,
                            expected_image=HelpersHMR.image_original)
Exemple #30
0
    def test_370_tns_run_android_with_jar_and_aar_files_in_app_res(self):
        """
        App should not crash when reference .jar or/and .aar file in App_Resources/Android/libs
        https://github.com/NativeScript/android-runtime/issues/899
        """

        # Create libs/ in app/App_resources/, add .jar and .aar files in it and modify the app to reference them
        curr_folder = os.getcwd()
        Folder.navigate_to(
            os.path.join(self.app_name, 'app', 'App_Resources', 'Android'))
        Folder.create("libs")
        app_res_libs = os.path.join(self.app_name, 'app', 'App_Resources',
                                    'Android', 'libs')
        Folder.navigate_to(curr_folder)

        custom_jar_file = os.path.join('data', 'issues',
                                       'android-runtime-pr-905',
                                       'customLib.jar')
        custom_aar_file = os.path.join('data', 'issues', 'android-runtime-899',
                                       'mylibrary.aar')

        File.copy(src=custom_jar_file, dest=app_res_libs)
        File.copy(src=custom_aar_file, dest=app_res_libs)

        source = os.path.join('data', 'issues', 'android-runtime-899',
                              'app.js')
        target = os.path.join(self.app_name, 'app', 'app.js')
        File.copy(src=source, dest=target)

        # `tns run android` and wait until app is deployed
        log = Tns.run_android(attributes={
            '--path': self.app_name,
            '--device': EMULATOR_ID
        },
                              wait=False,
                              assert_success=False)
        strings = [
            'Project successfully built',
            'Successfully installed on device with identifier', EMULATOR_ID,
            'Successfully synced application'
        ]
        Tns.wait_for_log(log_file=log,
                         string_list=strings,
                         timeout=180,
                         check_interval=10)

        # Verify app looks correct inside emulator
        Device.screen_match(device_name=EMULATOR_NAME,
                            device_id=EMULATOR_ID,
                            expected_image='livesync-hello-world_home')
    def test_300_prepare_ios_preserve_case(self):
        File.copy(self.app_name + "/node_modules/tns-core-modules/application/application-common.js",
                  self.app_name + "/node_modules/tns-core-modules/application/New-application-common.js")
        File.copy(self.app_name + "/node_modules/tns-core-modules/application/application.android.js",
                  self.app_name + "/node_modules/tns-core-modules/application/New-application.android.js")
        File.copy(self.app_name + "/node_modules/tns-core-modules/application/application.ios.js",
                  self.app_name + "/node_modules/tns-core-modules/application/New-application.ios.js")

        output = Tns.prepare_ios(attributes={"--path": self.app_name})
        TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.FULL)

        # Verify case is preserved
        path = TnsAsserts._get_ios_modules_path(self.app_name)
        assert File.exists(path + 'application/New-application-common.js')
        assert File.exists(path + 'application/New-application.js')
        assert not File.exists(path + 'application/New-application.ios.js')
Exemple #32
0
    def test_300_prepare_android_remove_old_files(self):
        Tns.prepare_android(attributes={"--path": self.app_name})

        # Add new files and delete old files
        time.sleep(1)
        File.copy(self.app_name + "/app/app.js", self.app_name + "/app/app-new.js")
        File.copy(self.app_name + "/app/app.css", self.app_name + "/app/app-new.css")
        File.copy(self.app_name + "/app/main-page.xml", self.app_name + "/app/main-page-new.xml")
        File.remove(self.app_name + "/app/app.js")
        File.remove(self.app_name + "/app/app.css")
        File.remove(self.app_name + "/app/main-page.xml")

        Tns.prepare_android(attributes={"--path": self.app_name})

        # Verify new files are in available in platforms folder
        app_path = os.path.join(self.app_name, TnsAsserts.PLATFORM_ANDROID_APP_PATH)
        assert File.exists(os.path.join(app_path, 'app-new.js'))
        assert File.exists(os.path.join(app_path, 'app-new.css'))
        assert File.exists(os.path.join(app_path, 'main-page-new.xml'))

        # Verify old files are removed from folder
        assert not File.exists(os.path.join(app_path, 'app.js'))
        assert not File.exists(os.path.join(app_path, 'app.css'))
        assert not File.exists(os.path.join(app_path, 'main-page.xml'))
Exemple #33
0
    def test_301_prepare_android_platform_specific_files(self):
        Tns.prepare_android(attributes={"--path": self.app_name})

        # Add set of platform specific files
        File.copy(self.app_name + "/app/app.js", self.app_name + "/app/app.ios.js")
        File.copy(self.app_name + "/app/app.js", self.app_name + "/app/app.android.js")
        File.copy(self.app_name + "/app/app.js", self.app_name + "/app/appios.js")
        File.copy(self.app_name + "/app/app.js", self.app_name + "/app/appandroid.js")
        File.copy(self.app_name + "/app/app.js", self.app_name + "/app/ios.js")
        File.copy(self.app_name + "/app/app.js", self.app_name + "/app/android.js")

        File.copy(self.app_name + "/app/app.css", self.app_name + "/app/app.ios.css")
        File.copy(self.app_name + "/app/app.css", self.app_name + "/app/app.android.css")
        File.copy(self.app_name + "/app/app.js", self.app_name + "/app/appNew.js")
        File.copy(self.app_name + "/app/app.css", self.app_name + "/app/appNew.css")
        File.remove(self.app_name + "/app/app.js")
        File.remove(self.app_name + "/app/app.css")

        Tns.prepare_android(attributes={"--path": self.app_name})

        # Verify new files are in available in platforms folder
        app_path = os.path.join(self.app_name, TnsAsserts.PLATFORM_ANDROID_APP_PATH)
        assert File.exists(os.path.join(app_path, 'app.css'))
        assert File.exists(os.path.join(app_path, 'app.js'))
        assert File.exists(os.path.join(app_path, 'appandroid.js'))
        assert File.exists(os.path.join(app_path, 'appios.js'))
        assert File.exists(os.path.join(app_path, 'android.js'))
        assert File.exists(os.path.join(app_path, 'ios.js'))
        assert not File.exists(os.path.join(app_path, 'app.ios.css'))
        assert not File.exists(os.path.join(app_path, 'app.android.css'))
Exemple #34
0
    def test_205_build_android_app_bundle_env_snapshot(self):
        """Build app with android app bundle option with --bundle and optimisations for snapshot.
           Verify the output(app.aab) and use bundletool to deploy on device."""
        # This test will not run on windows because env.snapshot option is not available on that OS

        path_to_aab = os.path.join(self.app_name, "platforms", "android",
                                   "app", "build", "outputs", "bundle",
                                   "release", "app.aab")

        #Configure app with snapshot optimisations
        source = os.path.join('data', 'abdoid-app-bundle', 'app.gradle')
        target = os.path.join(self.app_name, 'app', 'App_Resources', 'Android',
                              'app.gradle')
        File.copy(src=source, dest=target)

        source = os.path.join('data', 'abdoid-app-bundle', 'webpack.config.js')
        target = os.path.join(self.app_name, 'webpack.config.js')
        File.copy(src=source, dest=target)

        #env.snapshot is applicable only in release build
        output = Tns.build_android(attributes={
            "--path": self.app_name,
            "--keyStorePath": ANDROID_KEYSTORE_PATH,
            "--keyStorePassword": ANDROID_KEYSTORE_PASS,
            "--keyStoreAlias": ANDROID_KEYSTORE_ALIAS,
            "--keyStoreAliasPassword": ANDROID_KEYSTORE_ALIAS_PASS,
            "--release": "",
            "--aab": "",
            "--env.uglify": "",
            "--env.snapshot": "",
            "--bundle": ""
        },
                                   assert_success=False)
        assert "The build result is located at:" in output
        assert path_to_aab in output
        assert File.exists(path_to_aab)

        #Verify app can be deployed on emulator via bundletool
        # Use bundletool to create the .apks file
        self.bundletool_build(self.bundletool_path, path_to_aab,
                              self.path_to_apks)
        assert File.exists(self.path_to_apks)

        # Verify that the correct .so file is included in the package
        File.unzip(self.path_to_apks, os.path.join(self.app_name, 'apks'))
        File.unzip(
            os.path.join(self.app_name, 'apks', 'splits', 'base-x86.apk'),
            os.path.join(self.app_name, 'base_apk'))
        assert File.exists(
            os.path.join(self.app_name, 'base_apk', 'lib', 'x86',
                         'libNativeScript.so'))

        # Deploy on device
        self.bundletool_deploy(self.bundletool_path,
                               self.path_to_apks,
                               device_id=EMULATOR_ID)

        # Start the app on device
        Adb.start_app(EMULATOR_ID, "org.nativescript.TestApp")

        # Verify app looks correct inside emulator
        app_started = Device.wait_for_text(device_id=EMULATOR_ID, text='TAP')
        assert app_started, 'App is not started on device'
Exemple #35
0
    def screen_match(device_name,
                     device_id,
                     expected_image,
                     tolerance=0.1,
                     timeout=30):
        """
        Verify screen match expected image.
        :param device_name: Name of device (name of Android avd image, or name or iOS Simulator).
        :param device_id: Device identifier (example: `emulator-5554`).
        :param expected_image: Name of expected image.
        :param tolerance: Tolerance in percents.
        :param timeout: Timeout in seconds.
        """

        device_type = Device.__get_device_type(device_id)
        if device_type == DeviceType.IOS:
            type = run(command="ideviceinfo | grep ProductType",
                       log_level=CommandLogLevel.SILENT)
            type = type.replace(',', '')
            type = type.replace('ProductType:', '').strip(' ')
            device_name = type

        print "Verify {0} looks correct...".format(expected_image)
        expected_image_original_path = os.path.join(
            "data", "images", device_name, "{0}.png".format(expected_image))
        actual_image_path = os.path.join(
            OUTPUT_FOLDER, "images", device_name,
            "{0}_actual.png".format(expected_image))
        diff_image_path = os.path.join(OUTPUT_FOLDER, "images", device_name,
                                       "{0}_diff.png".format(expected_image))
        expected_image_path = os.path.join(
            OUTPUT_FOLDER, "images", device_name,
            "{0}_expected.png".format(expected_image))

        if File.exists(expected_image_original_path):
            t_end = time.time() + timeout
            diff = 100.0
            are_equal = False
            comparison_result = None
            while time.time() < t_end:
                time.sleep(1)
                if Device.get_screen(device_id=device_id,
                                     file_path=actual_image_path):
                    comparison_result = ImageUtils.image_match(
                        actual_image_path=actual_image_path,
                        expected_image_path=expected_image_original_path,
                        tolerance=tolerance)
                    are_equal = comparison_result[0]
                    diff = comparison_result[1]
                    if are_equal:
                        print "{0} looks OK.".format(expected_image)
                        break  # Exist if images look OK.
                    else:
                        time.sleep(2)
                        print "{0} does not match. Diff is {1} %. Wait...".format(
                            expected_image, diff)
                else:
                    print "Failed to get image from {0}".format(device_id)

            # Report results after timeout is over
            if not are_equal:
                # Save expected and diff images (actual is already there)
                diff_image_final_path = os.path.join("out", diff_image_path)
                print "Diff image will be saved at " + diff_image_final_path
                File.copy(src=expected_image_original_path,
                          dest=expected_image_path)
                comparison_result[2].save(diff_image_final_path)
                # Get logs (from android devices).
                if device_type == DeviceType.EMULATOR or device_type == DeviceType.ANDROID:
                    log_path = diff_image_final_path.replace(
                        '_diff.png', '.log')
                    print "Console logs will be saved at " + log_path
                    log = Adb.get_logcat(device_id=device_id)
                    if len(log) < 10000:
                        print log
                    File.write(file_path=log_path, text=log)
            assert are_equal, "Current image on {0} does not match expected image {1}. Diff is {2}%". \
                format(device_name, expected_image, diff)
        else:
            # If expected image is not found actual will be saved as expected.
            print "Expected image not found. Actual image will be saved as expected: " + expected_image_original_path
            time.sleep(timeout)
            Device.get_screen(device_id, expected_image_original_path)
            assert False, "Expected image not found!"
    def screen_match(device_name, device_id, expected_image, tolerance=0.1, timeout=30):
        """
        Verify screen match expected image.
        :param device_name: Name of device (name of Android avd image, or name or iOS Simulator).
        :param device_id: Device identifier (example: `emulator-5554`).
        :param expected_image: Name of expected image.
        :param tolerance: Tolerance in percents.
        :param timeout: Timeout in seconds.
        """

        device_type = Device.__get_device_type(device_id)
        if device_type == DeviceType.IOS:
            type = run(command="ideviceinfo | grep ProductType", log_level=CommandLogLevel.SILENT)
            type = type.replace(',', '')
            type = type.replace('ProductType:', '').strip(' ')
            device_name = type

        print "Verify {0} looks correct...".format(expected_image)
        expected_image_original_path = os.path.join("data", "images", device_name, "{0}.png".format(expected_image))
        actual_image_path = os.path.join(OUTPUT_FOLDER, "images", device_name, "{0}_actual.png".format(expected_image))
        diff_image_path = os.path.join(OUTPUT_FOLDER, "images", device_name, "{0}_diff.png".format(expected_image))
        expected_image_path = os.path.join(OUTPUT_FOLDER, "images", device_name,
                                           "{0}_expected.png".format(expected_image))

        if File.exists(expected_image_original_path):
            t_end = time.time() + timeout
            diff = 100.0
            are_equal = False
            comparison_result = None
            while time.time() < t_end:
                time.sleep(1)
                if Device.get_screen(device_id=device_id, file_path=actual_image_path):
                    comparison_result = ImageUtils.image_match(actual_image_path=actual_image_path,
                                                               expected_image_path=expected_image_original_path,
                                                               tolerance=tolerance)
                    are_equal = comparison_result[0]
                    diff = comparison_result[1]
                    if are_equal:
                        print "{0} looks OK.".format(expected_image)
                        break  # Exist if images look OK.
                    else:
                        time.sleep(2)
                        print "{0} does not match. Diff is {1} %. Wait...".format(expected_image, diff)
                else:
                    print "Failed to get image from {0}".format(device_id)

            # Report results after timeout is over
            if not are_equal:
                # Save expected and diff images (actual is already there)
                diff_image_final_path = os.path.join("out", diff_image_path)
                print "Diff image will be saved at " + diff_image_final_path
                File.copy(src=expected_image_original_path, dest=expected_image_path)
                comparison_result[2].save(diff_image_final_path)
                # Get logs (from android devices).
                if device_type == DeviceType.EMULATOR or device_type == DeviceType.ANDROID:
                    log_path = diff_image_final_path.replace('_diff.png', '.log')
                    print "Console logs will be saved at " + log_path
                    log = Adb.get_logcat(device_id=device_id)
                    if len(log) < 10000:
                        print log
                    File.write(file_path=log_path, text=log)
            assert are_equal, "Current image on {0} does not match expected image {1}. Diff is {2}%". \
                format(device_name, expected_image, diff)
        else:
            # If expected image is not found actual will be saved as expected.
            print "Expected image not found. Actual image will be saved as expected: " + expected_image_original_path
            time.sleep(timeout)
            Device.get_screen(device_id, expected_image_original_path)
            assert False, "Expected image not found!"
    def test_001_build_android(self):
        Tns.build_android(attributes={"--path": self.app_name})
        assert File.pattern_exists(self.platforms_android, "*.aar")
        assert not File.pattern_exists(self.platforms_android, "*.plist")
        assert not File.pattern_exists(self.platforms_android, "*.android.js")
        assert not File.pattern_exists(self.platforms_android, "*.ios.js")

        # Configs are respected
        assert 'debug' in File.read(os.path.join(self.app_name, TnsAsserts.PLATFORM_ANDROID_APP_PATH, 'config.json'))

        # And new platform specific file and verify next build is ok (test for issue #2697)
        src = os.path.join(self.app_name, 'app', 'app.js')
        dest_1 = os.path.join(self.app_name, 'app', 'new.android.js')
        dest_2 = os.path.join(self.app_name, 'app', 'new.ios.js')
        File.copy(src=src, dest=dest_1)
        File.copy(src=src, dest=dest_2)

        # Verify incremental native build
        before_build = datetime.datetime.now()
        output = Tns.build_android(attributes={"--path": self.app_name})
        after_build = datetime.datetime.now()
        assert "Gradle build..." in output, "Gradle build not called."
        assert output.count("Gradle build...") is 1, "Only one gradle build is triggered."
        assert (after_build - before_build).total_seconds() < 20, "Incremental build takes more then 20 sec."

        # Verify platform specific files
        assert File.pattern_exists(self.platforms_android, "*.aar")
        assert not File.pattern_exists(self.platforms_android, "*.plist")
        assert not File.pattern_exists(self.platforms_android, "*.android.js")
        assert not File.pattern_exists(self.platforms_android, "*.ios.js")

        # Verify apk does not contain aar files
        archive = ZipFile(os.path.join(self.app_name, TnsAsserts.PLATFORM_ANDROID_APK_DEBUG_PATH, self.debug_apk))
        archive.extractall(self.app_name + "/temp")
        archive.close()
        # Ceanup META-INF folder. It contains com.android.support.... files which are expected to be there due to
        # https://github.com/NativeScript/nativescript-cli/pull/3923
        Folder.cleanup(os.path.join(self.app_name, "temp", "META-INF"))
        assert not File.pattern_exists(self.app_name + "/temp", "*.aar")
        assert not File.pattern_exists(self.app_name + "/temp", "*.plist")
        assert not File.pattern_exists(self.app_name + "/temp", "*.android.*")
        assert not File.pattern_exists(self.app_name + "/temp", "*.ios.*")
        Folder.cleanup(self.app_name + "/temp")

        # Verify incremental native build
        before_build = datetime.datetime.now()
        output = Tns.build_android(attributes={"--path": self.app_name})
        after_build = datetime.datetime.now()
        assert "Gradle build..." in output, "Gradle build not called."
        assert output.count("Gradle build...") is 1, "Only one gradle build is triggered."
        assert (after_build - before_build).total_seconds() < 20, "Incremental build takes more then 20 sec."

        # Verify clean build force native project rebuild
        before_build = datetime.datetime.now()
        output = Tns.build_android(attributes={"--path": self.app_name, "--clean": ""})
        after_build = datetime.datetime.now()
        build_time = (after_build - before_build).total_seconds()
        assert "Gradle clean..." in output, "Gradle clean is not called."
        assert "Gradle build..." in output, "Gradle build is not called."
        assert output.count("Gradle build...") is 1, "More than 1 gradle build is triggered."
        assert build_time > 10, "Clean build takes less then 15 sec."
        assert build_time < 90, "Clean build takes more than 90 sec."
Exemple #38
0
    def test_180_tns_run_ios_console_log(self):
        """
         Test console info, warn, error, assert, trace, time and logging of different objects.
        """

        # Change main-page.js so it contains console logging
        source_js = os.path.join('data', 'console-log', 'main-page.js')
        target_js = os.path.join(self.app_name, 'app', 'main-page.js')
        File.copy(src=source_js, dest=target_js)

        john_obj = "{\n" \
                   "\"name\": \"John\",\n" \
                   "\"age\": 34\n" \
                   "}"

        john_obj2 = "[\n" + "1,\n" \
                            "5,\n" \
                            "12.5,\n" \
                            "{\n" \
                            "\"name\": \"John\",\n" \
                            "\"age\": 34\n" \
                            "},\n" \
                            "\"text\",\n" \
                            "42\n" \
                            "]"

        log = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': ''}, wait=False, assert_success=False)
        strings = ['Project successfully built',
                   'Successfully installed on device with identifier', self.SIMULATOR_ID,
                   "CONSOLE LOG file:///app/main-page.js",
                   "true",
                   "false",
                   "null",
                   "undefined",
                   "-1",
                   "text",
                   john_obj,
                   "number: -1",
                   "string: text",
                   "text -1",
                   "CONSOLE INFO",
                   "info",
                   "CONSOLE WARN",
                   "warn",
                   "CONSOLE ERROR",
                   "error",
                   "false == true",
                   "empty string evaluates to 'false'",
                   "CONSOLE TRACE file:///app/main-page.js",
                   "console.trace() called",
                   "pageLoaded",
                   "Button(8)",
                   "-1 text {",
                   john_obj2,
                   self.max_long_string,
                   "CONSOLE INFO Time:",
                   "### TEST END ###"
                   ]

        Tns.wait_for_log(log_file=log, string_list=strings, timeout=150, check_interval=10)
        assert self.very_long_string not in log
Exemple #39
0
    def test_001_build_android(self):
        Tns.build_android(attributes={"--path": self.app_name})
        assert File.pattern_exists(self.platforms_android, "*.aar")
        assert not File.pattern_exists(self.platforms_android, "*.plist")
        assert not File.pattern_exists(self.platforms_android, "*.android.js")
        assert not File.pattern_exists(self.platforms_android, "*.ios.js")

        # Configs are respected
        assert 'debug' in File.read(
            os.path.join(self.app_name, TnsAsserts.PLATFORM_ANDROID_APP_PATH,
                         'config.json'))

        # And new platform specific file and verify next build is ok (test for issue #2697)
        src = os.path.join(self.app_name, 'app', 'app.js')
        dest_1 = os.path.join(self.app_name, 'app', 'new.android.js')
        dest_2 = os.path.join(self.app_name, 'app', 'new.ios.js')
        File.copy(src=src, dest=dest_1)
        File.copy(src=src, dest=dest_2)

        # Verify incremental native build
        before_build = datetime.datetime.now()
        output = Tns.build_android(attributes={"--path": self.app_name})
        after_build = datetime.datetime.now()
        assert "Gradle build..." in output, "Gradle build not called."
        assert output.count(
            "Gradle build...") is 1, "Only one gradle build is triggered."
        assert (after_build - before_build).total_seconds(
        ) < 20, "Incremental build takes more then 20 sec."

        # Verify platform specific files
        assert File.pattern_exists(self.platforms_android, "*.aar")
        assert not File.pattern_exists(self.platforms_android, "*.plist")
        assert not File.pattern_exists(self.platforms_android, "*.android.js")
        assert not File.pattern_exists(self.platforms_android, "*.ios.js")

        # Verify apk does not contain aar files
        archive = ZipFile(
            os.path.join(self.app_name,
                         TnsAsserts.PLATFORM_ANDROID_APK_DEBUG_PATH,
                         self.debug_apk))
        archive.extractall(self.app_name + "/temp")
        archive.close()
        # Ceanup META-INF folder. It contains com.android.support.... files which are expected to be there due to
        # https://github.com/NativeScript/nativescript-cli/pull/3923
        Folder.cleanup(os.path.join(self.app_name, "temp", "META-INF"))
        assert not File.pattern_exists(self.app_name + "/temp", "*.aar")
        assert not File.pattern_exists(self.app_name + "/temp", "*.plist")
        assert not File.pattern_exists(self.app_name + "/temp", "*.android.*")
        assert not File.pattern_exists(self.app_name + "/temp", "*.ios.*")
        Folder.cleanup(self.app_name + "/temp")

        # Verify incremental native build
        before_build = datetime.datetime.now()
        output = Tns.build_android(attributes={"--path": self.app_name})
        after_build = datetime.datetime.now()
        assert "Gradle build..." in output, "Gradle build not called."
        assert output.count(
            "Gradle build...") is 1, "Only one gradle build is triggered."
        assert (after_build - before_build).total_seconds(
        ) < 20, "Incremental build takes more then 20 sec."

        # Verify clean build force native project rebuild
        before_build = datetime.datetime.now()
        output = Tns.build_android(attributes={
            "--path": self.app_name,
            "--clean": ""
        })
        after_build = datetime.datetime.now()
        build_time = (after_build - before_build).total_seconds()
        assert "Gradle clean..." in output, "Gradle clean is not called."
        assert "Gradle build..." in output, "Gradle build is not called."
        assert output.count(
            "Gradle build...") is 1, "More than 1 gradle build is triggered."
        assert build_time > 10, "Clean build takes less then 15 sec."
        assert build_time < 90, "Clean build takes more than 90 sec."