-
-
Notifications
You must be signed in to change notification settings - Fork 736
/
Copy pathscreenshotOnFail_test.js
105 lines (91 loc) · 3.76 KB
/
screenshotOnFail_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
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')
const { createTest } = require('../../../lib/mocha/test')
const { deserializeSuite } = require('../../../lib/mocha/suite')
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, createTest('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, createTest('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, createTest('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 = createTest('test1')
const suite = deserializeSuite({ title: 'suite1' })
test.addToSuite(suite)
event.dispatcher.emit(event.test.failed, test)
await recorder.promise()
expect(screenshotSaved.called).is.ok
expect(screenshotSaved.getCall(0).args[0]).not.to.include('/')
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 })
const test = createTest('test1')
event.dispatcher.emit(event.test.failed, test)
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 create screenshot with unique name when uid is null', async () => {
screenshotOnFail({ uniqueScreenshotNames: true })
const test = createTest('test1')
event.dispatcher.emit(event.test.failed, test)
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 })
const test = createTest('test1')
event.dispatcher.emit(event.test.failed, test, null, 'BeforeSuite')
await recorder.promise()
expect(!screenshotSaved.called).is.ok
})
it('should not save screenshot in AfterSuite', async () => {
screenshotOnFail({ uniqueScreenshotNames: true })
const test = createTest('test1')
event.dispatcher.emit(event.test.failed, test, null, 'AfterSuite')
await recorder.promise()
expect(!screenshotSaved.called).is.ok
})
// TODO: write more tests for different options
})