コード例 #1
0
    def test_500_test_ES6_support(self):
        """
         https://github.com/NativeScript/android-runtime/issues/1375
        """
        Folder.clean(os.path.join(TEST_RUN_HOME, APP_NAME))
        Tns.create(
            app_name=APP_NAME,
            template="https://github.com/NativeScript/es6-syntax-app.git",
            update=True)

        Tns.platform_add_android(APP_NAME,
                                 framework_path=Android.FRAMEWORK_PATH)
        log = Tns.run_android(APP_NAME,
                              device=self.emulator.id,
                              wait=False,
                              verify=False)
        strings = [
            'Successfully synced application', 'on device', self.emulator.id
        ]

        test_result = Wait.until(lambda: all(string in File.read(log.log_file)
                                             for string in strings),
                                 timeout=120,
                                 period=5)
        assert test_result, "App not build correctly after updating tns-core modules! Logs: " + File.read(
            log.log_file)
        button_text = "Use ES6 language features"

        test_result = Wait.until(
            lambda: Device.is_text_visible(self.emulator, button_text),
            timeout=30,
            period=5)
        message = "Use ES6 language features Button is missing on the device! The app has crashed!"
        assert test_result, message

        Device.click(self.emulator, text=button_text, case_sensitive=False)
        test_result = Wait.until(
            lambda: "class com.js.NativeList" in File.read(log.log_file),
            timeout=25,
            period=5)
        assert test_result, "com.js.NativeList not found! Logs: " + File.read(
            log.log_file)

        test_result = Wait.until(
            lambda: Device.is_text_visible(self.emulator, button_text),
            timeout=30,
            period=5)
        assert test_result, message
コード例 #2
0
    def test_443_build_app_and_assert_that_tns_core_modules_could_be_updated(
            self):
        """
         Test update of tns-core-modules works correctly if you have build the app first
         https://github.com/NativeScript/android-runtime/issues/1257
        """
        Folder.clean(os.path.join(TEST_RUN_HOME, APP_NAME))
        Tns.create(app_name=APP_NAME,
                   template=Template.HELLO_WORLD_JS.local_package)
        Tns.platform_add_android(APP_NAME,
                                 framework_path=Android.FRAMEWORK_PATH)
        log = Tns.run_android(APP_NAME,
                              device=self.emulator.id,
                              wait=False,
                              verify=False)

        strings = [
            'Successfully synced application', 'on device', self.emulator.id
        ]

        test_result = Wait.until(lambda: all(string in File.read(log.log_file)
                                             for string in strings),
                                 timeout=240,
                                 period=5)
        assert test_result, "App not build correctly ! Logs: " + File.read(
            log.log_file)
        Npm.install(package=Packages.MODULES,
                    folder=os.path.join(TEST_RUN_HOME, APP_NAME))
        Tns.plugin_add(plugin_name="[email protected]",
                       path=os.path.join(TEST_RUN_HOME, APP_NAME))
        log = Tns.run_android(APP_NAME,
                              device=self.emulator.id,
                              wait=False,
                              verify=False)

        strings = [
            'Successfully synced application', 'on device', self.emulator.id
        ]

        test_result = Wait.until(lambda: all(string in File.read(log.log_file)
                                             for string in strings),
                                 timeout=120,
                                 period=5)
        assert test_result, "App not build correctly after updating tns-core modules! Logs: " + File.read(
            log.log_file)
        test_result = Wait.until(
            lambda: Device.is_text_visible(self.emulator, "TAP", True),
            timeout=90,
            period=5)
        assert test_result, "TAP Button is missing on the device! Update of tns-core-modules not successful!"
