forked from DevExpress/testcafe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
655 lines (576 loc) · 31.8 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
const path = require('path');
const fs = require('fs');
const chai = require('chai');
const { expect } = chai;
const config = require('../../../../config.js');
const assertionHelper = require('../../../../assertion-helper.js');
chai.use(require('chai-string'));
const SCREENSHOTS_PATH = path.resolve(assertionHelper.SCREENSHOTS_PATH);
const THUMBNAILS_DIR_NAME = assertionHelper.THUMBNAILS_DIR_NAME;
const SCREENSHOT_PATH_MESSAGE_RE = /___test-screenshots___[\\/]\d{4,4}-\d{2,2}-\d{2,2}_\d{2,2}-\d{2,2}-\d{2,2}[\\/]test-1/;
const SCREENSHOT_ON_FAIL_PATH_MESSAGE_RE = /^.*run-1/;
const SLASH_RE = /[\\/]/g;
const getReporter = function (scope) {
const userAgents = { };
function patchScreenshotPath (screenshotPath) {
return screenshotPath.replace(SCREENSHOT_ON_FAIL_PATH_MESSAGE_RE, '').replace(SCREENSHOTS_PATH, '').replace(SLASH_RE, '_');
}
function prepareScreenshot (screenshot, quarantine) {
screenshot.screenshotPath = patchScreenshotPath(screenshot.screenshotPath);
screenshot.thumbnailPath = patchScreenshotPath(screenshot.thumbnailPath);
screenshot.isPassedAttempt = quarantine[screenshot.quarantineAttempt].passed;
screenshot.testRunId = scope.testRunIds.includes(screenshot.testRunId);
userAgents[screenshot.userAgent] = true;
}
return function () {
return {
reportTestDone: (name, testRunInfo) => {
testRunInfo.screenshots.forEach(screenshot => prepareScreenshot(screenshot, testRunInfo.quarantine));
scope.screenshots = testRunInfo.screenshots;
scope.userAgents = Object.keys(userAgents);
scope.unstable = testRunInfo.unstable;
},
reportTestStart: (name, meta, { testRunIds }) => {
scope.testRunIds = testRunIds;
},
reportFixtureStart: () => {
},
reportTaskStart: () => {
},
reportTaskDone: () => {
}
};
};
};
describe('[API] t.takeScreenshot()', function () {
afterEach(assertionHelper.removeScreenshotDir);
if (config.useLocalBrowsers && config.currentEnvironmentName !== config.testingEnvironmentNames.localBrowsersIE) {
it('Should take a screenshot', function () {
return runTests('./testcafe-fixtures/take-screenshot.js', 'Take a screenshot', { setScreenshotPath: true })
.then(function () {
expect(SCREENSHOT_PATH_MESSAGE_RE.test(testReport.screenshotPath)).eql(true);
expect(assertionHelper.checkScreenshotsCreated({ forError: false, screenshotsCount: 4 })).eql(true);
});
});
it('Should take a screenshot with a custom path (OS separator)', function () {
return runTests('./testcafe-fixtures/take-screenshot.js', 'Take a screenshot with a custom path (OS separator)',
{ setScreenshotPath: true })
.then(function () {
expect(testReport.screenshotPath).startsWith(path.join(SCREENSHOTS_PATH, 'custom'));
const screenshotsCheckingOptions = { forError: false, screenshotsCount: 2, customPath: 'custom' };
expect(assertionHelper.checkScreenshotsCreated(screenshotsCheckingOptions)).eql(true);
});
});
it('Should take a screenshot with a custom path (DOS separator)', function () {
return runTests('./testcafe-fixtures/take-screenshot.js', 'Take a screenshot with a custom path (DOS separator)',
{ setScreenshotPath: true })
.then(function () {
expect(testReport.screenshotPath).contains(SCREENSHOTS_PATH);
const screenshotsCheckingOptions = { forError: false, screenshotsCount: 2, customPath: 'custom' };
expect(assertionHelper.checkScreenshotsCreated(screenshotsCheckingOptions)).eql(true);
});
});
it('Should save screenshots to default dir if screenshotPath is not specified', function () {
return runTests('./testcafe-fixtures/take-screenshot.js', 'Take a screenshot')
.then(function () {
expect(assertionHelper.checkScreenshotsCreated({ baseDir: 'screenshots', screenshotsCount: 4 })).eql(true);
return assertionHelper.removeScreenshotDir('screenshots');
});
});
it('Should save screenshots to default dir with custom path specified', function () {
return runTests('./testcafe-fixtures/take-screenshot.js', 'Take a screenshot with a custom path (OS separator)')
.then(function () {
expect(assertionHelper.checkScreenshotsCreated({ baseDir: 'screenshots', customPath: 'custom' })).eql(true);
return assertionHelper.removeScreenshotDir('screenshots');
});
});
it('Should create warning if screenshots are disabled', function () {
return runTests('./testcafe-fixtures/take-screenshot.js', 'Take a screenshot', { disableScreenshots: true })
.then(function () {
expect(assertionHelper.isScreenshotDirExists()).eql(false);
expect(testReport.warnings).eql([
'Screenshots are disabled. To take screenshots, remove the "--disable-screenshots" command line flag ' +
'or set the "disableScreenshots" option to "false" in the API or configuration file.'
]);
});
});
it('Should create warning if screenshots are disabled when a custom path is specified', function () {
return runTests('./testcafe-fixtures/take-screenshot.js', 'Take a screenshot with a custom path (OS separator)', { disableScreenshots: true })
.then(function () {
expect(assertionHelper.isScreenshotDirExists()).eql(false);
expect(testReport.warnings).eql([
'Screenshots are disabled. To take screenshots, remove the "--disable-screenshots" command line flag ' +
'or set the "disableScreenshots" option to "false" in the API or configuration file.'
]);
});
});
it('Should validate path argument', function () {
return runTests('./testcafe-fixtures/take-screenshot.js', 'Incorrect action path argument', {
shouldFail: true,
only: 'chrome'
})
.catch(function (errs) {
expect(errs[0]).to.contains('The "path" argument is expected to be a non-empty string, but it was number.');
expect(errs[0]).to.contains(
'38 |test(\'Incorrect action path argument\', async t => {' +
' > 39 | await t.takeScreenshot(1); ' +
'40 |});'
);
});
});
it('Should check the path argument for forbidden characters', function () {
return runTests('./testcafe-fixtures/take-screenshot.js', 'Forbidden characters in the path argument', {
shouldFail: true,
only: 'chrome'
})
.catch(function (errs) {
expect(errs[0]).to.contains('There are forbidden characters in the "path:with*forbidden|chars" screenshot path: ":" at index 4 "*" at index 9 "|" at index 19');
expect(errs[0]).to.contains(
'42 |test(\'Forbidden characters in the path argument\', async t => {' +
' > 43 | await t.takeScreenshot(\'path:with*forbidden|chars\'); ' +
'44 |});'
);
});
});
it('Should take a screenshot in quarantine mode', function () {
return runTests('./testcafe-fixtures/take-screenshot.js', 'Take a screenshot in quarantine mode', {
setScreenshotPath: true,
quarantineMode: true
})
.catch(function () {
expect(SCREENSHOT_PATH_MESSAGE_RE.test(testReport.screenshotPath)).eql(true);
expect(testReport.unstable).eql(false);
const screenshotsCheckingOptions = { forError: false, screenshotsCount: 2, runDirCount: 3 };
expect(assertionHelper.checkScreenshotsCreated(screenshotsCheckingOptions)).eql(true);
});
});
it('Should throw warning when taking screenshots with same path', function () {
return runTests('./testcafe-fixtures/take-screenshot.js', 'Take screenshots with same path', {
setScreenshotPath: true
}).then(function () {
const screenshotFileName = path.join(SCREENSHOTS_PATH, '1.png');
expect(testReport.warnings).eql([
`The file at "${screenshotFileName}" already exists. It has just been rewritten ` +
'with a recent screenshot. This situation can possibly cause issues. To avoid them, make sure ' +
'that each screenshot has a unique path. If a test runs in multiple browsers, consider ' +
'including the user agent in the screenshot path or generate a unique identifier in another way.'
]);
});
});
it('Should crop screenshots to a page viewport area', function () {
return runTests('./testcafe-fixtures/take-screenshot.js', 'Should crop screenshots',
{ setScreenshotPath: true })
.then(function () {
return assertionHelper.checkScreenshotsCropped(false, 'custom');
})
.then(function (result) {
expect(result).eql(true);
});
});
it('Should crop scrollbars', function () {
return runTests('./testcafe-fixtures/take-screenshot.js', 'Should crop scrollbar',
{ setScreenshotPath: true });
});
it('Should provide screenshot log to a reporter', function () {
const result = {};
const reporter = getReporter(result);
return runTests('./testcafe-fixtures/take-screenshot.js', 'Take screenshots for reporter', {
setScreenshotPath: true,
quarantineMode: true,
screenshotsOnFails: true,
reporter: [ reporter ]
})
.then(function () {
const getScreenshotsInfo = (screenshotPath, thumbnailPath, attempt, userAgent, takenOnFail) => {
if (!takenOnFail) {
screenshotPath = '_' + userAgent + attempt + screenshotPath;
thumbnailPath = '_thumbnails' + screenshotPath;
}
return {
testRunId: true,
screenshotPath,
thumbnailPath,
takenOnFail,
quarantineAttempt: attempt,
isPassedAttempt: attempt > 1,
userAgent
};
};
const expected = result.userAgents.reduce(function (value, userAgent) {
for (let attempt = 1; attempt <= 4; attempt++) {
value.push(getScreenshotsInfo('1.png', null, attempt, userAgent, false));
value.push(getScreenshotsInfo('2.png', null, attempt, userAgent, false));
}
const errorScreenshotPath = '_' + userAgent + '_errors_1.png';
const errorThumbnailPath = '_' + userAgent + '_errors_thumbnails_1.png';
value.push(getScreenshotsInfo(errorScreenshotPath, errorThumbnailPath, 1, userAgent, true));
return value;
}, []);
expect(result.screenshots).deep.members(expected);
expect(result.unstable).eql(true);
});
});
it('Should allow to use a custom path pattern', function () {
return runTests('./testcafe-fixtures/take-screenshot.js', 'Take a screenshot',
{
setScreenshotPath: true,
screenshotPathPattern: '${TEST}-${FILE_INDEX}',
only: 'chrome'
})
.then(() => {
expect(testReport.screenshotPath).eql(SCREENSHOTS_PATH);
const screenshot1Path = path.join(assertionHelper.SCREENSHOTS_PATH, 'Take a screenshot-1.png');
const screenshot2Path = path.join(assertionHelper.SCREENSHOTS_PATH, 'Take a screenshot-2.png');
const thumbnail1Path = path.join(assertionHelper.SCREENSHOTS_PATH, THUMBNAILS_DIR_NAME, 'Take a screenshot-1.png');
const thumbnail2Path = path.join(assertionHelper.SCREENSHOTS_PATH, THUMBNAILS_DIR_NAME, 'Take a screenshot-2.png');
expect(fs.existsSync(screenshot1Path)).eql(true);
expect(fs.existsSync(screenshot2Path)).eql(true);
expect(fs.existsSync(thumbnail1Path)).eql(true);
expect(fs.existsSync(thumbnail2Path)).eql(true);
});
});
}
else if (!config.useLocalBrowsers) {
it('Should show a warning on an attempt to capture a screenshot for a remote browser', () => {
return runTests('./testcafe-fixtures/take-screenshot.js', 'Take a screenshot',
{ only: 'chrome', setScreenshotPath: true })
.then(() => {
expect(testReport.warnings).eql([
'The screenshot and window resize functionalities are not supported in a remote browser. ' +
'They can function only if the browser is running on the same machine and ' +
'in the same environment as the TestCafe server.'
]);
});
});
}
});
describe('[API] t.takeElementScreenshot()', function () {
afterEach(assertionHelper.removeScreenshotDir);
if (config.useLocalBrowsers && config.currentEnvironmentName !== config.testingEnvironmentNames.localBrowsersIE) {
it('Should take screenshot of an element', function () {
return runTests('./testcafe-fixtures/take-element-screenshot.js', 'Element',
{ setScreenshotPath: true })
.then(function () {
return assertionHelper.isScreenshotsEqual('custom', path.join(__dirname, './data/element.png'));
})
.then(function (result) {
expect(result).eql(true);
});
});
it('Should save screenshots to default dir with custom path specified', function () {
return runTests('./testcafe-fixtures/take-element-screenshot.js', 'Element')
.then(function () {
expect(assertionHelper.checkScreenshotsCreated({ baseDir: 'screenshots', customPath: 'custom' })).eql(true);
return assertionHelper.removeScreenshotDir('screenshots');
});
});
it('Should create warning if screenshots are disabled', function () {
return runTests('./testcafe-fixtures/take-element-screenshot.js', 'Element with margins', { disableScreenshots: true })
.then(function () {
expect(assertionHelper.isScreenshotDirExists()).eql(false);
expect(testReport.warnings).eql([
'Screenshots are disabled. To take screenshots, remove the "--disable-screenshots" command line flag ' +
'or set the "disableScreenshots" option to "false" in the API or configuration file.'
]);
});
});
it('Should validate selector argument', function () {
return runTests('./testcafe-fixtures/take-element-screenshot.js', 'Incorrect action selector argument', {
shouldFail: true,
only: 'chrome'
})
.catch(function (errs) {
expect(errs[0]).to.contains(
'Action "selector" argument error: Selector is expected to be initialized with a ' +
'function, CSS selector string, another Selector, node snapshot or a Promise returned ' +
'by a Selector, but number was passed.'
);
expect(errs[0]).to.contains(
' 29 |test(\'Incorrect action selector argument\', async t => {' +
' > 30 | await t.takeElementScreenshot(1, \'custom/\' + t.ctx.parsedUA.name + \'.png\');' +
' 31 |});'
);
});
});
it('Should validate path argument', function () {
return runTests('./testcafe-fixtures/take-element-screenshot.js', 'Incorrect action path argument', {
shouldFail: true,
only: 'chrome'
})
.catch(function (errs) {
expect(errs[0]).to.contains('The "path" argument is expected to be a non-empty string, but it was number.');
expect(errs[0]).to.contains(
' 33 |test(\'Incorrect action path argument\', async t => {' +
' > 34 | await t.takeElementScreenshot(\'table\', 1);' +
' 35 |});'
);
});
});
it('Should check the path argument for forbidden characters', function () {
return runTests('./testcafe-fixtures/take-element-screenshot.js', 'Forbidden characters in the path argument', {
shouldFail: true,
only: 'chrome'
})
.catch(function (errs) {
expect(errs[0]).to.contains('There are forbidden characters in the "path:with*forbidden|chars" screenshot path: ":" at index 4 "*" at index 9 "|" at index 19');
expect(errs[0]).to.contains(
'57 |test(\'Forbidden characters in the path argument\', async t => {' +
' > 58 | await t.takeElementScreenshot(\'table\', \'path:with*forbidden|chars\'); ' +
'59 |});'
);
});
});
it('Should take screenshot of an element with margins', function () {
return runTests('./testcafe-fixtures/take-element-screenshot.js', 'Element with margins',
{ setScreenshotPath: true })
.then(function () {
return assertionHelper.isScreenshotsEqual('custom', path.join(__dirname, './data/element-with-margins.png'));
})
.then(function (result) {
expect(result).eql(true);
});
});
it('Should perform top-left crop', function () {
return runTests('./testcafe-fixtures/take-element-screenshot.js', 'Top-left',
{ setScreenshotPath: true })
.then(function () {
return assertionHelper.isScreenshotsEqual('custom', path.join(__dirname, './data/top-left.png'));
})
.then(function (result) {
expect(result).eql(true);
});
});
it('Should perform top-left crop by default', function () {
return runTests('./testcafe-fixtures/take-element-screenshot.js', 'Default crop',
{ setScreenshotPath: true })
.then(function () {
return assertionHelper.isScreenshotsEqual('custom', path.join(__dirname, './data/top-left.png'));
})
.then(function (result) {
expect(result).eql(true);
});
});
it('Should perform top-right crop', function () {
return runTests('./testcafe-fixtures/take-element-screenshot.js', 'Top-right',
{ setScreenshotPath: true })
.then(function () {
return assertionHelper.isScreenshotsEqual('custom', path.join(__dirname, './data/top-right.png'));
})
.then(function (result) {
expect(result).eql(true);
});
});
it('Should perform bottom-left crop', function () {
return runTests('./testcafe-fixtures/take-element-screenshot.js', 'Bottom-left',
{ setScreenshotPath: true })
.then(function () {
return assertionHelper.isScreenshotsEqual('custom', path.join(__dirname, './data/bottom-left.png'));
})
.then(function (result) {
expect(result).eql(true);
});
});
it('Should perform bottom-right crop', function () {
return runTests('./testcafe-fixtures/take-element-screenshot.js', 'Bottom-right',
{ setScreenshotPath: true })
.then(function () {
return assertionHelper.isScreenshotsEqual('custom', path.join(__dirname, './data/bottom-right.png'));
})
.then(function (result) {
expect(result).eql(true);
});
});
it('Should throw an error if element dimensions are invalid', function () {
return runTests('./testcafe-fixtures/take-element-screenshot.js', 'Invalid dimensions', {
setScreenshotPath: true,
shouldFail: true,
only: 'chrome'
})
.catch(function (errs) {
const screenshotsCheckingOptions = { forError: false, screenshotsCount: 2, customPath: 'custom' };
expect(assertionHelper.checkScreenshotsCreated(screenshotsCheckingOptions)).eql(false);
expect(errs[0]).to.contains('Unable to capture an element image because the resulting image width is zero or negative.');
expect(errs[0]).to.contains(
' 37 |test(\'Invalid dimensions\', async t => {' +
' > 38 | await t.takeElementScreenshot(\'table\', \'custom/\' + t.ctx.parsedUA.name + \'.png\', { crop: { left: -10, right: -50 } });' +
' 39 |});'
);
});
});
it('Should throw an error if the element is invisible', function () {
return runTests('./testcafe-fixtures/take-element-screenshot.js', 'Invisible element', {
setScreenshotPath: true,
shouldFail: true,
only: 'chrome'
})
.catch(function (errs) {
expect(errs[0]).to.contains('The element that matches the specified selector is not visible.');
expect(errs[0]).to.contains(
' 43 | .click(\'#hide\')' +
' > 44 | .takeElementScreenshot(\'table\', \'custom/\' + t.ctx.parsedUA.name + \'.png\');' +
' 45 |});'
);
});
});
it('Should throw an error if the element doesn\'t exist', function () {
return runTests('./testcafe-fixtures/take-element-screenshot.js', 'Non-existent element', {
setScreenshotPath: true,
shouldFail: true,
only: 'chrome'
})
.catch(function (errs) {
expect(errs[0]).to.contains(
'The specified selector does not match any element in the DOM tree.' +
' > | Selector(\'table\')'
);
expect(errs[0]).to.contains(
' 49 | .click(\'#remove\')' +
' > 50 | .takeElementScreenshot(\'table\', \'custom/\' + t.ctx.parsedUA.name + \'.png\');' +
' 51 |});'
);
});
});
it('Should throw an error if the specified scroll target is out of the cropping region', function () {
return runTests('./testcafe-fixtures/take-element-screenshot.js', 'Invalid scroll target', {
setScreenshotPath: true,
shouldFail: true,
only: 'chrome'
})
.catch(function (errs) {
expect(errs[0]).to.contains('Unable to scroll to the specified point because a point ' +
'with the specified scrollTargetX and scrollTargetY properties ' +
'is not located inside the element\'s cropping region');
expect(errs[0]).to.contains(
' 53 |test(\'Invalid scroll target\', async t => {' +
' > 54 | await t.takeElementScreenshot(\'table\', \'custom/\' + t.ctx.parsedUA.name + \'.png\', { scrollTargetX: -2000, scrollTargetY: -3000 });' +
' 55 |});'
);
});
});
it('Should capture screenshot of the element inside a same-domain iframe', function () {
return runTests('./testcafe-fixtures/take-element-screenshot.js', 'Same-domain iframe',
{ setScreenshotPath: true })
.then(function () {
return assertionHelper.isScreenshotsEqual('custom', path.join(__dirname, './data/element.png'));
})
.then(function (result) {
expect(result).eql(true);
});
});
it('Should capture screenshot of the element inside a nested iframe', function () {
return runTests('./testcafe-fixtures/take-element-screenshot.js', 'Nested iframes',
{ setScreenshotPath: true })
.then(function () {
return assertionHelper.isScreenshotsEqual('custom', path.join(__dirname, './data/element.png'));
})
.then(function (result) {
expect(result).eql(true);
});
});
it('Should capture screenshot of the element inside a cross-domain iframe', function () {
return runTests('./testcafe-fixtures/take-element-screenshot.js', 'Cross-domain iframe',
{ setScreenshotPath: true })
.then(function () {
return assertionHelper.isScreenshotsEqual('custom', path.join(__dirname, './data/element.png'));
})
.then(function (result) {
expect(result).eql(true);
});
});
it("Shouldn't scroll parent frames multiple times", function () {
return runTests('./testcafe-fixtures/take-element-screenshot.js', 'Rescroll parents',
{ setScreenshotPath: true })
.then(function () {
return assertionHelper.isScreenshotsEqual('custom', path.join(__dirname, './data/element.png'));
})
.then(function (result) {
expect(result).eql(true);
});
});
it('Should scroll to the scroll target when positive scrollTargetX/Y are specified', function () {
return runTests('./testcafe-fixtures/take-element-screenshot.js', 'Scroll target',
{ setScreenshotPath: true })
.then(function () {
return assertionHelper.checkScreenshotIsNotWhite(false, 'custom');
})
.then(function (result) {
expect(result).eql(true);
});
});
it('Should scroll to the scroll target when negative scrollTargetX/Y are specified', function () {
return runTests('./testcafe-fixtures/take-element-screenshot.js', 'Negative scroll target',
{ setScreenshotPath: true })
.then(function () {
return assertionHelper.checkScreenshotIsNotWhite(false, 'custom');
})
.then(function (result) {
expect(result).eql(true);
});
});
it('Should remove screenshot mark from an element screenshot when the element is in bottom right corner', function () {
return runTests('./testcafe-fixtures/take-element-screenshot.js', 'Bottom-right element',
{ setScreenshotPath: true })
.then(function () {
function referenceImagePathGetter (screenshotPath) {
const referenceImageName = screenshotPath.match(/chrome|firefox/i) ? 'element' : 'element-bottom-right';
return path.join(__dirname, `./data/${referenceImageName}.png`);
}
return assertionHelper.isScreenshotsEqual('custom', referenceImagePathGetter);
})
.then(function (result) {
expect(result).eql(true);
});
});
}
else if (!config.useLocalBrowsers) {
it('Should show a warning on an attempt to capture an element screenshot for a remote browser', () => {
return runTests('./testcafe-fixtures/take-element-screenshot.js', 'Element',
{ only: 'chrome', setScreenshotPath: true })
.then(() => {
expect(testReport.warnings).eql([
'The screenshot and window resize functionalities are not supported in a remote browser. ' +
'They can function only if the browser is running on the same machine and ' +
'in the same environment as the TestCafe server.'
]);
});
});
}
});
describe('[API] Take full page screenshots', function () {
afterEach(assertionHelper.removeScreenshotDir);
if (config.useLocalBrowsers && config.useHeadlessBrowsers) {
it('Should take a full page screenshot via API', function () {
return runTests('./testcafe-fixtures/take-full-page-screenshot.js', 'API', { setScreenshotPath: true })
.then(function () {
return assertionHelper.checkScreenshotFileFullPage(false, 'custom');
})
.then(function (result) {
expect(result).eql(true);
});
});
it('Should take a full page screenshot via Runner', function () {
return runTests('./testcafe-fixtures/take-full-page-screenshot.js', 'Runner', {
setScreenshotPath: true,
screenshotsFullPage: true
})
.then(function () {
return assertionHelper.checkScreenshotFileFullPage(false, 'custom');
})
.then(function (result) {
expect(result).eql(true);
});
});
it('Should take a screenshot on fail', function () {
return runTests('./testcafe-fixtures/take-full-page-screenshot.js', 'Screenshot on fail', {
shouldFail: true,
setScreenshotPath: true,
screenshotsFullPage: true,
screenshotsOnFails: true
})
.catch(function (errs) {
expect(errs[0]).to.contains('screenshot on fail');
return assertionHelper.checkScreenshotFileFullPage(true);
});
});
}
});