Skip to content

Commit

Permalink
Improve feature documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
d4vidi committed Jul 22, 2020
1 parent 8177a18 commit f3a6ceb
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions docs/APIRef.ActionsOnElement.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,21 +244,32 @@ jestExpect(multipleMatchedElements.elements[0].identifier).toBe('FirstElement');

### `takeScreenshot()` Android Only

Take a screenshot of the native view associated with the element in question. Useful for highly-focused visual comparison tests (i.e. comparison between elements rather than a whole screen).
Take a screenshot of the native view associated with the element in question. Useful for highly-focused visual comparison tests (i.e. comparison between elements rather than of complete screen, with visual "noise").

Returns the path of a temporary file containing the resulted `.png` image.

```js
const bitmapPath = await element(by.id('fancy-element')).takeScreenshot();
```

A typical use case of this API is like so (i.e. taking a screenshot and saving the resulted image once, then keeping it as a snapshot of the expected result):

```js
const fs = require('fs');
const bitmapBuffer = fs.readFileSync(bitmapPath);
const bitmapBuffer = fs.readFileSync(bitmapPath); // bitmapPath: see above
const snapshottedBitmapBuffer = fs.readFileSync(snapshottedBitmapPath);
if (!bitmapBuffer.equals(expectedBitmapBuffer)) {
throw new Error('Bitmaps differ!');
}
```

> A more useful way of doing this is by utilizing more advanced 3rd-party image snapshotting and comparison tools such as [applitools](https://applitools.com).
Caveats:

* Currently, the image-file generated by Detox is stored in a temporary folder, and does not get automatically cleaned-up.
* The image-file does not get exported as a test artifact in the test's finalization (i.e. such as with [device.takeScreenshot(name)](https://github.com/wix/Detox/blob/master/docs/APIRef.DeviceObjectAPI.md#devicetakescreenshotname)).

## Deprecated Methods

- [`.tapAtPoint()`](#tapatpointpoint)
Expand Down

0 comments on commit f3a6ceb

Please sign in to comment.