コード例 #3
0
 def test_444_test_useV8Symbols_flag_in_package_json(self):
     """
      https://github.com/NativeScript/android-runtime/issues/1368
     """
     log = Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME))
     # check the default value for v8 symbols
     strings = [
         'adding nativescript runtime package dependency: nativescript-optimized-with-inspector'
     ]
     test_result = Wait.until(lambda: all(string in log.output
                                          for string in strings),
                              timeout=240,
                              period=5)
     assert test_result, "Missing nativescript runtime package dependency! Logs: " + log.output
     File.copy(
         os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                      'files', 'android-runtime-1368', 'package.json'),
         os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'package.json'), True)
     # check useV8Symbols flag is working
     log = Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME))
     strings = [
         'adding nativescript runtime package dependency: nativescript-regular'
     ]
     test_result = Wait.until(lambda: all(string in log.output
                                          for string in strings),
                              timeout=240,
                              period=5)
     assert test_result, "Missing nativescript runtime package dependency! Logs: " + log.output
     # check app is working
     Tns.run_android(APP_NAME,
                     device=self.emulator.id,
                     wait=False,
                     verify=False)
     test_result = Wait.until(
         lambda: Device.is_text_visible(self.emulator, "TAP", True),
         timeout=50,
         period=5)
     assert test_result, "TAP Button is missing on the device! V8 with debug symbols is making the app crash!"
