-
-
Notifications
You must be signed in to change notification settings - Fork 750
Expand file tree
/
Copy pathscreenshotOnFail_test.js
More file actions
85 lines (73 loc) · 2.97 KB
/
screenshotOnFail_test.js
File metadata and controls
85 lines (73 loc) · 2.97 KB
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
let expect
import('chai').then(chai => {
expect = chai.expect
})
const sinon = require('sinon')
const screenshotOnFail = require('../../../lib/plugin/screenshotOnFail')
const container = require('../../../lib/container')
const event = require('../../../lib/event')
const recorder = require('../../../lib/recorder')
let screenshotSaved
describe('screenshotOnFail', () => {
beforeEach(() => {
recorder.reset()
screenshotSaved = sinon.spy()
container.clear({
WebDriver: {
options: {},
saveScreenshot: screenshotSaved,
},
})
})
it('should remove the . at the end of test title', async () => {
screenshotOnFail({})
event.dispatcher.emit(event.test.failed, { title: 'test title.' })
await recorder.promise()
expect(screenshotSaved.called).is.ok
expect('test_title.failed.png').is.equal(screenshotSaved.getCall(0).args[0])
})
it('should exclude the data driven in failed screenshot file name', async () => {
screenshotOnFail({})
event.dispatcher.emit(event.test.failed, { title: 'Scenario with data driven | {"login":"admin","password":"123456"}' })
await recorder.promise()
expect(screenshotSaved.called).is.ok
expect('Scenario_with_data_driven.failed.png').is.equal(screenshotSaved.getCall(0).args[0])
})
it('should create screenshot on fail', async () => {
screenshotOnFail({})
event.dispatcher.emit(event.test.failed, { title: 'test1' })
await recorder.promise()
expect(screenshotSaved.called).is.ok
expect('test1.failed.png').is.equal(screenshotSaved.getCall(0).args[0])
})
it('should create screenshot with unique name', async () => {
screenshotOnFail({ uniqueScreenshotNames: true })
const test = { title: 'test1', uid: 1 }
event.dispatcher.emit(event.test.failed, test)
await recorder.promise()
expect(screenshotSaved.called).is.ok
expect(`test1_${test.uid}.failed.png`).is.equal(screenshotSaved.getCall(0).args[0])
})
it('should create screenshot with unique name when uid is null', async () => {
screenshotOnFail({ uniqueScreenshotNames: true })
event.dispatcher.emit(event.test.failed, { title: 'test1' })
await recorder.promise()
expect(screenshotSaved.called).is.ok
const fileName = screenshotSaved.getCall(0).args[0]
const regexpFileName = /test1_[0-9]{10}.failed.png/
expect(fileName.match(regexpFileName).length).is.equal(1)
})
it('should not save screenshot in BeforeSuite', async () => {
screenshotOnFail({ uniqueScreenshotNames: true })
event.dispatcher.emit(event.test.failed, { title: 'test1' }, null, 'BeforeSuite')
await recorder.promise()
expect(!screenshotSaved.called).is.ok
})
it('should not save screenshot in AfterSuite', async () => {
screenshotOnFail({ uniqueScreenshotNames: true })
event.dispatcher.emit(event.test.failed, { title: 'test1' }, null, 'AfterSuite')
await recorder.promise()
expect(!screenshotSaved.called).is.ok
})
// TODO: write more tests for different options
})