def run_url(url, device):
        """
        Runs project in the Preview App.
        :param url: Playground url.
        :param device: DeviceInfo object.
        """
        # Url needs to be escaped before open with adb or simctl
        url = url.replace(r'?', r'\?')
        url = url.replace(r'&', r'\&')

        # Run url
        Log.info('Open "{0}" on {1}.'.format(url, device.name))
        if device.type == DeviceType.EMU or device.type == DeviceType.ANDROID:
            cmd = 'shell am start -a android.intent.action.VIEW -d "{0}" org.nativescript.preview'.format(
                url)
            output = Adb.run_adb_command(command=cmd,
                                         device_id=device.id).output
            assert 'error' not in output, 'Failed to open URL!' + os.linesep + 'Error:' + os.linesep + output
        elif device.type == DeviceType.SIM:
            output = Simctl.run_simctl_command(
                command='openurl {0} {1}.'.format(device.id, url)).output
            assert 'error' not in output, 'Failed to open URL!' + os.linesep + 'Error:' + os.linesep + output
        else:
            raise NotImplementedError(
                'Open url not implemented for real iOS devices.')
Ejemplo n.º 2
0
 def archive_apps():
     if TestContext.TEST_APP_NAME is not None:
         app_path = os.path.join(Settings.TEST_RUN_HOME, TestContext.TEST_APP_NAME)
         if Folder.exists(app_path):
             archive_path = os.path.join(Settings.TEST_OUT_HOME, TestContext.CLASS_NAME, TestContext.TEST_NAME,
                                         TestContext.TEST_APP_NAME)
             Log.info('Archive app under test at: {0}'.format(archive_path))
Ejemplo n.º 3
0
    def test_190_build_ios_distribution_provisions(self):
        Tns.platform_remove(self.app_name, platform=Platform.ANDROID)
        result = Tns.exec_command(command='build ios --provision',
                                  path=self.app_name)
        assert "Provision Name" in result.output
        assert "Provision UUID" in result.output
        assert "App Id" in result.output
        assert "Team" in result.output
        assert "Type" in result.output
        assert "Due" in result.output
        assert "Devices" in result.output
        assert Settings.IOS.PROVISIONING in result.output
        assert Settings.IOS.DISTRIBUTION_PROVISIONING in result.output
        assert Settings.IOS.DEVELOPMENT_TEAM in result.output

        # Build with correct distribution provision
        if Xcode.get_version() < 11:
            Log.info(
                "Skip this check because we use new type of certificated that require Xcode 11."
            )
        else:
            Tns.build_ios(self.app_name,
                          provision=Settings.IOS.DISTRIBUTION_PROVISIONING,
                          for_device=True,
                          release=True)

        # Verify that passing wrong provision shows user friendly error
        result = Tns.build_ios(self.app_name, provision="fake", verify=False)
        assert "Failed to find mobile provision with UUID or Name: fake" in result.output
 def ng_serve(self, prod=False):
     NG.serve(project=self.app_name, prod=prod)
     self.chrome.open(DEFAULT_WEB_URL)
     welcome_element = self.chrome.driver.find_element_by_xpath('//h1')
     assert 'Welcome to' in welcome_element.text, 'Failed to find welcome message.'
     Log.info('Welcome page served successfully.')
     NG.kill()
Ejemplo n.º 5
0
 def clear_logcat(device_id):
     """
     Clear (flush) the entire log.
     :param device_id: Device id.
     """
     Adb.run_adb_command(command='logcat -c', device_id=device_id, wait=True)
     Log.info("The logcat on {0} is cleared.".format(device_id))
 def wait_for_main_color(self, color, timeout=60):
     result = Wait.until(lambda: (self.get_main_color() == color).all(),
                         timeout=timeout)
     if result:
         Log.info('Main color is: ' + str(color))
     assert result, "Expected main color: " + str(color) + os.linesep + \
                    "Actual main color: " + str(self.get_main_color())
 def test_102_run_android_typescript_platform_spec(self, test_id, app_type, hmr):
     Log.info(test_id)
     result = run_demo_app(app_name=self.app_name, app_type=app_type, plugin_name=self.plugin_name,
                           platform=Platform.ANDROID, hmr=hmr)
     verify_demo_initial_state(self.emu)
     sync_plugin_platform_spec(app_name=self.app_name, app_type=app_type,
                               platform=Platform.ANDROID, device=self.emu, log_result=result, hmr=hmr)
