def stop_application(app_id): """ Stop application :param app_id: Bundle identifier (example: org.nativescript.TestApp) """ command = 'xcrun simctl terminate booted {0}'.format(app_id) run(command=command, log_level=CommandLogLevel.FULL)
def update_typescript(path): """ Update modules for {N} project :param path: Path to {N} project :return: Output of command that update nativescript-typescript plugin. """ # Escape path with spaces if " " in path: path = "\"" + path + "\"" if USE_YARN == "True": Npm.uninstall(package="nativescript-typescript", folder=path) output = Npm.install(package=TYPESCRIPT_PACKAGE, folder=path) else: Npm.uninstall(package="nativescript-typescript", option="--save", folder=path) output = Npm.install(package=TYPESCRIPT_PACKAGE, option="--save", folder=path) if Npm.version() > 3: assert "ERR" not in output, "Something went wrong when typescript are installed." # Update TS dependencies update_script = os.path.join(TEST_RUN_HOME, path, "node_modules", ".bin", "ns-upgrade-tsconfig") run(update_script) if USE_YARN == "True": Npm.yarn_install(folder=path) else: Npm.install(folder=path) return output
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 update_webpack(path): """ Update modules for {N} project :param path: Path to {N} project :return: Output of command that update nativescript-dev-webpack plugin. """ # Escape path with spaces if " " in path: path = "\"" + path + "\"" if USE_YARN == "True": Npm.uninstall(package="nativescript-dev-webpack", option="--dev", folder=path) output = Npm.install(package=WEBPACK_PACKAGE, option="--dev", folder=path) else: Npm.uninstall(package="nativescript-dev-webpack", option="--save-dev", folder=path) output = Npm.install(package=WEBPACK_PACKAGE, option="--save-dev", folder=path) if Npm.version() > 3: assert "ERR" not in output, "Something went wrong when webpack are installed." # Update webpack dependencies update_script = os.path.join(TEST_RUN_HOME, path, "node_modules", ".bin", "update-ns-webpack --deps --configs") run(update_script) if USE_YARN == "True": Folder.cleanup(folder=os.path.join(TEST_RUN_HOME, path, "node_modules")) Npm.yarn_install(folder=path) else: Npm.install(folder=path) return output
def is_running(simulator_name=None): """ Check if simulator with given name is running :param simulator_name: Simulator name :return: Boolean value for simulator state and string with simulator id (if it is running). """ running = False if simulator_name is None: output = run(command='xcrun simctl list devices | grep Boot', timeout=60, log_level=CommandLogLevel.SILENT) lines = output.splitlines() if len(lines) > 0: running = True simid = lines[0].split('(')[1].split(')')[0] else: simid = None else: simid = Simulator.__get_id(name=simulator_name) if Simulator.__get_state(simulator_id=simid) == 'Booted': command = 'xcrun simctl spawn {0} launchctl print system | grep com.apple.springboard.services'.format( simid) output = run(command=command, timeout=60, log_level=CommandLogLevel.SILENT) if "M A com.apple.springboard.services" in output: print 'Simulator "{0}" loaded.'.format(simulator_name) running = True else: print 'Simulator "{0}" still loading...'.format(simulator_name) running = False return running, simid
def version(): if USE_YARN == "True": version = run('yarn -v', log_level=CommandLogLevel.SILENT) return int(version.split('.')[0]) else: version = run('npm -v', log_level=CommandLogLevel.SILENT) return int(version.split('.')[0])
def cache_clean(): print "Clean gradle cache." if CURRENT_OS == OSType.WINDOWS: run("rmdir /s /q {USERPROFILE}\\.gradle".format(**os.environ), COMMAND_TIMEOUT) else: run("rm -rf ~/.gradle", 600)
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 update_typescript(path): """ Update modules for {N} project :param path: Path to {N} project :return: Output of command that update nativescript-typescript plugin. """ # Escape path with spaces if " " in path: path = "\"" + path + "\"" if USE_YARN == "True": Npm.uninstall(package="nativescript-typescript", folder=path) output = Npm.install(package=TYPESCRIPT_PACKAGE, folder=path) else: Npm.uninstall(package="nativescript-typescript", option="--save", folder=path) output = Npm.install(package=TYPESCRIPT_PACKAGE, option="--save", folder=path) if Npm.version() > 3: assert "ERR" not in output, "Something went wrong when typescript are installed." # Update TS dependencies update_script = os.path.join(TEST_RUN_HOME, path, "node_modules", ".bin", "ns-upgrade-tsconfig") run(update_script) if USE_YARN == "True": Npm.yarn_install(folder=path) else: Npm.install(folder=path) return output
def turn_on_screen(device_id): """ Turn on screen. :param device_id: Device identifier """ cmd_key_event = ADB_PATH + " -s " + device_id + " shell input keyevent 26" cmd_input_method = ADB_PATH + " -s " + device_id + " shell dumpsys input_method | grep mActive" output = run(command=cmd_input_method, log_level=CommandLogLevel.SILENT) is_active = "mActive=true" in output if is_active: print "The screen is already active." run(command=cmd_key_event, log_level=CommandLogLevel.SILENT) time.sleep(1) output = run(command=cmd_input_method, log_level=CommandLogLevel.SILENT) assert "mActive=false" in output time.sleep(1) run(command=cmd_key_event) time.sleep(1) output = run(command=cmd_input_method, log_level=CommandLogLevel.SILENT) assert "mActive=true" in output else: print "The screen is not active. Turn it on..." run(command=cmd_key_event) time.sleep(1) output = run(command=cmd_input_method, log_level=CommandLogLevel.SILENT) assert "mActive=true" in output
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 is_running(simulator_name=None): """ Check if simulator with given name is running :param simulator_name: Simulator name :return: Boolean value for simulator state and string with simulator id (if it is running). """ running = False if simulator_name is None: output = run(command='xcrun simctl list devices | grep Boot', timeout=60, log_level=CommandLogLevel.SILENT) lines = output.splitlines() if len(lines) > 0: running = True simid = lines[0].split('(')[1].split(')')[0] else: simid = None else: simid = Simulator.__get_id(name=simulator_name) if Simulator.__get_state(simulator_id=simid) == 'Booted': command = 'xcrun simctl spawn {0} launchctl print system | grep com.apple.springboard.services'.format( simid) output = run(command=command, timeout=60, log_level=CommandLogLevel.SILENT) if "M A com.apple.springboard.services" in output: print 'Simulator "{0}" loaded.'.format(simulator_name) running = True else: print 'Simulator "{0}" still loading...'.format( simulator_name) running = False return running, simid
def reset(): """ Reset settings and storage of all simulators. """ Simulator.stop() run(command='xcrun simctl erase all', timeout=300, log_level=CommandLogLevel.SILENT) print 'Reset settings and storage of all simulators.'
def version(): if USE_YARN == "True": version = run('yarn -v', log_level=CommandLogLevel.SILENT) return int(version.split('.')[0]) else: version = run('npm -v', log_level=CommandLogLevel.SILENT) return int(version.split('.')[0])
def turn_on_screen(device_id): """ Turn on screen. :param device_id: Device identifier """ cmd_key_event = ADB_PATH + " -s " + device_id + " shell input keyevent 26" cmd_input_method = ADB_PATH + " -s " + device_id + " shell dumpsys input_method | grep mActive" output = run(command=cmd_input_method, log_level=CommandLogLevel.SILENT) is_active = "mActive=true" in output if is_active: print "The screen is already active." run(command=cmd_key_event, log_level=CommandLogLevel.SILENT) time.sleep(1) output = run(command=cmd_input_method, log_level=CommandLogLevel.SILENT) assert "mActive=false" in output time.sleep(1) run(command=cmd_key_event) time.sleep(1) output = run(command=cmd_input_method, log_level=CommandLogLevel.SILENT) assert "mActive=true" in output else: print "The screen is not active. Turn it on..." run(command=cmd_key_event) time.sleep(1) output = run(command=cmd_input_method, log_level=CommandLogLevel.SILENT) assert "mActive=true" in output
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 stop_application(app_id): """ Stop application :param app_id: Bundle identifier (example: org.nativescript.TestApp) """ command = 'xcrun simctl terminate booted {0}'.format(app_id) run(command=command, log_level=CommandLogLevel.FULL)
def run_app(url, emulator_id, platform): """Runs your project in the Preview App on simulator or emulator""" if platform is Platform.IOS: cmd = "xcrun simctl openurl {0} {1}.".format(emulator_id, url) output = run(command=cmd, log_level=CommandLogLevel.COMMAND_ONLY) elif platform is Platform.ANDROID: cmd = 'adb -s {0} shell am start -a android.intent.action.VIEW -d "{1}" org.nativescript.preview'.format(emulator_id, url) output = run(command=cmd, log_level=CommandLogLevel.COMMAND_ONLY)
def get_screen(device_id, file_path): """ Save screen of iOS Simulator. :param device_id: Device identifier (Simualtor GUID) :param file_path: Name of image that will be saved. """ run(command="xcrun simctl io {0} screenshot {1}".format(device_id, file_path), log_level=CommandLogLevel.SILENT) assert File.exists(file_path), "Failed to get screenshot at " + file_path
def dismiss_simulator_alert(): """When preview url is loaded in simulator there is alert for confirmation. This method will dismiss it. It is implemented only for one instance of simulator for the moment""" dismiss_sim_alert = os.path.join(TEST_RUN_HOME, 'core', 'device', 'helpers', 'send_enter_to_simulator.scpt') command = "osascript " + dismiss_sim_alert run(command, log_level=CommandLogLevel.FULL)
def reset(): """ Reset settings and storage of all simulators. """ Simulator.stop() run(command='xcrun simctl erase all', timeout=300, log_level=CommandLogLevel.SILENT) print 'Reset settings and storage of all simulators.'
def run_app(url, emulator_id, platform): """Runs your project in the Preview App on simulator or emulator""" if platform is Platform.IOS: cmd = "xcrun simctl openurl {0} {1}.".format(emulator_id, url) output = run(command=cmd, log_level=CommandLogLevel.COMMAND_ONLY) elif platform is Platform.ANDROID: cmd = 'adb -s {0} shell am start -a android.intent.action.VIEW -d "{1}" org.nativescript.preview'.format( emulator_id, url) output = run(command=cmd, log_level=CommandLogLevel.COMMAND_ONLY)
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 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)
def get_screen(device_id, file_path): """ Save screen of iOS Simulator. :param device_id: Device identifier (Simualtor GUID) :param file_path: Name of image that will be saved. """ run(command="xcrun simctl io {0} screenshot {1}".format( device_id, file_path), log_level=CommandLogLevel.SILENT) assert File.exists( file_path), "Failed to get screenshot at " + file_path
def test_399_build_project_with_gz_file(self): # This is required when build with different SDK Folder.cleanup(self.app_name) Tns.create_app(self.app_name) Tns.platform_add_android(attributes={"--path": self.app_name, "--frameworkPath": ANDROID_PACKAGE}) # Create zip run("tar -czf " + self.app_name + "/app/app.tar.gz " + self.app_name + "/app/app.js") assert File.exists(self.app_name + "/app/app.tar.gz") # Build the project Tns.build_android(attributes={"--path": self.app_name})
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 get_screen(device_id, file_path): """ Save screen of mobile device. :param device_id: Device identifier (example: `emulator-5554`). :param file_path: Name of image that will be saved. """ base_path, file_name = os.path.split(file_path) file_name = file_name.rsplit('.', 1)[0] run(command="idevicescreenshot -u {0} {1}.tiff".format(device_id, file_name), log_level=CommandLogLevel.SILENT) run(command="sips -s format png {0}.tiff --out {1}".format(file_name, file_path), log_level=CommandLogLevel.SILENT) File.remove("{0}.tiff".format(file_name))
def test_399_build_project_with_gz_file(self): # This is required when build with different SDK Folder.cleanup(self.app_name) Tns.create_app(self.app_name) Tns.platform_add_android(attributes={ "--path": self.app_name, "--frameworkPath": ANDROID_PACKAGE }) # Create zip run("tar -czf " + self.app_name + "/app/app.tar.gz " + self.app_name + "/app/app.js") assert File.exists(self.app_name + "/app/app.tar.gz") # Build the project Tns.build_android(attributes={"--path": self.app_name})
def delete(name): """ Delete simulator. :param name: Simulator name. """ delete_output = "" output = run(command='xcrun simctl list | grep \'{0}\''.format(name), log_level=CommandLogLevel.SILENT) while (SIMULATOR_NAME in output) and ('Invalid' not in output): if 'Booted' in output: run('xcrun simctl shutdown \'{0}\''.format(name), log_level=CommandLogLevel.SILENT) Simulator.stop() delete_output = run('xcrun simctl delete \'{0}\''.format(name), log_level=CommandLogLevel.SILENT) output = run('xcrun simctl list | grep \'{0}\''.format(name), log_level=CommandLogLevel.SILENT) assert "Unable to delete" not in delete_output, "Failed to delete simulator {0}".format(name) print 'Simulator \'{0}\' deleted.'.format(name)
def get_devices(): """ Get available iOS devices (only real devices). """ device_ids = list() output = run(command='idevice_id --list', timeout=60, log_level=CommandLogLevel.SILENT) for line in output.splitlines(): command = 'instruments -s | grep {0}'.format(line) check_connected = run(command=command, timeout=30, log_level=CommandLogLevel.SILENT) if 'null' not in check_connected: device_ids.append(line) else: message = '{0} is not trusted!'.format(line) print message return device_ids
def __run_yarn_command(command, folder=None, log_level=CommandLogLevel.FULL): if folder is not None: Folder.navigate_to(folder=folder, relative_from_current_folder=True) output = run('yarn {0}'.format(command), log_level=log_level) if folder is not None: Folder.navigate_to(TEST_RUN_HOME, relative_from_current_folder=False) return output
def start(emulator_name=EMULATOR_NAME, port=EMULATOR_PORT, timeout=300, wipe_data=True): """ Start emulator. :param wipe_data: If true it will wipe emulator date. :param emulator_name: Name of android emulator image (avd). :param port: Port for Android emulator. :param timeout: Time to wait until emulator boot. """ print 'Starting emulator {0}'.format(emulator_name) if CURRENT_OS == OSType.WINDOWS: start_command = 'START /B ' + EMULATOR_PATH + ' -avd ' + emulator_name + ' -port ' + port else: start_command = EMULATOR_PATH + ' -avd ' + emulator_name + ' -port ' + port if wipe_data: start_command += ' -wipe-data' log_file = run(start_command, timeout=timeout, wait=False, log_level=CommandLogLevel.COMMAND_ONLY) # Check if emulator is running device_name = 'emulator-' + port if Emulator.wait(device_name, timeout): print 'Emulator started successfully.' else: print 'Emulator failed to boot!' print File.read(log_file) raise Exception('Wait for emulator failed!')
def bundletool_deploy(bundletool_path, path_to_apks, device_id): deploy_command = ( 'java -jar {0} install-apks --apks="{1}" --device-id={2}').format( bundletool_path, path_to_apks, EMULATOR_ID) output = run(deploy_command, log_level=CommandLogLevel.FULL) assert not "Error" in output, "deploy of app failed" assert "The APKs have been extracted in the directory:" in output, "deploy of app failed"
def get_version(): """ Get Xcode version :return: Version as string. """ output = run(command="xcodebuild -version | head -n 1 | sed -e 's/Xcode //'", log_level=CommandLogLevel.SILENT) return int(output.split('.')[0])
def test_100_prepare_ios(self): Tns.platform_add_android(attributes={"--path": self.app_name, "--frameworkPath": ANDROID_PACKAGE}) # Initial prepare should be full. output = Tns.prepare_ios(attributes={"--path": self.app_name}) TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.FULL) # If no file is touched next time prepare should be skipped at all. output = Tns.prepare_ios(attributes={"--path": self.app_name}, assert_success=False) TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.SKIP) # If some JS/CSS/XML is changed incremental prepare should be done. ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS) output = Tns.prepare_ios(attributes={"--path": self.app_name}) TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.INCREMENTAL) # Verify Xcode Schemes output = run("xcodebuild -project " + self.app_name + "/platforms/ios/TestApp.xcodeproj/ -list") assert "This project contains no schemes." not in output result = re.search("Targets:\n\s*TestApp", output) assert result is not None result = re.search("Schemes:\n\s*TestApp", output) assert result is not None # Initial prepare for other platform (Android) should be full. output = Tns.prepare_android(attributes={"--path": self.app_name}) TnsAsserts.prepared(self.app_name, platform=Platform.ANDROID, output=output, prepare=Prepare.FULL) # Prepare original platform (iOS) should be skipped. output = Tns.prepare_ios(attributes={"--path": self.app_name}, assert_success=False) TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.SKIP) # Initial prepare for other platform (Android) should be skipped. output = Tns.prepare_android(attributes={"--path": self.app_name}, assert_success=False) TnsAsserts.prepared(self.app_name, platform=Platform.ANDROID, output=output, prepare=Prepare.SKIP)
def test_100_prepare_ios(self): Tns.platform_add_android(attributes={ "--path": self.app_name, "--frameworkPath": ANDROID_PACKAGE }) # Initial prepare should be full. output = Tns.prepare_ios(attributes={"--path": self.app_name}) TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.FULL) # If no file is touched next time prepare should be skipped at all. output = Tns.prepare_ios(attributes={"--path": self.app_name}, assert_success=False) TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.SKIP) # If some JS/CSS/XML is changed incremental prepare should be done. ReplaceHelper.replace(self.app_name, ReplaceHelper.CHANGE_JS) output = Tns.prepare_ios(attributes={"--path": self.app_name}) TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.INCREMENTAL) # Verify Xcode Schemes output = run("xcodebuild -project " + self.app_name + "/platforms/ios/TestApp.xcodeproj/ -list") assert "This project contains no schemes." not in output result = re.search("Targets:\n\s*TestApp", output) assert result is not None result = re.search("Schemes:\n\s*TestApp", output) assert result is not None # Initial prepare for other platform (Android) should be full. output = Tns.prepare_android(attributes={"--path": self.app_name}) TnsAsserts.prepared(self.app_name, platform=Platform.ANDROID, output=output, prepare=Prepare.FULL) # Prepare original platform (iOS) should be skipped. output = Tns.prepare_ios(attributes={"--path": self.app_name}, assert_success=False) TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.SKIP) # Initial prepare for other platform (Android) should be skipped. output = Tns.prepare_android(attributes={"--path": self.app_name}, assert_success=False) TnsAsserts.prepared(self.app_name, platform=Platform.ANDROID, output=output, prepare=Prepare.SKIP)
def start(emulator_name=EMULATOR_NAME, port=EMULATOR_PORT, timeout=300, wipe_data=True): """ Start emulator. :param wipe_data: If true it will wipe emulator date. :param emulator_name: Name of android emulator image (avd). :param port: Port for Android emulator. :param timeout: Time to wait until emulator boot. """ print 'Starting emulator {0}'.format(emulator_name) if CURRENT_OS == OSType.WINDOWS: start_command = 'START /B ' + EMULATOR_PATH + ' -avd ' + emulator_name + ' -port ' + port else: start_command = EMULATOR_PATH + ' -avd ' + emulator_name + ' -port ' + port if wipe_data: start_command += ' -wipe-data' log_file = run(start_command, timeout=timeout, wait=False, log_level=CommandLogLevel.COMMAND_ONLY) # Check if emulator is running device_name = 'emulator-' + port if Emulator.wait(device_name, timeout): print 'Emulator started successfully.' else: print 'Emulator failed to boot!' print File.read(log_file) raise Exception('Wait for emulator failed!')
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 update_angular(path): """ Update modules for {N} project :param path: Path to {N} project :return: Output of command that update nativescript-angular plugin. """ # Escape path with spaces if " " in path: path = "\"" + path + "\"" if USE_YARN == "True": Npm.uninstall(package="nativescript-angular", folder=path) output = Npm.install(package=ANGULAR_PACKAGE, folder=path) else: Npm.uninstall(package="nativescript-angular", option="--save", folder=path) output = Npm.install(package=ANGULAR_PACKAGE, option="--save", folder=path) if Npm.version() > 3: assert "ERR" not in output, "Something went wrong when angular are installed." # Update NG dependencies update_script = os.path.join(TEST_RUN_HOME, path, "node_modules", ".bin", "update-app-ng-deps") update_out = run(update_script) assert "Angular dependencies updated" in update_out if USE_YARN == "True": Npm.yarn_install(folder=path) else: Npm.install(folder=path) return output
def install(path): """ Install application :param path: Path to app """ command = 'xcrun simctl install booted {0}'.format(path) output = run(command=command, log_level=CommandLogLevel.SILENT) assert "Failed to install the requested application " + path not in output
def get_package_permission(apk_file): """ Get permission from apk file. :param apk_file: Path to apk file. :return: Permissions as string. """ command = Adb.__find_aapt() + ' d permissions ' + apk_file return run(command=command, log_level=CommandLogLevel.COMMAND_ONLY)
def get_package_permission(apk_file): """ Get permission from apk file. :param apk_file: Path to apk file. :return: Permissions as string. """ command = Adb.__find_aapt() + ' d permissions ' + apk_file return run(command=command, log_level=CommandLogLevel.COMMAND_ONLY)
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 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 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 install(path): """ Install application :param path: Path to app """ command = 'xcrun simctl install booted {0}'.format(path) output = run(command=command, log_level=CommandLogLevel.SILENT) assert "Failed to install the requested application " + path not in output
def uninstall(app_id): """ Uninstall application :param app_id: Bundle identifier (example: org.nativescript.TestApp) """ command = "xcrun simctl uninstall booted " + app_id output = run(command=command, log_level=CommandLogLevel.SILENT) assert "Failed to uninstall the requested application " + app_id not in output
def uninstall_all_app(device_id, app_prefix): """ Uninstall all apps on all connected iOS physical devices. :param device_id: Device identifier. :param app_prefix: App prefix, for example: org.nativescript. """ output = run("ideviceinstaller -u {0} -l".format(device_id), timeout=120) if "command not found" in output: raise NameError("ideviceinstaller not installed!") lines = output.splitlines() for line in lines: if app_prefix in line: app_name = line.split(",")[0].split("-")[0].replace(" ", "") uninstall_result = run("ideviceinstaller -u {0} -U {1}".format(device_id, app_name), timeout=120) if "Complete" in uninstall_result: print "{0} application successfully uninstalled.".format(app_prefix) else: raise NameError("{0} application failed to uninstall.".format(app_prefix))
def get_version(): """ Get Xcode version :return: Version as string. """ output = run( command="xcodebuild -version | head -n 1 | sed -e 's/Xcode //'", log_level=CommandLogLevel.SILENT) return int(output.split('.')[0])
def uninstall(app_id): """ Uninstall application :param app_id: Bundle identifier (example: org.nativescript.TestApp) """ command = "xcrun simctl uninstall booted " + app_id output = run(command=command, log_level=CommandLogLevel.SILENT) assert "Failed to uninstall the requested application " + app_id not in output
def test_001_tns_resources_generate_icons(self): app_resources_android = os.path.join(TEST_RUN_HOME, self.app_name, self.app_resources) app_resources_ios = os.path.join(TEST_RUN_HOME, self.app_name, self.assets_icons) output = run("tns resources generate icons \"" + self.image_path + "\"" + " --path " + self.app_name) assert "Generating icons" in output assert "Icons generation completed" in output ResourcesGenerateTests.check_icons(app_resources_android, app_resources_ios)
def __list_path(package_id, path): """ List file of application. :param package_id: Package identifier. :param path: Path relative to root folder of the package. :return: List of files and folders """ base_path = Simulator.__get_bundle_path(package_id=package_id) output = run(command='ls -la {0}/{1}'.format(base_path, path), log_level=CommandLogLevel.FULL) return output
def save_screen(path): """ Save screen of host machine. :param path: Path where screen will be saved. """ print 'Save current host screen at {0}'.format(path) if CURRENT_OS is OSType.LINUX: import os os.system("import -window root {0}".format(path)) else: try: from PIL import ImageGrab im = ImageGrab.grab() im.save(path) except IOError: print 'Failed to take screen of host OS' if CURRENT_OS is OSType.OSX: print 'Retry...' run('screencapture ' + path)
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 __list_path(package_id, path): """ List file of application. :param package_id: Package identifier. :param path: Path relative to root folder of the package. :return: List of files and folders """ base_path = Simulator.__get_bundle_path(package_id=package_id) output = run(command='ls -la {0}/{1}'.format(base_path, path), log_level=CommandLogLevel.FULL) return output