forked from codeceptjs/CodeceptJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbdd_test.js
More file actions
377 lines (335 loc) · 15.6 KB
/
bdd_test.js
File metadata and controls
377 lines (335 loc) · 15.6 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
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
const assert = require('assert')
const path = require('path')
const exec = require('child_process').exec
const runner = path.join(__dirname, '/../../bin/codecept.js')
const codecept_dir = path.join(__dirname, '/../data/sandbox')
const codecept_run = `${runner} run`
const config_run_config = config => `${codecept_run} --config ${codecept_dir}/${config}`
describe('BDD Gherkin', () => {
before(() => {
process.chdir(codecept_dir)
})
it('should run feature files', done => {
exec(config_run_config('codecept.bdd.js') + ' --steps --grep "Checkout process"', (err, stdout, stderr) => {
stdout.should.include('Checkout process') // feature
stdout.should.include('-- before checkout --')
stdout.should.include('-- after checkout --')
// stdout.should.include('In order to buy products'); // test name
stdout.should.include('Given I have product with $600 price')
stdout.should.include('And I have product with $1000 price')
stdout.should.include('Then I should see that total number of products is 2')
stdout.should.include('And my order amount is $1600')
stdout.should.not.include('I add item 600') // 'Given' actor's non-gherkin step check
stdout.should.not.include('I see sum 1600') // 'And' actor's non-gherkin step check
assert(!err)
done()
})
})
it('should print substeps in debug mode', done => {
exec(config_run_config('codecept.bdd.js') + ' --debug --grep "Checkout process"', (err, stdout, stderr) => {
stdout.should.include('Checkout process') // feature
// stdout.should.include('In order to buy products'); // test name
stdout.should.include('Given I have product with $600 price')
stdout.should.include('I add item 600')
stdout.should.include('And I have product with $1000 price')
stdout.should.include('I add item 1000')
stdout.should.include('Then I should see that total number of products is 2')
stdout.should.include('I see num 2')
stdout.should.include('And my order amount is $1600')
stdout.should.include('I see sum 1600')
assert(!err)
done()
})
})
it('should print events in nodejs debug mode', done => {
exec(`DEBUG=codeceptjs:* ${config_run_config('codecept.bdd.js')} --grep "Checkout products" --debug`, (err, stdout, stderr) => {
stderr.should.include('Emitted | step.start (I add product "Harry Potter", 5)')
stdout.should.include('name | category | price')
stdout.should.include('Harry Potter | Books | 5')
stdout.should.include('iPhone 5 | Smartphones | 1200 ')
stdout.should.include('Nuclear Bomb | Weapons | 100000')
assert(!err)
done()
})
})
it('should obfuscate secret substeps in debug mode', done => {
exec(config_run_config('codecept.bdd.js') + ' --debug --grep "Secrets"', (err, stdout, stderr) => {
stdout.should.include('Given I login') // feature
stdout.should.not.include('password')
assert(!err)
done()
})
})
it('should run feature with examples files', done => {
exec(config_run_config('codecept.bdd.js') + ' --steps --grep "Checkout examples"', (err, stdout, stderr) => {
stdout.should.include(' order discount {"price":"10","total":"10.0"}')
stdout.should.include(' Given I have product with price 10$ in my cart')
stdout.should.include(' order discount {"price":"20","total":"20.0"}')
stdout.should.include(' Given I have product with price 20$ in my cart')
stdout.should.include(' order discount {"price":"21","total":"18.9"}')
stdout.should.include(' Given I have product with price 21$ in my cart')
stdout.should.include(' order discount {"price":"30","total":"27.0"}')
stdout.should.include(' Given I have product with price 30$ in my cart')
stdout.should.include(' order discount {"price":"50","total":"45.0"}')
stdout.should.include(' Given I have product with price 50$ in my cart')
assert(!err)
done()
})
})
it('should run feature with table and examples files', done => {
exec(config_run_config('codecept.bdd.js') + ' --steps --grep "Include Examples in dataTtable placeholder"', (err, stdout, stderr) => {
stdout.should.include('name | Nuclear Bomb ')
stdout.should.include('price | 20 ')
stdout.should.include('name | iPhone 5 ')
stdout.should.include('price | 10 ')
assert(!err)
done()
})
})
it('should show data from examples in test title', done => {
exec(config_run_config('codecept.bdd.js') + ' --steps --grep "Include Examples in dataTtable placeholder"', (err, stdout, stderr) => {
stdout.should.include('order a product with discount - iPhone 5 - 10 @IncludeExamplesIndataTtable')
stdout.should.include('name | Nuclear Bomb ')
stdout.should.include('price | 20 ')
stdout.should.include('name | iPhone 5 ')
stdout.should.include('price | 10 ')
assert(!err)
done()
})
})
it('should run feature with tables', done => {
exec(config_run_config('codecept.bdd.js') + ' --steps --grep "Checkout products"', (err, stdout, stderr) => {
stdout.should.include('Given I have products in my cart')
stdout.should.include('name')
stdout.should.include('Harry Potter')
stdout.should.include('Smartphones')
stdout.should.include('100000')
stdout.should.include('Then my order amount is $101205')
assert(!err)
done()
})
})
it('should run feature with tables contain long text', done => {
exec(config_run_config('codecept.bdd.js') + ' --steps --grep "Checkout products"', (err, stdout, stderr) => {
stdout.should.include('Given I have products in my cart')
stdout.should.include('name')
stdout.should.include('Harry Potter and the deathly hallows')
assert(!err)
done()
})
})
it('should run feature with long strings', done => {
exec(config_run_config('codecept.bdd.js') + ' --steps --grep "Checkout string"', (err, stdout, stderr) => {
stdout.should.include('Given I have product described as')
stdout.should.include('The goal of the product description is to provide the customer with enough information to compel them to want to buy the product immediately.')
stdout.should.include('Then my order amount is $582')
assert(!err)
done()
})
})
it('should run feature by file name', done => {
exec(config_run_config('codecept.bdd.js') + ' --steps features/tables.feature', (err, stdout, stderr) => {
stdout.should.include('Checkout product')
stdout.should.include('checkout 3 products')
stdout.should.not.include('Checkout string')
stdout.should.not.include('describe product')
stdout.should.not.include('Checkout process')
stdout.should.not.include('Checkout examples process')
assert(!err)
done()
})
})
it('should run feature by scenario name', done => {
exec(config_run_config('codecept.bdd.js') + ' --grep "checkout 3 products" --steps', (err, stdout, stderr) => {
stdout.should.include('Checkout product')
stdout.should.include('checkout 3 products')
stdout.should.not.include('Checkout string')
stdout.should.not.include('describe product')
stdout.should.not.include('Checkout process')
stdout.should.not.include('Checkout examples process')
assert(!err)
done()
})
})
it('should run feature by tag name', done => {
exec(config_run_config('codecept.bdd.js') + ' --grep "@important" --steps', (err, stdout, stderr) => {
stdout.should.include('I have product with $600 price in my cart')
stdout.should.not.include('Checkout string')
stdout.should.not.include('describe product')
stdout.should.not.include('Checkout table')
stdout.should.not.include('Checkout examples process')
assert(!err)
done()
})
})
it('should run scenario by tag name', done => {
exec(config_run_config('codecept.bdd.js') + ' --grep "@very" --steps', (err, stdout, stderr) => {
stdout.should.include('I have product with $600 price in my cart')
stdout.should.not.include('Checkout string')
stdout.should.not.include('describe product')
stdout.should.not.include('Checkout table')
stdout.should.not.include('Checkout examples process')
assert(!err)
done()
})
})
it('should run scenario outline by tag', done => {
exec(config_run_config('codecept.bdd.js') + ' --grep "@user" --steps', (err, stdout, stderr) => {
stdout.should.not.include('0 passed')
stdout.should.include('I have product with price 10$')
assert(!err)
done()
})
})
it('should run scenario and scenario outline by tags', done => {
exec(config_run_config('codecept.bdd.js') + ' --grep "@user|@very" --steps', (err, stdout, stderr) => {
stdout.should.not.include('0 passed')
stdout.should.include('I have product with price 10$')
stdout.should.include('I have product with $600 price in my cart')
stdout.should.include('6 passed')
assert(!err)
done()
})
})
it('should run scenario and scenario outline by tags', done => {
exec(config_run_config('codecept.bdd.js') + ' --grep "@user|@very" --steps', (err, stdout, stderr) => {
stdout.should.not.include('0 passed')
stdout.should.include('I have product with price 10$')
stdout.should.include('I have product with $600 price in my cart')
stdout.should.include('6 passed')
assert(!err)
done()
})
})
it('should run not get stuck on failing step', done => {
exec(config_run_config('codecept.bdd.js') + ' --grep "@fail" --steps', (err, stdout, stderr) => {
// stdout.should.include('Given I make a request (and it fails)');
// stdout.should.not.include('Then my test execution gets stuck');
stdout.should.include('1 failed')
stdout.should.include('[Wrapped Error]')
assert(err)
done()
})
})
it('should show all available steps', done => {
exec(`${runner} gherkin:steps --config ${codecept_dir}/codecept.bdd.js`, (err, stdout, stderr) => {
stdout.should.include('Gherkin')
stdout.should.include('/I have product with \\$(\\d+) price/')
stdout.should.include('step_definitions/my_steps.js:3:1')
stdout.should.include('step_definitions/my_steps.js:3:1')
stdout.should.include('I should see that total number of products is {int}')
stdout.should.include('I should see overall price is "{float}" $')
assert(!err)
done()
})
})
it('should generate snippets for missing steps', done => {
exec(`${runner} gherkin:snippets --dry-run --config ${codecept_dir}/codecept.dummy.bdd.js`, (err, stdout, stderr) => {
stdout.should.include(`Given('I open a browser on a site', () => {
// From "support/dummy.feature" {"line":4,"column":5}
throw new Error('Not implemented yet');
});
When('I click login button at {float}', () => {
// From "support/dummy.feature" {"line":5,"column":5}
throw new Error('Not implemented yet');
});
When('I enter username {string} and password {string}', () => {
// From "support/dummy.feature" {"line":6,"column":5}
throw new Error('Not implemented yet');
});
When('I submit {int} form', () => {
// From "support/dummy.feature" {"line":7,"column":5}
throw new Error('Not implemented yet');
});
Then('I should log in', () => {
// From "support/dummy.feature" {"line":8,"column":5}
throw new Error('Not implemented yet');
});
When(/^I define a step with an opening paren \\( only$/, () => {
// From "support/dummy.feature" {"line":9,"column":5}
throw new Error('Not implemented yet');
});
When(/^I define a step with a closing paren \\) only$/, () => {
// From "support/dummy.feature" {"line":10,"column":5}
throw new Error('Not implemented yet');
});
When(/^I define a step with a opening brace \\{ only$/, () => {
// From "support/dummy.feature" {"line":11,"column":5}
throw new Error('Not implemented yet');
});
When(/^I define a step with a closing brace \\} only$/, () => {
// From "support/dummy.feature" {"line":12,"column":5}
throw new Error('Not implemented yet');
});
When(/^I define a step with a slash http:\\/\\/example\\.com\\/foo$/, () => {
// From "support/dummy.feature" {"line":13,"column":5}
throw new Error('Not implemented yet');
});
When(/^I define a step with a \\( paren and an (\\d+) int$/, () => {
// From "support/dummy.feature" {"line":14,"column":5}
throw new Error('Not implemented yet');
});
When(/^I define a step with a \\( paren and a (\\d+\\.\\d+) float$/, () => {
// From "support/dummy.feature" {"line":15,"column":5}
throw new Error('Not implemented yet');
});
When(/^I define a step with a \\( paren and a "(.*?)" string$/, () => {
// From "support/dummy.feature" {"line":16,"column":5}
throw new Error('Not implemented yet');
});`)
assert(!err)
done()
})
})
it('should not generate duplicated steps', done => {
exec(`${runner} gherkin:snippets --dry-run --config ${codecept_dir}/codecept.duplicate.bdd.js`, (err, stdout, stderr) => {
assert.equal(stdout.match(/I open a browser on a site/g).length, 1)
assert(!err)
done()
})
})
describe('i18n', () => {
const codecept_dir = path.join(__dirname, '/../data/sandbox/i18n')
const config_run_config = config => `${codecept_run} --config ${codecept_dir}/${config}`
before(() => {
process.chdir(codecept_dir)
})
it('should run feature files in DE', done => {
exec(config_run_config('codecept.bdd.de.js') + ' --steps --grep "@i18n"', (err, stdout, stderr) => {
stdout.should.include('On Angenommen: ich habe ein produkt mit einem preis von 10$ in meinem warenkorb')
stdout.should.include('On Und: der rabatt für bestellungen über $20 beträgt 10 %')
stdout.should.include('On Wenn: ich zur kasse gehe')
stdout.should.include('On Dann: sollte ich den gesamtpreis von "10.0" $ sehen')
stdout.should.include('On Angenommen: ich habe ein produkt mit einem preis von 10$ in meinem warenkorb')
stdout.should.include('Ich add item 10')
stdout.should.include('On Und: der rabatt für bestellungen über $20 beträgt 10 %')
stdout.should.include('Ich have discount for price 20, 10')
stdout.should.include('On Wenn: ich zur kasse gehe')
stdout.should.include('Ich checkout')
stdout.should.include('On Dann: sollte ich den gesamtpreis von "10.0" $ sehen')
stdout.should.include('Ich see sum 10')
assert(!err)
done()
})
})
it('should run feature files in NL', done => {
exec(config_run_config('codecept.bdd.nl.js') + ' --steps --grep "@i18n"', (err, stdout, stderr) => {
console.log(stdout)
stdout.should.include('On Gegeven: ik heb een product met een prijs van 10$ in mijn winkelwagen')
stdout.should.include('On En: de korting voor bestellingen van meer dan $20 is 10 %')
stdout.should.include('On Wanneer: ik naar de kassa ga')
stdout.should.include('On Dan: zou ik de totaalprijs van "10.0" $ moeten zien')
stdout.should.include('On Gegeven: ik heb een product met een prijs van 10$ in mijn winkelwagen')
stdout.should.include('Ik add item 10')
stdout.should.include('On En: de korting voor bestellingen van meer dan $20 is 10 %')
stdout.should.include('Ik have discount for price 20, 10')
stdout.should.include('On Wanneer: ik naar de kassa ga')
stdout.should.include('Ik checkout')
stdout.should.include('On Dan: zou ik de totaalprijs van "10.0" $ moeten zien')
stdout.should.include('Ik see sum 10')
assert(!err)
done()
})
})
})
})