コード例 #4
0
    def test_440_tns_run_android_new_date_work_as_expected_when_changing_timezone(
            self):
        """
         Test new date is working as expected. Test in different timezones
        """
        output = Adb.run_adb_command(
            "shell settings put global auto_time_zone 0",
            self.emulator.id,
            wait=True)
        assert output.output == '', "Failed to change auto timezone!"

        output = Adb.run_adb_command("shell settings put system time_12_24 24",
                                     self.emulator.id,
                                     wait=True)
        assert output.output == '', "Failed to change system format to 24!"

        output = Adb.run_adb_command("shell settings put global time_zone UTC",
                                     self.emulator.id,
                                     wait=True)
        assert output.output == '', "Failed to change timezone!"
        if self.emulator.version < 10.0:
            output = Adb.run_adb_command(
                "shell setprop persist.sys.timezone Atlantic/Reykjavik",
                self.emulator.id,
                wait=True)
            assert output.output == '', "Failed to change timezone!"
        else:
            # Open Date and time settings to change the timezone
            output = Adb.run_adb_command(
                "shell am start -a android.settings.DATE_SETTINGS",
                self.emulator.id,
                wait=True)
            assert_text = 'Starting: Intent { act=android.settings.DATE_SETTINGS }'
            assert assert_text in output.output, "Failed to start Date and Time settings activity!"
            Device.click(self.emulator, text="Time zone", case_sensitive=True)
            Device.click(self.emulator, text="Region")
            Adb.run_adb_command("shell input keyevent \"KEYCODE_I\"",
                                self.emulator.id,
                                wait=True)
            Adb.run_adb_command("shell input keyevent \"KEYCODE_C\"",
                                self.emulator.id,
                                wait=True)
            Device.click(self.emulator, text="Iceland")
        # Change main-page.js so it contains only logging information
        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                                 'files', 'android-runtime-961',
                                 'main-page.js')
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app',
                                 'main-page.js')
        File.copy(source=source_js, target=target_js, backup_files=True)
        # Change main-view-model.js so it contains the new date logging functionality
        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                                 'files', 'android-runtime-961',
                                 'main-view-model.js')
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app',
                                 'main-view-model.js')
        File.copy(source=source_js, target=target_js, backup_files=True)
        # Change app package.json so it contains the options for remove V8 date cache
        source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android',
                                 'files', 'android-runtime-961',
                                 'package.json')
        target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app',
                                 'package.json')

        File.copy(source=source_js, target=target_js, backup_files=True)

        log = Tns.run_android(APP_NAME,
                              device=self.emulator.id,
                              wait=False,
                              verify=False)

        strings = ['Successfully synced application', '### TEST END ###']
        assert_result = Wait.until(
            lambda: all(string in File.read(log.log_file)
                        for string in strings),
            timeout=240,
            period=5)
        assert assert_result, "Application not build correct! Logs: " + File.read(
            log.log_file)
        # Get UTC date and time
        time_utc = datetime.datetime.utcnow()

        # Generate regex for asserting date and time
        date_to_find_gmt = time_utc.strftime(
            r'%a %b %d %Y %H:.{2}:.{2}') + r" GMT\+0000 \(GMT\)"
        test_result = Wait.until(
            lambda: Device.is_text_visible(self.emulator, "TAP", True),
            timeout=200,
            period=5)
        assert test_result, "TAP Button is missing on the device"
        Device.click(self.emulator, text="TAP", case_sensitive=True)
        assert_result = Wait.until(
            lambda: "GMT+0000 (GMT)" in File.read(log.log_file),
            timeout=30,
            period=5)
        assert assert_result, "Missing log for time! Logs: " + File.read(
            log.log_file)
        # Assert date time is correct
        assert_result = Wait.until(
            lambda: re.search(date_to_find_gmt, File.read(log.log_file)),
            timeout=20,
            period=5)
        assert assert_result, 'Date {0} was not found! \n Log: \n {1}'.format(
            date_to_find_gmt, File.read(log.log_file))
        # Get Los Angeles date and time
        los_angeles_time = time_utc.replace(tzinfo=pytz.utc).astimezone(
            pytz.timezone("America/Los_Angeles"))

        # Open Date and time settings to change the timezone
        output = Adb.run_adb_command(
            "shell am start -a android.settings.DATE_SETTINGS",
            self.emulator.id,
            wait=True)
        assert_text = 'Starting: Intent { act=android.settings.DATE_SETTINGS }'
        assert assert_text in output.output, "Failed to start Date and Time settings activity!"
        # Change TimeZone
        if self.emulator.version < 10.0:
            test_result = Wait.until(lambda: Device.is_text_visible(
                self.emulator, "Select time zone", True),
                                     timeout=30,
                                     period=5)
            assert test_result, "Select time zone Button is missing on the device"
            Device.click(self.emulator, text="Select time zone")
            test_result = Wait.until(lambda: Device.is_text_visible(
                self.emulator, "Pacific Daylight Time", True),
                                     timeout=30,
                                     period=5)
            assert test_result, "Pacific Daylight Time Button is missing on the device"
            Device.click(self.emulator, text="Pacific Daylight Time")

        else:
            output = Adb.run_adb_command(
                "shell am start -a android.settings.DATE_SETTINGS",
                self.emulator.id,
                wait=True)
            assert_text = 'Starting: Intent { act=android.settings.DATE_SETTINGS }'
            assert assert_text in output.output, "Failed to start Date and Time settings activity!"
            Device.click(self.emulator, text="Region")
            Adb.run_adb_command("shell input keyevent \"KEYCODE_U\"",
                                self.emulator.id,
                                wait=True)
            Adb.run_adb_command("shell input keyevent \"KEYCODE_S\"",
                                self.emulator.id,
                                wait=True)
            Device.click(self.emulator, text="United States")
            Device.click(self.emulator, text="Los Angeles")

        # Open the test app again
        output = Adb.run_adb_command(
            "shell am start -n org.nativescript.TestApp/com.tns.NativeScriptActivity",
            self.emulator.id,
            wait=True)
        assert_text = 'Starting: Intent { cmp=org.nativescript.TestApp/com.tns.NativeScriptActivity }'
        assert assert_text in output.output, "Failed to start Nativescript test app activity!"
        test_result = Wait.until(
            lambda: Device.is_text_visible(self.emulator, "TAP", True),
            timeout=30,
            period=5)
        assert test_result, "TAP Button is missing on the device"
        Device.click(self.emulator, text="TAP", case_sensitive=True)
        assert_result = Wait.until(
            lambda: "GMT-0700 (PDT)" in File.read(log.log_file),
            timeout=240,
            period=5)
        assert assert_result, "Missing log for time! Logs: " + File.read(
            log.log_file)
        # Generate regex for asserting date and time
        date_to_find_los_angeles = los_angeles_time.strftime(
            r'%a %b %d %Y %H:.{2}:.{2}') + r" GMT\-0700 \(PDT\)"
        # Assert date time is correct
        assert_result = Wait.until(lambda: re.search(date_to_find_los_angeles,
                                                     File.read(log.log_file)),
                                   timeout=20,
                                   period=5)
        assert assert_result, 'Date {0} was not found! \n Log: \n {1}'.format(
            date_to_find_los_angeles, File.read(log.log_file))