Ejemplo n.º 8
0
 def kill():
     Log.info("Kill gradle processes.")
     if Settings.HOST_OS is OSType.WINDOWS:
         Process.kill(proc_name='java.exe', proc_cmdline='gradle')
     else:
         command = "ps -ef  | grep '.gradle/wrapper' | grep -v grep | awk '{ print $2 }' | xargs kill -9"
         run(cmd=command)
    def copy(source, target, clean_target=True, only_files=False):
        """
        Copy folders.
        :param source: Source folder.
        :param target: Target folder.
        :param clean_target: If True clean target folder before copy.
        :param only_files: If True only the files from source folder are copied to target folder.
        """
        if clean_target:
            Folder.clean(folder=target)
        Log.info('Copy {0} to {1}'.format(source, target))
        if only_files is True:
            files = os.listdir(source)

            for f in files:
                f_path = os.path.join(source, f)
                File.copy(f_path, target)
        else:
            try:
                shutil.copytree(source, target)
            except OSError as exc:
                if exc.errno == errno.ENOTDIR:
                    shutil.copy(source, target)
                else:
                    raise
Ejemplo n.º 10
0
 def get_active_services(device_id, service_name=""):
     """
     Get actice services
     :param device_id: Device identifier as float.
     :param service_name: Service name you want to find as string.
     """
     try:
         result = Adb.run_adb_command(
             command='shell dumpsys activity services {0}'.format(
                 service_name),
             wait=True,
             device_id=device_id).output
     except TimeoutExpired:
         Log.info('get_logcat timeout! Retrying...')
         command_result = Adb.run_adb_command(
             command='shell dumpsys activity services {0}'.format(
                 service_name),
             wait=False,
             device_id=device_id)
         time.sleep(15)
         result = File.read(command_result.log_file)
         try:
             os.kill(command_result.pid, 0)
         except OSError:
             Log.info('Process already killed...')
     return result
 def test_104_run_ios_typescript_platform_spec(self, test_id, app_type, hmr):
     Log.info(test_id)
     result = run_demo_app(app_name=self.app_name, app_type=app_type, plugin_name=self.plugin_name,
                           platform=Platform.IOS, hmr=hmr)
     verify_demo_initial_state(self.sim)
     sync_plugin_platform_spec(app_name=self.app_name, app_type=app_type, platform=Platform.IOS,
                               device=self.sim, log_result=result, hmr=hmr)
Ejemplo n.º 12
0
 def run_npm_command(cmd, folder=Settings.TEST_RUN_HOME, verify=True):
     command = 'npm {0}'.format(cmd).strip()
     Log.info(command + " (at " + str(folder) + ").")
     result = run(cmd=command, cwd=folder, wait=True, timeout=300)
     if verify:
         assert result.exit_code == 0, '" + command + " exited with non zero exit code!: \n' + result.output
     return result.output.strip()
Ejemplo n.º 13
0
 def clean_repo_changes(local_folder):
     """
     :param local_folder: the folder of the git project in which clean and reset commands will be called
     """
     commands = ['git clean -fdx', 'git reset', 'git checkout .']
     Log.info(commands)
     for command in commands:
         run(cmd=command, cwd=local_folder)
 def is_process_running(simulator_info, app_id):
     result = Simctl.run_simctl_command(
         'spawn {0} launchctl list | grep \'{1}\''.format(
             simulator_info.id, app_id))
     is_running = result.exit_code == 0
     if not is_running:
         Log.info('Process {0} is not running !'.format(app_id))
     return is_running
 def click(self, text, case_sensitive=False):
     self.wait_for_text(text=text, case_sensitive=case_sensitive)
     if self.type is DeviceType.EMU or self.type is DeviceType.ANDROID:
         Adb.click_element_by_text(self.id, text, case_sensitive)
     elif self.type is DeviceType.SIM:
         SimAuto.click(self, text=text)
     else:
         raise NotImplementedError('Click not implemented for iOS devices.')
     Log.info('Click on "{0}" text.'.format(text))
 def uninstall(simulator_info, app_id):
     result = Simctl.run_simctl_command('uninstall {0} {1}'.format(
         simulator_info.id, app_id))
     assert result.exit_code == 0, 'Failed to uninstall {0} on {1}'.format(
         app_id, simulator_info.name)
     assert 'Failed to uninstall the requested application' not in result.output, \
         'Failed to uninstall {0} on {1}'.format(app_id, simulator_info.name)
     Log.info('Successfully uninstalled {0} from {1}'.format(
         app_id, simulator_info.id))
