How to use expectUnreverseTcpPortCalled method in root

Best JavaScript code snippet using root

RuntimeDevice.test.js

Source:RuntimeDevice.test.js Github

copy

Full Screen

...70 }71 expectReverseTcpPortCalled(port) {72 expect(this.driver.reverseTcpPort).toHaveBeenCalledWith(port);73 }74 expectUnreverseTcpPortCalled(port) {75 expect(this.driver.unreverseTcpPort).toHaveBeenCalledWith(port);76 }77 }78 function aDevice(overrides) {79 const appsConfig = overrides.appsConfig || {};80 errorComposer = new DetoxRuntimeErrorComposer({ appsConfig });81 const device = new RuntimeDevice({82 appsConfig,83 behaviorConfig: {},84 deviceConfig: {},85 sessionConfig: {},86 runtimeErrorComposer: errorComposer,87 eventEmitter: emitter,88 ...overrides,89 }, driverMock.driver);90 device.deviceDriver.getBundleIdFromBinary.mockReturnValue(bundleId);91 return device;92 }93 function aValidUnpreparedDevice(overrides) {94 const configs = _.merge(_.cloneDeep({95 appsConfig: {96 default: configurationsMock.appWithRelativeBinaryPath,97 },98 deviceConfig: configurationsMock.iosSimulatorWithShorthandQuery,99 sessionConfig: configurationsMock.validSession,100 }), overrides);101 if (overrides && overrides.appsConfig === null) {102 configs.appsConfig = {};103 }104 return aDevice(configs);105 }106 async function aValidDevice(overrides) {107 const device = aValidUnpreparedDevice(overrides);108 await device._prepare();109 return device;110 }111 async function aValidDeviceWithLaunchArgs(launchArgs) {112 return await aValidDevice({113 appsConfig: {114 default: {115 launchArgs,116 },117 },118 });119 }120 it('should return the name from the driver', async () => {121 driverMock.driver.getDeviceName.mockReturnValue('mock-device-name-from-driver');122 const device = await aValidDevice();123 expect(device.name).toEqual('mock-device-name-from-driver');124 });125 it('should return the type from the configuration', async () => {126 const device = await aValidDevice();127 expect(device.type).toEqual('ios.simulator');128 });129 it('should return the device ID, as provided by acquireFreeDevice', async () => {130 const device = await aValidUnpreparedDevice();131 await device._prepare();132 driverMock.driver.getExternalId.mockReturnValue('mockExternalId');133 expect(device.id).toEqual('mockExternalId');134 driverMock.expectExternalIdCalled();135 });136 describe('selectApp()', () => {137 let device;138 describe('when there is a single app', () => {139 beforeEach(async () => {140 device = await aValidUnpreparedDevice();141 jest.spyOn(device, 'selectApp');142 await device._prepare();143 });144 it(`should select the default app upon prepare()`, async () => {145 expect(device.selectApp).toHaveBeenCalledWith('default');146 });147 it(`should function as usual when the app is selected`, async () => {148 await device.launchApp();149 expect(driverMock.driver.launchApp).toHaveBeenCalled();150 });151 it(`should throw on call without args`, async () => {152 await expect(device.selectApp()).rejects.toThrowError(errorComposer.cantSelectEmptyApp());153 });154 it(`should throw on app interactions with no selected app`, async () => {155 await device.selectApp(null);156 await expect(device.launchApp()).rejects.toThrowError(errorComposer.appNotSelected());157 });158 it(`should throw on attempt to select a non-existent app`, async () => {159 await expect(device.selectApp('nonExistent')).rejects.toThrowError();160 });161 });162 describe('when there are multiple apps', () => {163 beforeEach(async () => {164 device = await aValidUnpreparedDevice({165 appsConfig: {166 withBinaryPath: {167 binaryPath: 'path/to/app',168 },169 withBundleId: {170 binaryPath: 'path/to/app2',171 bundleId: 'com.app2'172 },173 },174 });175 jest.spyOn(device, 'selectApp');176 driverMock.driver.getBundleIdFromBinary.mockReturnValue('com.app1');177 await device._prepare();178 });179 it(`should not select the app at all`, async () => {180 expect(device.selectApp).not.toHaveBeenCalled();181 });182 it(`upon select, it should infer bundleId if it is missing`, async () => {183 await device.selectApp('withBinaryPath');184 expect(driverMock.driver.getBundleIdFromBinary).toHaveBeenCalledWith('path/to/app');185 });186 it(`upon select, it should terminate the previous app`, async () => {187 jest.spyOn(device, 'terminateApp');188 await device.selectApp('withBinaryPath');189 expect(device.terminateApp).not.toHaveBeenCalled(); // because no app was running before190 await device.selectApp('withBundleId');191 expect(device.terminateApp).toHaveBeenCalled(); // because there is a running app192 });193 it(`upon select, it should not infer bundleId if it is specified`, async () => {194 await device.selectApp('withBundleId');195 expect(driverMock.driver.getBundleIdFromBinary).not.toHaveBeenCalled();196 });197 it(`upon re-selecting the same app, it should not infer bundleId twice`, async () => {198 await device.selectApp('withBinaryPath');199 await device.selectApp('withBundleId');200 await device.selectApp('withBinaryPath');201 expect(driverMock.driver.getBundleIdFromBinary).toHaveBeenCalledTimes(1);202 });203 });204 describe('when there are no apps', () => {205 beforeEach(async () => {206 device = await aValidUnpreparedDevice({207 appsConfig: null208 });209 jest.spyOn(device, 'selectApp');210 await device._prepare();211 });212 it(`should not select the app at all`, async () => {213 expect(device.selectApp).not.toHaveBeenCalled();214 });215 it(`should be able to execute actions with an explicit bundleId`, async () => {216 const bundleId = 'com.example.app';217 jest.spyOn(device, 'terminateApp');218 await device.uninstallApp(bundleId);219 expect(driverMock.driver.uninstallApp).toHaveBeenCalledWith(bundleId);220 await device.installApp('/tmp/app', '/tmp/app-test');221 expect(driverMock.driver.installApp).toHaveBeenCalledWith('/tmp/app', '/tmp/app-test');222 await device.launchApp({}, bundleId);223 expect(driverMock.driver.launchApp).toHaveBeenCalledWith(bundleId, expect.anything(), undefined);224 await device.terminateApp(bundleId);225 expect(driverMock.driver.terminate).toHaveBeenCalledWith(bundleId);226 await device.uninstallApp(bundleId);227 expect(driverMock.driver.uninstallApp).toHaveBeenCalledWith(bundleId);228 });229 });230 });231 describe('re/launchApp()', () => {232 const expectedDriverArgs = {233 'detoxServer': 'ws://localhost:8099',234 'detoxSessionId': 'test',235 };236 it(`with no args should launch app with defaults`, async () => {237 const expectedArgs = expectedDriverArgs;238 const device = await aValidDevice();239 await device.launchApp();240 driverMock.expectLaunchCalledWithArgs(bundleId, expectedArgs);241 });242 it(`given behaviorConfig.launchApp == 'manual' should wait for the app launch`, async () => {243 const expectedArgs = expectedDriverArgs;244 const device = await aValidDevice({245 behaviorConfig: { launchApp: 'manual' }246 });247 await device.launchApp();248 expect(driverMock.driver.launchApp).not.toHaveBeenCalled();249 driverMock.expectWaitForLaunchCalled(bundleId, expectedArgs);250 });251 it(`args should launch app and emit appReady`, async () => {252 driverMock.driver.launchApp = async () => 42;253 const device = await aValidDevice();254 await device.launchApp();255 expect(emitter.emit).toHaveBeenCalledWith('appReady', {256 deviceId: device.id,257 bundleId: device._bundleId,258 pid: 42,259 });260 });261 it(`(relaunch) with no args should use defaults`, async () => {262 const expectedArgs = expectedDriverArgs;263 const device = await aValidDevice();264 await device.relaunchApp();265 driverMock.expectLaunchCalledWithArgs(bundleId, expectedArgs);266 });267 it(`(relaunch) with no args should terminate the app before launch - backwards compat`, async () => {268 const device = await aValidDevice();269 await device.relaunchApp();270 driverMock.expectTerminateCalled();271 });272 it(`(relaunch) with newInstance=false should not terminate the app before launch`, async () => {273 const device = await aValidDevice();274 await device.relaunchApp({ newInstance: false });275 driverMock.expectTerminateNotCalled();276 });277 it(`(relaunch) with newInstance=true should terminate the app before launch`, async () => {278 const device = await aValidDevice();279 await device.relaunchApp({ newInstance: true });280 driverMock.expectTerminateCalled();281 });282 it(`(relaunch) with delete=true`, async () => {283 const expectedArgs = expectedDriverArgs;284 const device = await aValidDevice();285 await device.relaunchApp({ delete: true });286 driverMock.expectReinstallCalled();287 driverMock.expectLaunchCalledWithArgs(bundleId, expectedArgs);288 });289 it(`(relaunch) with delete=false when reuse is enabled should not uninstall and install`, async () => {290 const expectedArgs = expectedDriverArgs;291 const device = await aValidDevice();292 argparse.getArgValue.mockReturnValue(true);293 await device.relaunchApp();294 driverMock.expectReinstallNotCalled();295 driverMock.expectLaunchCalledWithArgs(bundleId, expectedArgs);296 });297 it(`(relaunch) with url should send the url as a param in launchParams`, async () => {298 const expectedArgs = { ...expectedDriverArgs, 'detoxURLOverride': 'scheme://some.url' };299 const device = await aValidDevice();300 await device.relaunchApp({ url: `scheme://some.url` });301 driverMock.expectLaunchCalledWithArgs(bundleId, expectedArgs);302 });303 it(`(relaunch) with url should send the url as a param in launchParams`, async () => {304 const expectedArgs = {305 ...expectedDriverArgs,306 'detoxURLOverride': 'scheme://some.url',307 'detoxSourceAppOverride': 'sourceAppBundleId',308 };309 const device = await aValidDevice();310 await device.relaunchApp({ url: `scheme://some.url`, sourceApp: 'sourceAppBundleId' });311 driverMock.expectLaunchCalledWithArgs(bundleId, expectedArgs);312 });313 it(`(relaunch) with userNofitication should send the userNotification as a param in launchParams`, async () => {314 const expectedArgs = {315 ...expectedDriverArgs,316 'detoxUserNotificationDataURL': 'url',317 };318 const device = await aValidDevice();319 device.deviceDriver.createPayloadFile = jest.fn(() => 'url');320 await device.relaunchApp({ userNotification: 'json' });321 driverMock.expectLaunchCalledWithArgs(bundleId, expectedArgs);322 });323 it(`(relaunch) with url and userNofitication should throw`, async () => {324 const device = await aValidDevice();325 try {326 await device.relaunchApp({ url: 'scheme://some.url', userNotification: 'notif' });327 fail('should fail');328 } catch (ex) {329 expect(ex).toBeDefined();330 }331 });332 it(`(relaunch) with permissions should send trigger setpermissions before app starts`, async () => {333 const device = await aValidDevice();334 await device.relaunchApp({ permissions: { calendar: 'YES' } });335 expect(driverMock.driver.setPermissions).toHaveBeenCalledWith(bundleId, { calendar: 'YES' });336 });337 it('with languageAndLocale should launch app with a specific language/locale', async () => {338 const expectedArgs = expectedDriverArgs;339 const device = await aValidDevice();340 const languageAndLocale = {341 language: 'es-MX',342 locale: 'es-MX'343 };344 await device.launchApp({ languageAndLocale });345 driverMock.expectLaunchCalledWithArgs(bundleId, expectedArgs, languageAndLocale);346 });347 it(`with disableTouchIndicators should send a boolean switch as a param in launchParams`, async () => {348 const expectedArgs = { ...expectedDriverArgs, 'detoxDisableTouchIndicators': true };349 const device = await aValidDevice();350 await device.launchApp({ disableTouchIndicators: true });351 driverMock.expectLaunchCalledWithArgs(bundleId, expectedArgs);352 });353 it(`with newInstance=false should check if process is in background and reopen it`, async () => {354 const processId = 1;355 const device = await aValidDevice();356 device.deviceDriver.launchApp.mockReturnValue(processId);357 await device._prepare();358 await device.launchApp({ newInstance: true });359 await device.launchApp({ newInstance: false });360 expect(driverMock.driver.deliverPayload).not.toHaveBeenCalled();361 });362 it(`with a url should check if process is in background and use openURL() instead of launch args`, async () => {363 const processId = 1;364 const device = await aValidDevice();365 device.deviceDriver.launchApp.mockReturnValue(processId);366 await device._prepare();367 await device.launchApp({ newInstance: true });368 await device.launchApp({ url: 'url://me' });369 expect(driverMock.driver.deliverPayload).toHaveBeenCalledTimes(1);370 });371 it(`with a url should check if process is in background and if not use launch args`, async () => {372 const launchParams = { url: 'url://me' };373 const processId = 1;374 const newProcessId = 2;375 const device = await aValidDevice();376 device.deviceDriver.launchApp.mockReturnValueOnce(processId).mockReturnValueOnce(newProcessId);377 await device._prepare();378 await device.launchApp(launchParams);379 expect(driverMock.driver.deliverPayload).not.toHaveBeenCalled();380 });381 it(`with a url should check if process is in background and use openURL() instead of launch args`, async () => {382 const launchParams = { url: 'url://me' };383 const processId = 1;384 const device = await aValidDevice();385 device.deviceDriver.launchApp.mockReturnValue(processId);386 await device._prepare();387 await device.launchApp({ newInstance: true });388 await device.launchApp(launchParams);389 expect(driverMock.driver.deliverPayload).toHaveBeenCalledWith({ delayPayload: true, url: 'url://me' });390 });391 it('with userActivity should check if process is in background and if it is use deliverPayload', async () => {392 const launchParams = { userActivity: 'userActivity' };393 const processId = 1;394 const device = await aValidDevice();395 device.deviceDriver.launchApp.mockReturnValueOnce(processId).mockReturnValueOnce(processId);396 device.deviceDriver.createPayloadFile = () => 'url';397 await device._prepare();398 await device.launchApp({ newInstance: true });399 await device.launchApp(launchParams);400 expect(driverMock.driver.deliverPayload).toHaveBeenCalledWith({ delayPayload: true, detoxUserActivityDataURL: 'url' });401 });402 it('with userNotification should check if process is in background and if it is use deliverPayload', async () => {403 const launchParams = { userNotification: 'notification' };404 const processId = 1;405 const device = await aValidDevice();406 device.deviceDriver.launchApp.mockReturnValueOnce(processId).mockReturnValueOnce(processId);407 device.deviceDriver.createPayloadFile = () => 'url';408 await device._prepare();409 await device.launchApp({ newInstance: true });410 await device.launchApp(launchParams);411 expect(driverMock.driver.deliverPayload).toHaveBeenCalledTimes(1);412 });413 it(`with userNotification should check if process is in background and if not use launch args`, async () => {414 const launchParams = { userNotification: 'notification' };415 const processId = 1;416 const newProcessId = 2;417 const device = await aValidDevice();418 device.deviceDriver.launchApp.mockReturnValueOnce(processId).mockReturnValueOnce(newProcessId);419 await device._prepare();420 await device.launchApp(launchParams);421 expect(driverMock.driver.deliverPayload).not.toHaveBeenCalled();422 });423 it(`with userNotification and url should fail`, async () => {424 const launchParams = { userNotification: 'notification', url: 'url://me' };425 const processId = 1;426 driverMock.driver.launchApp.mockReturnValueOnce(processId).mockReturnValueOnce(processId);427 const device = await aValidDevice();428 await device._prepare();429 try {430 await device.launchApp(launchParams);431 fail('should throw');432 } catch (ex) {433 expect(ex).toBeDefined();434 }435 expect(device.deviceDriver.deliverPayload).not.toHaveBeenCalled();436 });437 it('should keep user params unmodified', async () => {438 const params = {439 url: 'some.url',440 launchArgs: {441 some: 'userArg',442 }443 };444 const paramsClone = _.cloneDeep(params);445 const device = await aValidDevice();446 await device.launchApp(params);447 expect(params).toStrictEqual(paramsClone);448 });449 describe('launch arguments', () => {450 const baseArgs = {451 detoxServer: 'ws://localhost:8099',452 detoxSessionId: 'test',453 };454 const someLaunchArgs = () => ({455 argX: 'valX',456 argY: { value: 'Y' },457 });458 it('should pass preconfigured launch-args to device via driver', async () => {459 const launchArgs = someLaunchArgs();460 const device = await aValidDeviceWithLaunchArgs(launchArgs);461 await device.launchApp();462 driverMock.expectLaunchCalledContainingArgs(launchArgs);463 });464 it('should pass on-site launch-args to device via driver', async () => {465 const launchArgs = someLaunchArgs();466 const expectedArgs = {467 ...baseArgs,468 ...launchArgs,469 };470 const device = await aValidDevice();471 await device.launchApp({ launchArgs });472 driverMock.expectLaunchCalledWithArgs(bundleId, expectedArgs);473 });474 it('should allow for launch-args modification', async () => {475 const launchArgs = someLaunchArgs();476 const argsModifier = {477 argY: null,478 argZ: 'valZ',479 };480 const expectedArgs = {481 argX: 'valX',482 argZ: 'valZ',483 };484 const device = await aValidDeviceWithLaunchArgs(launchArgs);485 device.appLaunchArgs.modify(argsModifier);486 await device.launchApp();487 driverMock.expectLaunchCalledContainingArgs(expectedArgs);488 });489 it('should override launch-args with on-site launch-args', async () => {490 const launchArgs = {491 aLaunchArg: 'aValue?',492 };493 const device = await aValidDeviceWithLaunchArgs();494 device.appLaunchArgs.modify(launchArgs);495 await device.launchApp({496 launchArgs: {497 aLaunchArg: 'aValue!',498 },499 });500 driverMock.expectLaunchCalledContainingArgs({ aLaunchArg: 'aValue!' });501 });502 it('should allow for resetting all args', async () => {503 const launchArgs = someLaunchArgs();504 const expectedArgs = { ...baseArgs };505 const device = await aValidDeviceWithLaunchArgs(launchArgs);506 device.appLaunchArgs.modify({ argZ: 'valZ' });507 device.appLaunchArgs.reset();508 await device.launchApp();509 driverMock.expectLaunchCalledWithArgs(bundleId, expectedArgs);510 });511 });512 });513 describe('installApp()', () => {514 it(`with a custom app path should use custom app path`, async () => {515 const device = await aValidDevice();516 await device.installApp('newAppPath');517 expect(driverMock.driver.installApp).toHaveBeenCalledWith('newAppPath', device._deviceConfig.testBinaryPath);518 });519 it(`with no args should use the default path given in configuration`, async () => {520 const device = await aValidDevice();521 await device.installApp();522 expect(driverMock.driver.installApp).toHaveBeenCalledWith(device._currentApp.binaryPath, device._currentApp.testBinaryPath);523 });524 });525 describe('uninstallApp()', () => {526 it(`with a custom app path should use custom app path`, async () => {527 const device = await aValidDevice();528 await device.uninstallApp('newBundleId');529 expect(driverMock.driver.uninstallApp).toHaveBeenCalledWith('newBundleId');530 });531 it(`with no args should use the default path given in configuration`, async () => {532 const device = await aValidDevice();533 await device.uninstallApp();534 expect(driverMock.driver.uninstallApp).toHaveBeenCalledWith(bundleId);535 });536 });537 describe('installBinary()', () => {538 it('should install the set of util binaries', async () => {539 const device = await aValidDevice({540 deviceConfig: {541 utilBinaryPaths: ['path/to/util/binary']542 },543 });544 await device.installUtilBinaries();545 expect(driverMock.driver.installUtilBinaries).toHaveBeenCalledWith(['path/to/util/binary']);546 });547 it('should break if driver installation fails', async () => {548 driverMock.driver.installUtilBinaries.mockRejectedValue(new Error());549 const device = await aValidDevice({550 deviceConfig: {551 utilBinaryPaths: ['path/to/util/binary']552 },553 });554 await expect(device.installUtilBinaries()).rejects.toThrowError();555 });556 it('should not install anything if util-binaries havent been configured', async () => {557 const device = await aValidDevice({});558 await device.installUtilBinaries();559 expect(driverMock.driver.installUtilBinaries).not.toHaveBeenCalled();560 });561 });562 it(`sendToHome() should pass to device driver`, async () => {563 const device = await aValidDevice();564 await device.sendToHome();565 expect(driverMock.driver.sendToHome).toHaveBeenCalledTimes(1);566 });567 it(`setBiometricEnrollment(true) should pass YES to device driver`, async () => {568 const device = await aValidDevice();569 await device.setBiometricEnrollment(true);570 expect(driverMock.driver.setBiometricEnrollment).toHaveBeenCalledWith('YES');571 expect(driverMock.driver.setBiometricEnrollment).toHaveBeenCalledTimes(1);572 });573 it(`setBiometricEnrollment(false) should pass NO to device driver`, async () => {574 const device = await aValidDevice();575 await device.setBiometricEnrollment(false);576 expect(driverMock.driver.setBiometricEnrollment).toHaveBeenCalledWith('NO');577 expect(driverMock.driver.setBiometricEnrollment).toHaveBeenCalledTimes(1);578 });579 it(`matchFace() should pass to device driver`, async () => {580 const device = await aValidDevice();581 await device.matchFace();582 expect(driverMock.driver.matchFace).toHaveBeenCalledTimes(1);583 });584 it(`unmatchFace() should pass to device driver`, async () => {585 const device = await aValidDevice();586 await device.unmatchFace();587 expect(driverMock.driver.unmatchFace).toHaveBeenCalledTimes(1);588 });589 it(`matchFinger() should pass to device driver`, async () => {590 const device = await aValidDevice();591 await device.matchFinger();592 expect(driverMock.driver.matchFinger).toHaveBeenCalledTimes(1);593 });594 it(`unmatchFinger() should pass to device driver`, async () => {595 const device = await aValidDevice();596 await device.unmatchFinger();597 expect(driverMock.driver.unmatchFinger).toHaveBeenCalledTimes(1);598 });599 it(`setStatusBar() should pass to device driver`, async () => {600 const device = await aValidDevice();601 const params = {};602 await device.setStatusBar(params);603 expect(driverMock.driver.setStatusBar).toHaveBeenCalledWith(params);604 });605 it(`resetStatusBar() should pass to device driver`, async () => {606 const device = await aValidDevice();607 await device.resetStatusBar();608 expect(driverMock.driver.resetStatusBar).toHaveBeenCalledWith();609 });610 it(`typeText() should pass to device driver`, async () => {611 const device = await aValidDevice();612 await device._typeText('Text');613 expect(driverMock.driver.typeText).toHaveBeenCalledWith('Text');614 });615 it(`shake() should pass to device driver`, async () => {616 const device = await aValidDevice();617 await device.shake();618 expect(driverMock.driver.shake).toHaveBeenCalledTimes(1);619 });620 it(`terminateApp() should pass to device driver`, async () => {621 const device = await aValidDevice();622 await device.terminateApp();623 expect(driverMock.driver.terminate).toHaveBeenCalledTimes(1);624 });625 it(`openURL({url:url}) should pass to device driver`, async () => {626 const device = await aValidDevice();627 await device.openURL({ url: 'url' });628 expect(driverMock.driver.deliverPayload).toHaveBeenCalledWith({ url: 'url' });629 });630 it(`openURL(notAnObject) should pass to device driver`, async () => {631 const device = await aValidDevice();632 try {633 await device.openURL('url');634 fail('should throw');635 } catch (ex) {636 expect(ex).toBeDefined();637 }638 });639 it(`reloadReactNative() should pass to device driver`, async () => {640 const device = await aValidDevice();641 await device.reloadReactNative();642 expect(driverMock.driver.reloadReactNative).toHaveBeenCalledTimes(1);643 });644 it(`setOrientation() should pass to device driver`, async () => {645 const device = await aValidDevice();646 await device.setOrientation('param');647 expect(driverMock.driver.setOrientation).toHaveBeenCalledWith('param');648 });649 it(`sendUserNotification() should pass to device driver`, async () => {650 const device = await aValidDevice();651 await device.sendUserNotification('notif');652 expect(driverMock.driver.createPayloadFile).toHaveBeenCalledTimes(1);653 expect(driverMock.driver.deliverPayload).toHaveBeenCalledTimes(1);654 });655 it(`sendUserActivity() should pass to device driver`, async () => {656 const device = await aValidDevice();657 await device.sendUserActivity('notif');658 expect(driverMock.driver.createPayloadFile).toHaveBeenCalledTimes(1);659 expect(driverMock.driver.deliverPayload).toHaveBeenCalledTimes(1);660 });661 it(`setLocation() should pass to device driver`, async () => {662 const device = await aValidDevice();663 await device.setLocation(30.1, 30.2);664 expect(driverMock.driver.setLocation).toHaveBeenCalledWith('30.1', '30.2');665 });666 it(`reverseTcpPort should pass to device driver`, async () => {667 const device = await aValidDevice();668 await device.reverseTcpPort(666);669 await driverMock.expectReverseTcpPortCalled(666);670 });671 it(`unreverseTcpPort should pass to device driver`, async () => {672 const device = await aValidDevice();673 await device.unreverseTcpPort(777);674 await driverMock.expectUnreverseTcpPortCalled(777);675 });676 it(`setURLBlacklist() should pass to device driver`, async () => {677 const device = await aValidDevice();678 await device.setURLBlacklist();679 expect(driverMock.driver.setURLBlacklist).toHaveBeenCalledTimes(1);680 });681 it(`enableSynchronization() should pass to device driver`, async () => {682 const device = await aValidDevice();683 await device.enableSynchronization();684 expect(driverMock.driver.enableSynchronization).toHaveBeenCalledTimes(1);685 });686 it(`disableSynchronization() should pass to device driver`, async () => {687 const device = await aValidDevice();688 await device.disableSynchronization();...

Full Screen

Full Screen

Device.test.js

Source:Device.test.js Github

copy

Full Screen

...55 }56 expectReverseTcpPortCalled(deviceId, port) {57 expect(this.driver.reverseTcpPort).toHaveBeenCalledWith(deviceId, port);58 }59 expectUnreverseTcpPortCalled(deviceId, port) {60 expect(this.driver.unreverseTcpPort).toHaveBeenCalledWith(deviceId, port);61 }62 }63 function schemeDevice(scheme, configuration) {64 const device = new Device({65 deviceConfig: scheme.configurations[configuration],66 deviceDriver: driverMock.driver,67 sessionConfig: scheme.session,68 });69 device.deviceDriver.acquireFreeDevice.mockReturnValue('mockDeviceId');70 return device;71 }72 function validDevice() {73 return schemeDevice(validScheme, 'ios.sim.release');74 }75 it('should return the name from the driver', async () => {76 driverMock.driver.name = 'mock-device-name-from-driver';77 const device = validDevice();78 expect(device.name).toEqual('mock-device-name-from-driver');79 });80 it('should return an undefined ID for an unprepared device', async() => {81 const device = validDevice();82 expect(device.id).toBeUndefined();83 });84 it('should return the device ID, as provided by acquireFreeDevice', async () => {85 const device = validDevice();86 await device.prepare();87 expect(device.id).toEqual('mockDeviceId');88 });89 describe('prepare()', () => {90 it(`valid scheme, no binary, should throw`, async () => {91 const device = validDevice();92 fs.existsSync.mockReturnValue(false);93 try {94 await device.prepare();95 fail('should throw')96 } catch (ex) {97 expect(ex.message).toMatch(/app binary not found at/)98 }99 });100 it(`valid scheme, no binary, should not throw`, async () => {101 const device = validDevice();102 await device.prepare();103 });104 it(`when reuse is enabled in CLI args should not uninstall and install`, async () => {105 const device = validDevice();106 argparse.getArgValue.mockReturnValue(true);107 await device.prepare();108 expect(driverMock.driver.uninstallApp).not.toHaveBeenCalled();109 expect(driverMock.driver.installApp).not.toHaveBeenCalled();110 });111 it(`when reuse is enabled in params should not uninstall and install`, async () => {112 const device = validDevice();113 await device.prepare({reuse: true});114 expect(driverMock.driver.uninstallApp).not.toHaveBeenCalled();115 expect(driverMock.driver.installApp).not.toHaveBeenCalled();116 });117 });118 describe('re/launchApp()', () => {119 const expectedDriverArgs = {120 "detoxServer": "ws://localhost:8099",121 "detoxSessionId": "test",122 };123 it(`with no args should launch app with defaults`, async () => {124 const expectedArgs = expectedDriverArgs;125 const device = validDevice();126 await device.launchApp();127 driverMock.expectLaunchCalled(device, expectedArgs);128 });129 it(`(relaunch) with no args should use defaults`, async () => {130 const expectedArgs = expectedDriverArgs;131 const device = validDevice();132 await device.relaunchApp();133 driverMock.expectLaunchCalled(device, expectedArgs);134 });135 it(`(relaunch) with no args should terminate the app before launch - backwards compat`, async () => {136 const device = validDevice();137 await device.relaunchApp();138 driverMock.expectTerminateCalled();139 });140 it(`(relaunch) with newInstance=false should not terminate the app before launch`, async () => {141 const device = validDevice();142 await device.relaunchApp({newInstance: false});143 driverMock.expectTerminateNotCalled();144 });145 it(`(relaunch) with newInstance=true should terminate the app before launch`, async () => {146 const device = validDevice();147 await device.relaunchApp({newInstance: true});148 driverMock.expectTerminateCalled();149 });150 it(`(relaunch) with delete=true`, async () => {151 const expectedArgs = expectedDriverArgs;152 const device = validDevice();153 await device.relaunchApp({delete: true});154 driverMock.expectReinstallCalled();155 driverMock.expectLaunchCalled(device, expectedArgs);156 });157 it(`(relaunch) with delete=false when reuse is enabled should not uninstall and install`, async () => {158 const expectedArgs = expectedDriverArgs;159 const device = validDevice();160 argparse.getArgValue.mockReturnValue(true);161 await device.relaunchApp();162 driverMock.expectReinstallNotCalled();163 driverMock.expectLaunchCalled(device, expectedArgs);164 });165 it(`(relaunch) with url should send the url as a param in launchParams`, async () => {166 const expectedArgs = {...expectedDriverArgs, "detoxURLOverride": "scheme://some.url"};167 const device = await validDevice();168 await device.relaunchApp({url: `scheme://some.url`});169 driverMock.expectLaunchCalled(device, expectedArgs);170 });171 it(`(relaunch) with url should send the url as a param in launchParams`, async () => {172 const expectedArgs = {173 ...expectedDriverArgs,174 "detoxURLOverride": "scheme://some.url",175 "detoxSourceAppOverride": "sourceAppBundleId",176 };177 const device = await validDevice();178 await device.relaunchApp({url: `scheme://some.url`, sourceApp: 'sourceAppBundleId'});179 driverMock.expectLaunchCalled(device, expectedArgs);180 });181 it(`(relaunch) with userNofitication should send the userNotification as a param in launchParams`, async () => {182 const expectedArgs = {183 ...expectedDriverArgs,184 "detoxUserNotificationDataURL": "url",185 };186 const device = validDevice();187 device.deviceDriver.createPayloadFile = jest.fn(() => 'url');188 await device.relaunchApp({userNotification: 'json'});189 driverMock.expectLaunchCalled(device, expectedArgs);190 });191 it(`(relaunch) with url and userNofitication should throw`, async () => {192 const device = validDevice();193 try {194 await device.relaunchApp({url: "scheme://some.url", userNotification: 'notif'});195 fail('should fail');196 } catch (ex) {197 expect(ex).toBeDefined();198 }199 });200 it(`(relaunch) with permissions should send trigger setpermissions before app starts`, async () => {201 const device = await validDevice();202 await device.relaunchApp({permissions: {calendar: "YES"}});203 expect(driverMock.driver.setPermissions).toHaveBeenCalledWith(device._deviceId, device._bundleId, {calendar: "YES"});204 });205 it('with languageAndLocale should launch app with a specific language/locale', async () => {206 const expectedArgs = expectedDriverArgs;207 const device = validDevice();208 const languageAndLocale = {209 language: 'es-MX',210 locale: 'es-MX'211 };212 await device.launchApp({languageAndLocale});213 driverMock.expectLaunchCalled(device, expectedArgs, languageAndLocale);214 });215 it(`with disableTouchIndicators should send a boolean switch as a param in launchParams`, async () => {216 const expectedArgs = {...expectedDriverArgs, "detoxDisableTouchIndicators": true};217 const device = await validDevice();218 await device.launchApp({disableTouchIndicators: true});219 driverMock.expectLaunchCalled(device, expectedArgs);220 });221 it(`with custom launchArgs should pass to native as launch args`, async () => {222 const launchArgs = {223 arg1: "1",224 arg2: 2,225 };226 const expectedArgs = {227 "detoxServer": "ws://localhost:8099",228 "detoxSessionId": "test",229 "arg1": "1",230 "arg2": 2,231 };232 const device = validDevice();233 await device.launchApp({launchArgs});234 driverMock.expectLaunchCalled(device, expectedArgs);235 });236 it(`with newInstance=false should check if process is in background and reopen it`, async () => {237 const processId = 1;238 const device = validDevice();239 device.deviceDriver.getBundleIdFromBinary.mockReturnValue('test.bundle');240 device.deviceDriver.launchApp.mockReturnValue(processId);241 await device.prepare({launchApp: true});242 await device.launchApp({newInstance: false});243 expect(driverMock.driver.deliverPayload).not.toHaveBeenCalled();244 });245 it(`with a url should check if process is in background and use openURL() instead of launch args`, async () => {246 const processId = 1;247 const device = validDevice();248 device.deviceDriver.getBundleIdFromBinary.mockReturnValue('test.bundle');249 device.deviceDriver.launchApp.mockReturnValue(processId);250 await device.prepare({launchApp: true});251 await device.launchApp({url: 'url://me'});252 expect(driverMock.driver.deliverPayload).toHaveBeenCalledTimes(1);253 });254 it(`with a url should check if process is in background and if not use launch args`, async () => {255 const launchParams = {url: 'url://me'};256 const processId = 1;257 const newProcessId = 2;258 const device = validDevice();259 device.deviceDriver.getBundleIdFromBinary.mockReturnValue('test.bundle');260 device.deviceDriver.launchApp.mockReturnValueOnce(processId).mockReturnValueOnce(newProcessId);261 await device.prepare();262 await device.launchApp(launchParams);263 expect(driverMock.driver.deliverPayload).not.toHaveBeenCalled();264 });265 it(`with a url should check if process is in background and use openURL() instead of launch args`, async () => {266 const launchParams = {url: 'url://me'};267 const processId = 1;268 const device = validDevice();269 device.deviceDriver.getBundleIdFromBinary.mockReturnValue('test.bundle');270 device.deviceDriver.launchApp.mockReturnValue(processId);271 await device.prepare({launchApp: true});272 await device.launchApp(launchParams);273 expect(driverMock.driver.deliverPayload).toHaveBeenCalledWith({delayPayload: true, url: 'url://me'});274 });275 it(`should keep user params unmodified`, async () => {276 const params = {277 url: 'some.url',278 launchArgs: {279 some: 'userArg',280 }281 };282 const paramsClone = _.cloneDeep(params);283 const device = validDevice();284 await device.launchApp(params);285 expect(params).toEqual(paramsClone);286 });287 it('with userActivity should check if process is in background and if it is use deliverPayload', async () => {288 const launchParams = {userActivity: 'userActivity'};289 const processId = 1;290 const device = validDevice();291 device.deviceDriver.getBundleIdFromBinary.mockReturnValue('test.bundle');292 device.deviceDriver.launchApp.mockReturnValueOnce(processId).mockReturnValueOnce(processId);293 device.deviceDriver.createPayloadFile = () => 'url';294 await device.prepare({launchApp: true});295 await device.launchApp(launchParams);296 expect(driverMock.driver.deliverPayload).toHaveBeenCalledWith({delayPayload: true, detoxUserActivityDataURL: 'url'});297 });298 it('with userNotification should check if process is in background and if it is use deliverPayload', async () => {299 const launchParams = {userNotification: 'notification'};300 const processId = 1;301 const device = validDevice();302 device.deviceDriver.getBundleIdFromBinary.mockReturnValue('test.bundle');303 device.deviceDriver.launchApp.mockReturnValueOnce(processId).mockReturnValueOnce(processId);304 device.deviceDriver.createPayloadFile = () => 'url';305 await device.prepare({launchApp: true});306 await device.launchApp(launchParams);307 expect(driverMock.driver.deliverPayload).toHaveBeenCalledTimes(1);308 });309 it(`with userNotification should check if process is in background and if not use launch args`, async () => {310 const launchParams = {userNotification: 'notification'};311 const processId = 1;312 const newProcessId = 2;313 const device = validDevice();314 device.deviceDriver.getBundleIdFromBinary.mockReturnValue('test.bundle');315 device.deviceDriver.launchApp.mockReturnValueOnce(processId).mockReturnValueOnce(newProcessId);316 await device.prepare();317 await device.launchApp(launchParams);318 expect(driverMock.driver.deliverPayload).not.toHaveBeenCalled();319 });320 it(`with userNotification and url should fail`, async () => {321 const launchParams = {userNotification: 'notification', url: 'url://me'};322 const processId = 1;323 driverMock.driver.getBundleIdFromBinary.mockReturnValue('test.bundle');324 driverMock.driver.launchApp.mockReturnValueOnce(processId).mockReturnValueOnce(processId);325 const device = validDevice();326 await device.prepare();327 try {328 await device.launchApp(launchParams);329 fail('should throw');330 } catch (ex) {331 expect(ex).toBeDefined();332 }333 expect(device.deviceDriver.deliverPayload).not.toHaveBeenCalled();334 });335 });336 describe('installApp()', () => {337 it(`with a custom app path should use custom app path`, async () => {338 const device = validDevice();339 await device.installApp('newAppPath');340 expect(driverMock.driver.installApp).toHaveBeenCalledWith(device._deviceId, 'newAppPath', undefined);341 });342 it(`with a custom test app path should use custom test app path`, async () => {343 const device = validDevice();344 await device.installApp('newAppPath', 'newTestAppPath');345 expect(driverMock.driver.installApp).toHaveBeenCalledWith(device._deviceId, 'newAppPath', 'newTestAppPath');346 });347 it(`with no args should use the default path given in configuration`, async () => {348 const device = validDevice();349 await device.installApp();350 expect(driverMock.driver.installApp).toHaveBeenCalledWith(device._deviceId, device._binaryPath, device._testBinaryPath);351 });352 });353 describe('uninstallApp()', () => {354 it(`with a custom app path should use custom app path`, async () => {355 const device = validDevice();356 await device.uninstallApp('newBundleId');357 expect(driverMock.driver.uninstallApp).toHaveBeenCalledWith(device._deviceId, 'newBundleId');358 });359 it(`with no args should use the default path given in configuration`, async () => {360 const device = validDevice();361 await device.uninstallApp();362 expect(driverMock.driver.uninstallApp).toHaveBeenCalledWith(device._deviceId, device._binaryPath);363 });364 });365 it(`sendToHome() should pass to device driver`, async () => {366 const device = validDevice();367 await device.sendToHome();368 expect(driverMock.driver.sendToHome).toHaveBeenCalledTimes(1);369 });370 it(`setBiometricEnrollment(true) should pass YES to device driver`, async () => {371 const device = validDevice();372 await device.setBiometricEnrollment(true);373 expect(driverMock.driver.setBiometricEnrollment).toHaveBeenCalledWith(device._deviceId, 'YES');374 expect(driverMock.driver.setBiometricEnrollment).toHaveBeenCalledTimes(1);375 });376 it(`setBiometricEnrollment(false) should pass NO to device driver`, async () => {377 const device = validDevice();378 await device.setBiometricEnrollment(false);379 expect(driverMock.driver.setBiometricEnrollment).toHaveBeenCalledWith(device._deviceId, 'NO');380 expect(driverMock.driver.setBiometricEnrollment).toHaveBeenCalledTimes(1);381 });382 it(`matchFace() should pass to device driver`, async () => {383 const device = validDevice();384 await device.matchFace();385 expect(driverMock.driver.matchFace).toHaveBeenCalledTimes(1);386 });387 it(`unmatchFace() should pass to device driver`, async () => {388 const device = validDevice();389 await device.unmatchFace();390 expect(driverMock.driver.unmatchFace).toHaveBeenCalledTimes(1);391 });392 it(`matchFinger() should pass to device driver`, async () => {393 const device = validDevice();394 await device.matchFinger();395 expect(driverMock.driver.matchFinger).toHaveBeenCalledTimes(1);396 });397 it(`unmatchFinger() should pass to device driver`, async () => {398 const device = validDevice();399 await device.unmatchFinger();400 expect(driverMock.driver.unmatchFinger).toHaveBeenCalledTimes(1);401 });402 it(`setStatusBar() should pass to device driver`, async () => {403 const device = validDevice();404 const params = {};405 await device.setStatusBar(params);406 expect(driverMock.driver.setStatusBar).toHaveBeenCalledWith(device._deviceId, params);407 });408 it(`resetStatusBar() should pass to device driver`, async () => {409 const device = validDevice();410 await device.resetStatusBar();411 expect(driverMock.driver.resetStatusBar).toHaveBeenCalledWith(device._deviceId);412 });413 it(`shake() should pass to device driver`, async () => {414 const device = validDevice();415 await device.shake();416 expect(driverMock.driver.shake).toHaveBeenCalledTimes(1);417 });418 it(`terminateApp() should pass to device driver`, async () => {419 const device = validDevice();420 await device.terminateApp();421 expect(driverMock.driver.terminate).toHaveBeenCalledTimes(1);422 });423 it(`shutdown() should pass to device driver`, async () => {424 const device = validDevice();425 await device.shutdown();426 expect(driverMock.driver.shutdown).toHaveBeenCalledTimes(1);427 });428 it(`openURL({url:url}) should pass to device driver`, async () => {429 const device = validDevice();430 await device.openURL({url: 'url'});431 expect(driverMock.driver.deliverPayload).toHaveBeenCalledWith({url: 'url'});432 });433 it(`openURL(notAnObject) should pass to device driver`, async () => {434 const device = validDevice();435 try {436 await device.openURL('url');437 fail('should throw');438 } catch (ex) {439 expect(ex).toBeDefined();440 }441 });442 it(`reloadReactNative() should pass to device driver`, async () => {443 const device = validDevice();444 await device.reloadReactNative();445 expect(driverMock.driver.reloadReactNative).toHaveBeenCalledTimes(1);446 });447 it(`setOrientation() should pass to device driver`, async () => {448 const device = validDevice();449 await device.setOrientation('param');450 expect(driverMock.driver.setOrientation).toHaveBeenCalledWith(device._deviceId, 'param');451 });452 it(`sendUserNotification() should pass to device driver`, async () => {453 const device = validDevice();454 await device.sendUserNotification('notif');455 expect(driverMock.driver.createPayloadFile).toHaveBeenCalledTimes(1);456 expect(driverMock.driver.deliverPayload).toHaveBeenCalledTimes(1);457 });458 it(`sendUserActivity() should pass to device driver`, async () => {459 const device = validDevice();460 await device.sendUserActivity('notif');461 expect(driverMock.driver.createPayloadFile).toHaveBeenCalledTimes(1);462 expect(driverMock.driver.deliverPayload).toHaveBeenCalledTimes(1);463 });464 it(`setLocation() should pass to device driver`, async () => {465 const device = validDevice();466 await device.setLocation(30.1, 30.2);467 expect(driverMock.driver.setLocation).toHaveBeenCalledWith(device._deviceId, '30.1', '30.2');468 });469 it(`reverseTcpPort should pass to device driver`, async () => {470 const device = validDevice();471 await device.reverseTcpPort(666);472 await driverMock.expectReverseTcpPortCalled(device._deviceId, 666);473 });474 it(`unreverseTcpPort should pass to device driver`, async () => {475 const device = validDevice();476 await device.unreverseTcpPort(777);477 await driverMock.expectUnreverseTcpPortCalled(device._deviceId, 777);478 });479 it(`setURLBlacklist() should pass to device driver`, async () => {480 const device = validDevice();481 await device.setURLBlacklist();482 expect(driverMock.driver.setURLBlacklist).toHaveBeenCalledTimes(1);483 });484 it(`enableSynchronization() should pass to device driver`, async () => {485 const device = validDevice();486 await device.enableSynchronization();487 expect(driverMock.driver.enableSynchronization).toHaveBeenCalledTimes(1);488 });489 it(`disableSynchronization() should pass to device driver`, async () => {490 const device = validDevice();491 await device.disableSynchronization();...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1root.expectUnreverseTcpPortCalled = function (port) {2}3root.expectUnreverseTcpPortCalled = function (port) {4}5root.expectUnreverseTcpPortCalled = function (port) {6}7root.expectUnreverseTcpPortCalled = function (port) {8}9root.expectUnreverseTcpPortCalled = function (port) {10}11root.expectUnreverseTcpPortCalled = function (port) {12}13root.expectUnreverseTcpPortCalled = function (port) {14}15root.expectUnreverseTcpPortCalled = function (port) {16}

Full Screen

Using AI Code Generation

copy

Full Screen

1expectUnreverseTcpPortCalled(1234);2expectUnreverseTcpPortCalled(1234);3expectUnreverseTcpPortCalled(1234);4expectUnreverseTcpPortCalled(1234);5expectUnreverseTcpPortCalled(1234);6expectUnreverseTcpPortCalled(1234);7expectUnreverseTcpPortCalled(1234);8expectUnreverseTcpPortCalled(1234);9expectUnreverseTcpPortCalled(1234);10expectUnreverseTcpPortCalled(1234);11expectUnreverseTcpPortCalled(1234);12expectUnreverseTcpPortCalled(1234);13expectUnreverseTcpPortCalled(123

Full Screen

Using AI Code Generation

copy

Full Screen

1expectUnreverseTcpPortCalled(8090, "localhost");2expectUnreverseTcpPortCalled(8090, "localhost");3expectUnreverseTcpPortCalled(8090, "localhost");4expectUnreverseTcpPortCalled(8090, "localhost");5expectUnreverseTcpPortCalled(8090, "localhost");6expectUnreverseTcpPortCalled(8090, "localhost");7expectUnreverseTcpPortCalled(8090, "localhost");8expectUnreverseTcpPortCalled(8090, "localhost");9expectUnreverseTcpPortCalled(8090, "localhost");10expectUnreverseTcpPortCalled(8090, "localhost");11expectUnreverseTcpPortCalled(8090, "localhost");12expectUnreverseTcpPortCalled(8090, "localhost");

Full Screen

Using AI Code Generation

copy

Full Screen

1var test = require('test');2test.setup();3var root = {};4var unreverseTcpPortCalled = false;5root.expectUnreverseTcpPortCalled = function() {6 unreverseTcpPortCalled = true;7};8var codeUnderTest = require('codeUnderTest');9codeUnderTest.doStuff(root);10assert.ok(unreverseTcpPortCalled);11test.run(console.DEBUG);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful