Skip to content

Commit

Permalink
Merge pull request #217 from formatlos/device-resetContentAndSettings
Browse files Browse the repository at this point in the history
device: add `resetContentAndSettings`
  • Loading branch information
rotemmiz authored Aug 15, 2017
2 parents 4fc20bb + f3100c6 commit 4814bac
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 1 deletion.
4 changes: 4 additions & 0 deletions detox/src/devices/Device.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ class Device {
await this.deviceDriver.disableSynchronization();
}

async resetContentAndSettings() {
await this.deviceDriver.resetContentAndSettings(this._deviceId);
}

getPlatform() {
return this.deviceDriver.getPlatform(this._deviceId);
}
Expand Down
7 changes: 7 additions & 0 deletions detox/src/devices/Device.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,13 @@ describe('Device', () => {
expect(device.deviceDriver.disableSynchronization).toHaveBeenCalledTimes(1);
});

it(`resetContentAndSettings() should pass to device driver`, async () => {
device = validDevice();
await device.resetContentAndSettings();

expect(device.deviceDriver.resetContentAndSettings).toHaveBeenCalledTimes(1);
});

it(`getPlatform() should pass to device driver`, async () => {
device = validDevice();
device.getPlatform();
Expand Down
4 changes: 4 additions & 0 deletions detox/src/devices/DeviceDriverBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ class DeviceDriverBase {
return await Promise.resolve('');
}

async resetContentAndSettings() {
return await Promise.resolve('');
}

defaultLaunchArgsPrefix() {
return '';
}
Expand Down
8 changes: 8 additions & 0 deletions detox/src/devices/Fbsimctl.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ class Fbsimctl {
await this._execFbsimctlCommand(options);
}

async resetContentAndSettings(udid) {
await this.shutdown(udid);
const result = await exec.execWithRetriesAndLogs(`/usr/bin/xcrun simctl erase ${udid}`);
const resultCode = parseInt(result.stdout.trim().split(':')[1]);
await this.boot(udid);
return resultCode;
}

async _execFbsimctlCommand(options, statusLogs, retries, interval) {
const bin = `fbsimctl --json`;
return await exec.execWithRetriesAndLogs(bin, options, statusLogs, retries, interval);
Expand Down
11 changes: 11 additions & 0 deletions detox/src/devices/Fbsimctl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ describe('Fbsimctl', () => {
await validateFbsimctlisCalledOn(fbsimctl, async () => fbsimctl.setLocation(simUdid));
});

it(`resetContentAndSettings() - is triggering shutdown, exec and boot`, async() => {
fs.existsSync.mockReturnValue(true);
exec.mockReturnValue({stdout: "appId: 22 \n"});
fbsimctl.shutdown = jest.fn();
fbsimctl.boot = jest.fn();
await fbsimctl.resetContentAndSettings(simUdid);
expect(fbsimctl.shutdown).toHaveBeenCalledTimes(1);
expect(exec).toHaveBeenCalledTimes(1);
expect(fbsimctl.boot).toHaveBeenCalledTimes(1);
});

it(`exec simulator command successfully`, async() => {
const result = returnSuccessfulWithValue("");
exec.mockReturnValue(Promise.resolve(result));
Expand Down
4 changes: 4 additions & 0 deletions detox/src/devices/SimulatorDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ class SimulatorDriver extends IosDriver {
await this._applesimutils.setPermissions(deviceId, bundleId, permissions);
}

async resetContentAndSettings(deviceId) {
return await this._fbsimctl.resetContentAndSettings(deviceId);
}

validateDeviceConfig(deviceConfig) {
if (!deviceConfig.binaryPath) {
configuration.throwOnEmptyBinaryPath();
Expand Down
9 changes: 9 additions & 0 deletions detox/test/e2e/f-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ describe('Device', () => {
await expect(element(by.label('Hello!!!'))).toBeVisible();
});

it('resetContentAndSettings() + install() + relaunch() - should tap successfully', async () => {
await device.resetContentAndSettings();
await device.installApp();
await device.launchApp({ newInstance: true });
await element(by.label('Sanity')).tap();
await element(by.label('Say Hello')).tap();
await expect(element(by.label('Hello!!!'))).toBeVisible();
});

describe('device orientation', () => {
beforeEach(async() => {
await device.reloadReactNative();
Expand Down
12 changes: 11 additions & 1 deletion docs/APIRef.DeviceObjectAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- [`device.setURLBlacklist([urls])`](#deviceseturlblacklisturls)
- [`device.enableSynchronization()`](#deviceenablesynchronization)
- [`device.disableSynchronization()`](#devicedisablesynchronization)
- [`device.resetContentAndSettings()`](#resetcontentandsettings)

### `device.launchApp(params)`
Launch the app defined in the current [`configuration`](APIRef.Configuration.md).
Expand Down Expand Up @@ -190,4 +191,13 @@ Disable [EarlGrey's synchronization mechanism](https://github.com/google/EarlGre

```js
await device.disableSynchronization();
```
```


### `device.resetContentAndSettings()`
Resets the Simulator to clean state (like the Simulator > Reset Content and Settings... menu item), especially removing
previously set permissions.

```js
await device.resetContentAndSettings();
```

0 comments on commit 4814bac

Please sign in to comment.