Ejemplo n.º 17
0
 def install(simulator_info, path):
     result = Simctl.run_simctl_command('install {0} {1}'.format(simulator_info.id, path))
     if result.exit_code != 0:
         # Since Xcode 10 sometimes xcrun simctl install fails first time (usually with iPhone X* devices).
         Log.info('Failed to install {0} on {1}.'.format(path, simulator_info.name))
         Log.info('Retry...')
         result = Simctl.run_simctl_command('install {0} {1}'.format(simulator_info.id, path))
         assert result.exit_code == 0, 'Failed to install {0} on {1}'.format(path, simulator_info.name)
         assert 'Failed to install the requested application' not in result.output, \
             'Failed to install {0} on {1}'.format(path, simulator_info.name)
Ejemplo n.º 18
0
    def test_05_get_text_unicode(self):
        text = ImageUtils.get_text(self.unicode_image)
        Log.info(text)
        assert 'Ter Stegen' in text
        assert 'Neymar' in text

        text = ImageUtils.get_text(self.app_image_ng)
        Log.info(text)
        assert 'Ter Stegen' in text
        assert 'Piqué' in text
Ejemplo n.º 19
0
 def start_application(device_id, app_id):
     """
     Start application.
     :param device_id: Device id.
     :param app_id: App id.
     """
     command = 'shell monkey -p ' + app_id + ' -c android.intent.category.LAUNCHER 1'
     output = Adb.run_adb_command(command=command, device_id=device_id, wait=True).output
     assert 'Events injected: 1' in output, 'Failed to start {0}.'.format(app_id)
     Log.info('{0} started successfully.'.format(app_id))
    def get_preserved_data():
        file_path = os.path.join(Settings.TEST_RUN_HOME, 'results.json')
        data = None
        if os.path.isfile(file_path):
            with open(file_path, "r") as json_file:
                data = json.load(json_file)
        else:
            with open(file_path, "w") as new_file:
                Log.info("Results.json file created " + new_file.name)

        return data
Ejemplo n.º 21
0
 def is_value_in_range(actual, expected, tolerance=0.25):
     """
     Check if value is in range
     :param actual: Number value.
     :param expected: Number value.
     :param tolerance: Tolerance as percent.
     """
     Log.info("Actual value: " + str(actual))
     Log.info("Expected value: " + str(expected))
     return expected - (expected * tolerance) <= actual <= expected + (
         expected * tolerance)
Ejemplo n.º 22
0
 def download(file_name, url, destination_dir=Settings.TEST_RUN_HOME):
     file_path = os.path.join(destination_dir, file_name)
     if Settings.PYTHON_VERSION < 3:
         import urllib
         urllib.urlretrieve(url, file_path)
     else:
         import urllib.request
         urllib.request.urlretrieve(url, file_path)
     file_path = os.path.join(destination_dir, file_name)
     assert File.exists(file_path), 'Failed to download {0} at {1}.'.format(url, file_path)
     Log.info('Downloaded {0} at {1}'.format(url, file_path))
Ejemplo n.º 23
0
 def doubleclick_line(self, text):
     """
     Doubleclick on line text on element tab.
     :param text: text.
     """
     line = self.__find_line_by_text(text=text)
     assert line is not None, "Failed to find line with text " + text
     x, y = self.chrome.get_absolute_center(line)
     pyautogui.doubleClick(x, y)
     sleep(2)
     Log.info('Double click line with text "{0}".'.format(text))
