def setUpClass(cls): BaseClass.setUpClass(cls.__name__) Process.kill('Safari') Process.kill('NativeScript Inspector') Emulator.stop() Simulator.stop() cls.SIMULATOR_ID = Simulator.ensure_available( simulator_name=SIMULATOR_NAME) Folder.cleanup(cls.INSPECTOR_GLOBAL_PATH) Tns.create_app(cls.app_name, attributes={ '--template': os.path.join('data', 'apps', 'livesync-hello-world.tgz') }, update_modules=True) Tns.platform_add_ios(attributes={ '--path': cls.app_name, '--frameworkPath': IOS_PACKAGE }) if USE_YARN == "True": Npm.install(package=IOS_INSPECTOR_PACKAGE, option='--dev', folder=cls.app_name) else: Npm.install(package=IOS_INSPECTOR_PACKAGE, option='--save-dev', folder=cls.app_name) Tns.build_ios(attributes={"--path": cls.app_name})
def kill(): print "Kill gradle processes." if CURRENT_OS != OSType.WINDOWS: command = "ps -ef | grep '.gradle/wrapper' | grep -v grep | awk '{ print $2 }' | xargs kill -9" run(command=command, log_level=CommandLogLevel.SILENT) else: print Process.kill(proc_name='java.exe', proc_cmdline='gradle')
def setUpClass(cls, class_name): print "" print "_________________________________CLASS START_______________________________________" print "Class Name: {0}".format(class_name) print "Start Time: {0}".format(time.strftime("%X")) print "" Tns.kill() Gradle.kill() Process.kill('node') Process.kill('adb') if CURRENT_OS == OSType.OSX: Process.kill('NativeScript Inspector') Process.kill('Safari') Process.kill('Xcode') if class_name is not None: logfile = os.path.join('out', class_name + '.txt') else: logfile = os.path.join(OUTPUT_FOLDER, cls.__name__ + ".txt") File.remove(logfile) sys.stdout = sys.stderr = Logger.Logger(logfile) Folder.cleanup(cls.app_name)
def tearDownClass(cls): Tns.kill() Emulator.stop() Gradle.kill() if CURRENT_OS == OSType.OSX: Process.kill('NativeScript Inspector') Process.kill('Safari') Simulator.stop()
def start(url=""): if CURRENT_OS is OSType.OSX: chrome_path = os.path.join(TEST_RUN_HOME, 'core', 'chrome', 'start_chrome') command = "osascript " + chrome_path + " " + url.replace("&", "\&") run(command=command, log_level=CommandLogLevel.SILENT) print "Open Google Chrome at {0}".format(url) Process.wait_until_running(proc_name="Google Chrome", timeout=30) elif CURRENT_OS is OSType.LINUX: run(command="google-chrome", log_level=CommandLogLevel.SILENT, wait=False) Process.wait_until_running(proc_name="chrome", timeout=30)
def test_100_debug_ios_simulator_with_livesync(self): """ `tns debug ios` should be able to run with livesync """ log = Tns.debug_ios(attributes={'--path': self.app_name, '--emulator': '', '--inspector': ''}) DebugiOSInspectorSimulatorTests.__verify_debugger_attach(log) # Verify app starts and do not stop on first line of code Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID, expected_image='livesync-hello-world_home') # Change JS and wait until app is synced ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS, sleep=10) strings = ['Successfully transferred', 'main-view-model.js', 'CONSOLE LOG', 'Backend socket closed', 'Frontend socket closed', 'Frontend client connected', 'Backend socket created', 'NativeScript debugger attached'] Tns.wait_for_log(log_file=log, string_list=strings) # Change XML and wait until app is synced. App doesn't restart from 5.1.0 version ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_XML, sleep=3) strings = ['Successfully transferred', 'main-page.xml', 'CONSOLE LOG'] Tns.wait_for_log(log_file=log, string_list=strings) # Change CSS and wait until app is synced. App doesn't restart from 5.1.0 version ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_CSS, sleep=3) strings = ['Successfully transferred', 'app.css', 'CONSOLE LOG'] Tns.wait_for_log(log_file=log, string_list=strings) # Verify application looks correct Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID, expected_image='livesync-hello-world_js_css_xml', tolerance=0.26) assert Process.is_running('NativeScript Inspector')
def start(name, timeout=180): """ Start iOS Simulator :param name: Simulator name. :param timeout: Timeout in seconds. :return: Identifier of booted iOS Simulator. """ # Find simulator GUID sim_id = Simulator.__get_id(name) if sim_id is None: raise AssertionError("Unable to find device with name " + name) # Start simulator via commandline run(command="xcrun simctl boot " + sim_id, log_level=CommandLogLevel.SILENT) # Start GUI if Process.is_running('Simulator.app'): print "Simulator GUI is already running." else: print "Start simulator GUI." run(command="open -a Simulator", log_level=CommandLogLevel.SILENT) # Wait until simulator boot found, simulator_id = Simulator.wait_for_simulator(simulator_name=name, timeout=timeout) if found: print 'Simulator {0} with id {1} is up and running!'.format(name, simulator_id) return simulator_id else: raise NameError('Failed to boot {0}!'.format(name))
def start(name, timeout=180): """ Start iOS Simulator :param name: Simulator name. :param timeout: Timeout in seconds. :return: Identifier of booted iOS Simulator. """ # Find simulator GUID sim_id = Simulator.__get_id(name) if sim_id is None: raise AssertionError("Unable to find device with name " + name) # Start simulator via commandline run(command="xcrun simctl boot " + sim_id, log_level=CommandLogLevel.SILENT) # Start GUI if Process.is_running('Simulator.app'): print "Simulator GUI is already running." else: print "Start simulator GUI." run(command="open -a Simulator", log_level=CommandLogLevel.SILENT) # Wait until simulator boot found, simulator_id = Simulator.wait_for_simulator(simulator_name=name, timeout=timeout) if found: print 'Simulator {0} with id {1} is up and running!'.format( name, simulator_id) return simulator_id else: raise NameError('Failed to boot {0}!'.format(name))
def cleanup(folder, force=True): if os.path.exists(folder): try: shutil.rmtree(folder, False) except: if os.path.exists(folder): if 'Windows' in platform.platform(): # File is locked by some process print "Failed to delete {0}.".format(folder) if force: print "Kill processes associated with this folder." Process.kill_by_handle(folder) run('rm -rf ' + folder) if Folder.exists(folder): shutil.rmtree(folder) else: run('rm -rf ' + folder)
def setUpClass(cls): BaseClass.setUpClass(cls.__name__) Process.kill('Safari') Process.kill('NativeScript Inspector') Emulator.stop() Simulator.stop() cls.SIMULATOR_ID = Simulator.ensure_available(simulator_name=SIMULATOR_NAME) Folder.cleanup(cls.INSPECTOR_GLOBAL_PATH) Tns.create_app(cls.app_name, attributes={'--template': os.path.join('data', 'apps', 'livesync-hello-world.tgz')}, update_modules=True) Tns.platform_add_ios(attributes={'--path': cls.app_name, '--frameworkPath': IOS_PACKAGE}) if USE_YARN == "True": Npm.install(package=IOS_INSPECTOR_PACKAGE, option='--dev', folder=cls.app_name) else: Npm.install(package=IOS_INSPECTOR_PACKAGE, option='--save-dev', folder=cls.app_name) Tns.build_ios(attributes={"--path": cls.app_name})
def kill(): """ Kill all running `tns` processes """ print "Kill all tns processes." Process.kill(proc_name='node', proc_cmdline=os.sep + 'tns') time.sleep(1) Process.kill(proc_name='node', proc_cmdline=TEST_RUN_HOME.split(os.sep)[-1]) time.sleep(1) Process.kill_by_commandline('webpack.js') time.sleep(1) Process.kill_by_commandline('tsc')
def __verify_debugger_attach(log, app_started=True): strings = ["Frontend client connected", "Backend socket created", "NativeScript debugger attached"] Tns.wait_for_log(log_file=log, string_list=strings, timeout=90, check_interval=10, clean_log=False) time.sleep(10) output = File.read(log) assert "Frontend socket closed" not in output assert "Backend socket closed" not in output assert "NativeScript debugger detached" not in output assert Process.is_running('NativeScript Inspector') if app_started: assert "Page loaded 1 time" in output, "Page not reloaded, this is bug!" else: assert "Page loaded 1 time" not in output, "Page reloaded, this is bug!"
def test_100_debug_ios_simulator_with_livesync(self): """ `tns debug ios` should be able to run with livesync """ log = Tns.debug_ios(attributes={ '--path': self.app_name, '--emulator': '', '--inspector': '' }) DebugiOSInspectorSimulatorTests.__verify_debugger_attach(log) # Verify app starts and do not stop on first line of code Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID, expected_image='livesync-hello-world_home') # Change JS and wait until app is synced ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS, sleep=10) strings = [ 'Successfully transferred', 'main-view-model.js', 'CONSOLE LOG', 'Backend socket closed', 'Frontend socket closed', 'Frontend client connected', 'Backend socket created', 'NativeScript debugger attached' ] Tns.wait_for_log(log_file=log, string_list=strings) # Change XML and wait until app is synced. App doesn't restart from 5.1.0 version ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_XML, sleep=3) strings = ['Successfully transferred', 'main-page.xml', 'CONSOLE LOG'] Tns.wait_for_log(log_file=log, string_list=strings) # Change CSS and wait until app is synced. App doesn't restart from 5.1.0 version ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_CSS, sleep=3) strings = ['Successfully transferred', 'app.css', 'CONSOLE LOG'] Tns.wait_for_log(log_file=log, string_list=strings) # Verify application looks correct Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID, expected_image='livesync-hello-world_js_css_xml', tolerance=0.26) assert Process.is_running('NativeScript Inspector')
def remove(file_path, force=True): if os.path.exists(file_path): try: os.remove(file_path) except: # File is locked by some process print "Failed to delete {0}.".format(file_path) if force: print "Kill processes associated with this file." Process.kill_by_handle(file_path) if CURRENT_OS == OSType.WINDOWS: Process.kill('node') Process.kill('adb') os.remove(file_path)
def __verify_debugger_attach(log, app_started=True): strings = [ "Frontend client connected", "Backend socket created", "NativeScript debugger attached" ] Tns.wait_for_log(log_file=log, string_list=strings, timeout=90, check_interval=10, clean_log=False) time.sleep(10) output = File.read(log) assert "Frontend socket closed" not in output assert "Backend socket closed" not in output assert "NativeScript debugger detached" not in output assert Process.is_running('NativeScript Inspector') if app_started: assert "Page loaded 1 time" in output, "Page not reloaded, this is bug!" else: assert "Page loaded 1 time" not in output, "Page reloaded, this is bug!"
def stop(device_id='booted'): """ Stop running simulators (by default stop all simulators) :param device_id: Device identifier (Simulator GUID) """ if device_id == 'booted': print 'Stop all running simulators.' Process.kill('Simulator') Process.kill('tail') Process.kill('launchd_sim') command = "ps -ef | grep 'CoreSimulator' | grep -v grep | awk '{ print $2 }' | xargs kill -9" run(command=command, log_level=CommandLogLevel.SILENT) time.sleep(1) else: print 'Stop simulator with id ' + device_id run(command='xcrun simctl shutdown {0}'.format(device_id), timeout=60, log_level=CommandLogLevel.SILENT) time.sleep(1)
def run(command, timeout=COMMAND_TIMEOUT, output=True, wait=True, log_level=CommandLogLevel.FULL): """ Execute command in shell. :param command: Command to be executed. :param timeout: Timeout for command execution. :param output: :param wait: Specify if method should wait until command execution complete. :param log_level: CommandLogLevel value (SILENT, COMMAND_ONLY, FULL). :return: If wait=True return output of the command, else return path to file where command writes log. """ def fork_it(): """ This function will be emulate in a parallel thread. You can redirect the output to one place and the errors to another: # dir file.xxx > output.msg 2> output.err You can print the errors and standard output to a single file by using the "&1" command to redirect the output for STDERR to STDOUT and then sending the output from STDOUT to a file: # dir file.xxx 1> output.msg 2>&1 """ # execute command # print "Thread started" if output: os.system(command + ' 1> ' + out_file + ' 2>&1') else: os.system(command) # If wait=False log should be writen out_file = OUTPUT_FILE if not wait: time_string = "_" + datetime.now().strftime('%Y_%m_%d_%H_%M_%S') out_file = OUTPUT_FILE_ASYNC.replace('.', time_string + '.') if CURRENT_OS is OSType.WINDOWS: command = command + " 1> " + out_file + " 2>&1" elif CURRENT_OS is OSType.LINUX: command = command + " 1> " + out_file + " 2>&1 &" else: command = command + " &> " + out_file + " 2>&1 &" # remove output.txt try: File.remove(out_file) except OSError: print "Failed to delete " + out_file time.sleep(1) File.remove(out_file) # log command that is executed (and append to TEST_LOG file) if log_level is not CommandLogLevel.SILENT: File.append(TEST_LOG, command) print "##### {0} Executing command : {1}\n".format( time.strftime("%X"), command) # Hack for async commands on Windows if CURRENT_OS is OSType.WINDOWS: if not wait: timeout = 10 # prepare command line thread = threading.Thread(target=fork_it) thread.start() # wait for thread to finish or timeout thread.join(timeout) # kill thread if it exceed the timeout if thread.is_alive(): if wait: Process.kill_by_commandline( command.partition(' ')[0].rpartition(os.sep)[-1]) thread.join() raise NameError('Process has timed out at ' + time.strftime("%X")) # get whenever exist in the pipe ? pipe_output = 'NOT_COLLECTED' if output: pipe_output = File.read(out_file) if (log_level is CommandLogLevel.FULL) and wait: print "##### OUTPUT BEGIN #####\n" print pipe_output print "##### OUTPUT END #####\n" if wait: return pipe_output.strip('\r\n') else: return out_file
def stop(): print "Stop Google Chrome." if CURRENT_OS is OSType.OSX: Process.kill("Google Chrome") elif CURRENT_OS is OSType.LINUX: Process.kill("chrome")
def stop(): """ Stop all running emulators. """ print 'Stop all running emulators.' Process.kill_by_commandline('qemu') Process.kill_by_commandline('emulator64') Process.kill('emulator64-arm') Process.kill('emulator64-x86') Process.kill('emulator-arm') Process.kill('emulator-x86') Process.kill('qemu-system-arm') Process.kill('qemu-system-i386') Process.kill('qemu-system-i38') assert not Emulator.is_running(device_id=EMULATOR_ID), 'Emulator is still running!'
def __kill_uiautomator(): Process.kill(proc_name="adb", proc_cmdline="uiautomator")
def run(command, timeout=COMMAND_TIMEOUT, output=True, wait=True, log_level=CommandLogLevel.FULL): """ Execute command in shell. :param command: Command to be executed. :param timeout: Timeout for command execution. :param output: :param wait: Specify if method should wait until command execution complete. :param log_level: CommandLogLevel value (SILENT, COMMAND_ONLY, FULL). :return: If wait=True return output of the command, else return path to file where command writes log. """ def fork_it(): """ This function will be emulate in a parallel thread. You can redirect the output to one place and the errors to another: # dir file.xxx > output.msg 2> output.err You can print the errors and standard output to a single file by using the "&1" command to redirect the output for STDERR to STDOUT and then sending the output from STDOUT to a file: # dir file.xxx 1> output.msg 2>&1 """ # execute command # print "Thread started" if output: os.system(command + ' 1> ' + out_file + ' 2>&1') else: os.system(command) # If wait=False log should be writen out_file = OUTPUT_FILE if not wait: time_string = "_" + datetime.now().strftime('%Y_%m_%d_%H_%M_%S') out_file = OUTPUT_FILE_ASYNC.replace('.', time_string + '.') if CURRENT_OS is OSType.WINDOWS: command = command + " 1> " + out_file + " 2>&1" elif CURRENT_OS is OSType.LINUX: command = command + " 1> " + out_file + " 2>&1 &" else: command = command + " &> " + out_file + " 2>&1 &" # remove output.txt try: File.remove(out_file) except OSError: print "Failed to delete " + out_file time.sleep(1) File.remove(out_file) # log command that is executed (and append to TEST_LOG file) if log_level is not CommandLogLevel.SILENT: File.append(TEST_LOG, command) print "##### {0} Executing command : {1}\n".format(time.strftime("%X"), command) # Hack for async commands on Windows if CURRENT_OS is OSType.WINDOWS: if not wait: timeout = 10 # prepare command line thread = threading.Thread(target=fork_it) thread.start() # wait for thread to finish or timeout thread.join(timeout) # kill thread if it exceed the timeout if thread.is_alive(): if wait: Process.kill_by_commandline(command.partition(' ')[0].rpartition(os.sep)[-1]) thread.join() raise NameError('Process has timed out at ' + time.strftime("%X")) # get whenever exist in the pipe ? pipe_output = 'NOT_COLLECTED' if output: pipe_output = File.read(out_file) if (log_level is CommandLogLevel.FULL) and wait: print "##### OUTPUT BEGIN #####\n" print pipe_output print "##### OUTPUT END #####\n" if wait: return pipe_output.strip('\r\n') else: return out_file
def stop(): """ Stop all running emulators. """ print 'Stop all running emulators.' Process.kill_by_commandline('qemu') Process.kill_by_commandline('emulator64') Process.kill('emulator64-arm') Process.kill('emulator64-x86') Process.kill('emulator-arm') Process.kill('emulator-x86') Process.kill('qemu-system-arm') Process.kill('qemu-system-i386') Process.kill('qemu-system-i38') assert not Emulator.is_running( device_id=EMULATOR_ID), 'Emulator is still running!'
def tearDown(self): BaseClass.tearDown(self) Process.kill('Safari') Process.kill('NativeScript Inspector') Tns.kill()
def setUp(self): BaseClass.setUp(self) Process.kill('Safari') Process.kill('NativeScript Inspector') Tns.kill()