-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
26.element-screenshots.test.js
33 lines (25 loc) · 1.27 KB
/
26.element-screenshots.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const fs = require('fs');
describe('Element screenshots', () => {
beforeEach(async () => {
await device.reloadReactNative();
await element(by.text('Element-Screenshots')).tap();
});
it('should take a screenshot of a vertically-clipped element', async () => {
const screenshotAssetPath = `./e2e/assets/elementScreenshot.${device.getPlatform()}.vert.png`;
const bitmapPath = await element(by.id('fancyElement')).takeScreenshot();
expectBitmapsToBeEqual(bitmapPath, screenshotAssetPath);
});
it('should take a screenshot of a horizontally-clipped element', async () => {
const screenshotAssetPath = `./e2e/assets/elementScreenshot.${device.getPlatform()}.horiz.png`;
await element(by.id('switchOrientation')).tap();
const bitmapPath = await element(by.id('fancyElement')).takeScreenshot('fancy-element');
expectBitmapsToBeEqual(bitmapPath, screenshotAssetPath);
});
function expectBitmapsToBeEqual(bitmapPath, expectedBitmapPath) {
const bitmapBuffer = fs.readFileSync(bitmapPath);
const expectedBitmapBuffer = fs.readFileSync(expectedBitmapPath);
if (!bitmapBuffer.equals(expectedBitmapBuffer)) {
throw new Error(`Expected bitmap at ${bitmapPath} to be equal to ${expectedBitmapPath}, but it is different!`);
}
}
});