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.')
def __init__(self, id, name, type, model, version): self.id = id self.type = type self.version = version self.model = model self.name = name if type is DeviceType.IOS: type = run(cmd="ideviceinfo | grep ProductType").output type = type.replace(',', '') type = type.replace('ProductType:', '').strip(' ') self.name = type if type is DeviceType.SIM: self.model = name if type is DeviceType.EMU: cmd = 'shell getprop ro.product.model' model = Adb.run_adb_command(command=cmd, wait=True, device_id=self.id).output self.model = model.strip('\n\r') else: self.name = name if type is DeviceType.SIM: self.device_log_file = Simctl.get_log_file(self.id)
def test_365_tns_run_android_should_respect_adb_errors(self): """ If device memory is full and error is thrown during deploy cli should respect it https://github.com/NativeScript/nativescript-cli/issues/2170 """ # Deploy the app to make sure we have something at /data/data/org.nativescript.TestApp result = run_hello_world_js_ts(self.app_name, Platform.ANDROID, self.emu, just_launch=True) # Use all the disk space on emulator dest_file = '/data/data/' + TnsPaths.get_bundle_id(self.app_name) for index in range(1, 3000): command = "shell 'su 0 cp -r {0} {0}{1}'".format(dest_file, str(index)) result = Adb.run_adb_command(device_id=self.emu.id, command=command) Log.info(result.output) if "No space left on device" in result.output: break # Create new app Tns.create(app_name='TestApp2', template=Template.HELLO_WORLD_JS.local_package, update=True) # Run the app and verify there is appropriate error result = Tns.run_android('TestApp2', verify=True, device=self.emu.id, just_launch=True) strings = ['No space left on device'] TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=120)