Ejemplo n.º 24
0
 def kill():
     """
     Kill all tns related processes.
     """
     Log.info("Kill tns processes.")
     if Settings.HOST_OS == OSType.WINDOWS:
         Process.kill(proc_name='node')
     else:
         Process.kill(proc_name='node',
                      proc_cmdline=Settings.Executables.TNS)
         Process.kill_by_commandline(cmdline='webpack.js')
Ejemplo n.º 25
0
 def __expand_main_panel(self):
     button_container = self.main_panel.find_element(
         By.CSS_SELECTOR, 'div.tabbed-pane-left-toolbar.toolbar')
     button_root = self.__expand_shadow_element(button_container)
     button = button_root.find_element(
         By.CSS_SELECTOR, "button[aria-label='Toggle screencast']")
     if 'toolbar-state-on' in button.get_attribute("class"):
         Log.info('Expand dev tools main pannel.')
         button.click()
         sleep(1)
     else:
         Log.info('Dev tools main panel already expanded.')
Ejemplo n.º 26
0
 def uninstall(app_id, device_id, assert_success=True):
     """
     Uninstall application.
     :param app_id: Package identifier - org.nativescript.testapp.
     :param device_id: Device id.
     :param assert_success: Assert if uninstall is successful.
     """
     command = 'uninstall ' + app_id
     output = Adb.run_adb_command(command=command, device_id=device_id, wait=True).output
     if assert_success:
         assert 'Success' in output, 'Failed to uninstall {0}. Output: {1}'.format(app_id, output)
         Log.info('{0} uninstalled successfully from {1}.'.format(app_id, device_id))
Ejemplo n.º 27
0
 def wait_element_by_text(self, text, timeout=30):
     self.chrome.driver.implicitly_wait(1)
     result = Wait.until(
         lambda: self.find_element_by_text(text) is not None,
         timeout=timeout,
         period=1)
     self.chrome.driver.implicitly_wait(self.chrome.implicitly_wait)
     assert result, 'Failed to find element by "{0}" text.'.format(
         text.encode('utf-8'))
     Log.info('Element with text "{0}" found in CDT.'.format(
         text.encode('utf-8')))
     return self.find_element_by_text(text)
Ejemplo n.º 28
0
 def ng_serve(self, prod=False):
     NG.serve(project=self.app_name, prod=prod)
     self.chrome.open(DEFAULT_WEB_URL)
     if "Angular CLI: 8.3" in NG.exec_command(command="version").output:
         element = self.chrome.driver.find_element(
             By.XPATH, '//*[contains(text(), "TestApp app is running!")]')
     else:
         element = self.chrome.driver.find_element(
             By.XPATH, '//*[contains(text(), "Welcome")]')
     assert element.is_displayed(), 'Failed to serve default NG project.'
     Log.info('Default NG web project loaded!')
     NG.kill()
Ejemplo n.º 29
0
 def is_running(simulator_info):
     for sim in Simctl.__get_devices_by_version(simulator_info.sdk):
         if sim['name'] == simulator_info.name and sim['state'] == 'Booted':
             # simctl returns Booted too early, so we will wait some untill service is started
             simulator_info.id = str(sim['udid'])
             command = 'spawn {0} launchctl print system | grep com.apple.springboard.services'.format(
                 simulator_info.id)
             service_state = Simctl.run_simctl_command(command=command)
             if "M   A   com.apple.springboard.services" in service_state.output:
                 Log.info('Simulator "{0}" booted.'.format(
                     simulator_info.name))
                 return simulator_info
     return False
Ejemplo n.º 30
0
 def clean_network_tab(self):
     """
     Click clean button on network tab.
     """
     network = self.chrome.driver.find_element(By.CSS_SELECTOR,
                                               "div[aria-label='network']")
     toolbar = network.find_element(By.CSS_SELECTOR, "div[class='toolbar']")
     root = self.__expand_shadow_element(toolbar)
     button = root.find_element(By.CSS_SELECTOR,
                                "button[aria-label='Clear']")
     button.click()
     sleep(1)
     Log.info("Clear Network tab.")