diff --git a/lib/plugin/screenshotOnFail.js b/lib/plugin/screenshotOnFail.js index d9144d06e..fddfea643 100644 --- a/lib/plugin/screenshotOnFail.js +++ b/lib/plugin/screenshotOnFail.js @@ -129,7 +129,7 @@ module.exports = function (config) { return test.uuid; } - if (test.ctx) { + if (test.ctx && test.ctx.test.uuid) { return test.ctx.test.uuid; } diff --git a/test/unit/plugin/screenshotOnFail_test.js b/test/unit/plugin/screenshotOnFail_test.js index 6412c47d6..6c47c1dc7 100644 --- a/test/unit/plugin/screenshotOnFail_test.js +++ b/test/unit/plugin/screenshotOnFail_test.js @@ -44,5 +44,15 @@ describe('screenshotOnFail', () => { assert.equal('test1_1.failed.png', screenshotSaved.getCall(0).args[0]); }); + it('should create screenshot with unique name when uuid is null', async () => { + screenshotOnFail({ uniqueScreenshotNames: true }); + event.dispatcher.emit(event.test.failed, { title: 'test1' }); + await recorder.promise(); + assert.ok(screenshotSaved.called); + const fileName = screenshotSaved.getCall(0).args[0]; + const regexpFileName = /test1_[0-9]{10}.failed.png/; + assert.equal(fileName.match(regexpFileName).length, 1); + }); + // TODO: write more tests for different options });