How to use aValidDevice method in root

Best JavaScript code snippet using root

RuntimeDevice.test.js

Source:RuntimeDevice.test.js Github

copy

Full Screen

...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();689 expect(driverMock.driver.disableSynchronization).toHaveBeenCalledTimes(1);690 });691 it(`resetContentAndSettings() should pass to device driver`, async () => {692 const device = await aValidDevice();693 await device.resetContentAndSettings();694 expect(driverMock.driver.resetContentAndSettings).toHaveBeenCalledTimes(1);695 });696 it(`getPlatform() should pass to device driver`, async () => {697 const device = await aValidDevice();698 device.getPlatform();699 expect(driverMock.driver.getPlatform).toHaveBeenCalledTimes(1);700 });701 it(`_cleanup() should pass to device driver`, async () => {702 const device = await aValidDevice();703 await device._cleanup();704 expect(driverMock.driver.cleanup).toHaveBeenCalledTimes(1);705 });706 it(`should accept absolute path for binary`, async () => {707 const actualPath = await launchAndTestBinaryPath('absolute');708 expect(actualPath).toEqual(configurationsMock.appWithAbsoluteBinaryPath.binaryPath);709 });710 it(`should accept relative path for binary`, async () => {711 const actualPath = await launchAndTestBinaryPath('relative');712 expect(actualPath).toEqual(configurationsMock.appWithRelativeBinaryPath.binaryPath);713 });714 it(`pressBack() should invoke driver's pressBack()`, async () => {715 const device = await aValidDevice();716 await device.pressBack();717 expect(driverMock.driver.pressBack).toHaveBeenCalledWith();718 });719 it(`clearKeychain() should invoke driver's clearKeychain()`, async () => {720 const device = await aValidDevice();721 await device.clearKeychain();722 expect(driverMock.driver.clearKeychain).toHaveBeenCalledWith();723 });724 describe('get ui device', () => {725 it(`getUiDevice should invoke driver's getUiDevice`, async () => {726 const device = await aValidDevice();727 await device.getUiDevice();728 expect(driverMock.driver.getUiDevice).toHaveBeenCalled();729 });730 it('should call return UiDevice when call getUiDevice', async () => {731 const uiDevice = {732 uidevice: true,733 };734 const device = await aValidDevice();735 driverMock.driver.getUiDevice = () => uiDevice;736 const result = await device.getUiDevice();737 expect(result).toEqual(uiDevice);738 });739 });740 it('takeScreenshot(name) should throw an exception if given name is empty', async () => {741 await expect((await aValidDevice()).takeScreenshot()).rejects.toThrowError(/empty name/);742 });743 it('takeScreenshot(name) should delegate the work to the driver', async () => {744 const device = await aValidDevice();745 await device.takeScreenshot('name');746 expect(device.deviceDriver.takeScreenshot).toHaveBeenCalledWith('name');747 });748 it('captureViewHierarchy(name) should delegate the work to the driver', async () => {749 const device = await aValidDevice();750 await device.captureViewHierarchy('name');751 expect(device.deviceDriver.captureViewHierarchy).toHaveBeenCalledWith('name');752 });753 it('captureViewHierarchy([name]) should set name = "capture" by default', async () => {754 const device = await aValidDevice();755 await device.captureViewHierarchy();756 expect(device.deviceDriver.captureViewHierarchy).toHaveBeenCalledWith('capture');757 });758 describe('_isAppRunning (internal method)', () => {759 let device;760 beforeEach(async () => {761 device = await aValidDevice();762 driverMock.driver.launchApp = async () => 42;763 await device.launchApp();764 });765 it('should return the value for the current app if called with no args', async () => {766 expect(device._isAppRunning()).toBe(true);767 });768 it('should return the value for the given bundleId', async () => {769 expect(device._isAppRunning('test.bundle')).toBe(true);770 expect(device._isAppRunning('somethingElse')).toBe(false);771 });772 });773 async function launchAndTestBinaryPath(absoluteOrRelative) {774 const appConfig = absoluteOrRelative === 'absolute'775 ? configurationsMock.appWithAbsoluteBinaryPath776 : configurationsMock.appWithRelativeBinaryPath;777 const device = await aValidDevice({ appsConfig: { default: appConfig } });778 await device.installApp();779 return driverMock.driver.installApp.mock.calls[0][0];780 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var root = require('root');2var aValidDevice = root.aValidDevice;3module.exports.aValidDevice = function (device) {4}5var root = require('root');6var aValidDevice = root.aValidDevice;7module.exports.aValidDevice = function (device) {8}9var root = require('root');10var aValidDevice = root.aValidDevice;11module.exports.aValidDevice = function (device) {12}13var root = require('root');14var aValidDevice = root.aValidDevice;15module.exports.aValidDevice = function (device) {16}17var root = require('root');18var aValidDevice = root.aValidDevice;19module.exports.aValidDevice = function (device) {20}21var root = require('root');22var aValidDevice = root.aValidDevice;23module.exports.aValidDevice = function (device) {24}

Full Screen

Using AI Code Generation

copy

Full Screen

1var root = require('./root');2root.aValidDevice();3var aValidDevice = function(){4 console.log('aValidDevice called');5}6module.exports.aValidDevice = aValidDevice;

Full Screen

Using AI Code Generation

copy

Full Screen

1var root = require('./root.js');2root.aValidDevice("Dell");3exports.aValidDevice = function(device){4 console.log("Valid Device: " + device);5}6var root = require('./root.js');7module.exports.aValidDevice = function(device){8 console.log("Valid Device: " + device);9}

Full Screen

Using AI Code Generation

copy

Full Screen

1var root = require('Root');2var device = root.aValidDevice("aValidDeviceName");3device.aMethodOfDevice();4var device = require('Device');5module.exports = {6 aValidDevice: function (name) {7 return new device(name);8 }9}10module.exports = function (name) {11 this.name = name;12 this.aMethodOfDevice = function () {13 console.log("aMethodOfDevice called on device " + this.name);14 }15}16var root = require('Root');17var device = root.aValidDevice("aValidDeviceName");18device.aMethodOfDevice();19var device = require('Device');20module.exports = {21 aValidDevice: function (name) {22 return new device(name);23 }24}25module.exports = function (name) {26 this.name = name;27 this.aMethodOfDevice = function () {28 console.log("aMethodOfDevice called on device " + this.name);29 }30}31var root = require('Root');32var device = root.aValidDevice("aValidDeviceName");33device.aMethodOfDevice();34var device = require('Device');35module.exports = {36 aValidDevice: function (name) {37 return new device(name);38 }39}40module.exports = function (name) {41 this.name = name;42 this.aMethodOfDevice = function () {43 console.log("aMethodOfDevice called on device " + this.name);44 }45}46var root = require('Root');47var device = root.aValidDevice("aValidDeviceName");48device.aMethodOfDevice();

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