Skip to content

fix: examples in test title #4030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/interfaces/gherkin.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,14 @@ module.exports = (text, file) => {
});
}
const tags = child.scenario.tags.map(t => t.name).concat(examples.tags.map(t => t.name));
const title = `${child.scenario.name} ${JSON.stringify(current)} ${tags.join(' ')}`.trim();
let title = `${child.scenario.name} ${JSON.stringify(current)} ${tags.join(' ')}`.trim();

for (const [key, value] of Object.entries(current)) {
if (title.includes(`<${key}>`)) {
title = title.replace(JSON.stringify(current), '').replace(`<${key}>`, value);
}
}

const test = new Test(title, async () => runSteps(addExampleInTable(exampleSteps, current)));
test.tags = suite.tags.concat(tags);
test.file = file;
Expand Down
2 changes: 1 addition & 1 deletion test/bdd/features/faker.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@bdd
Feature: Faker examples

Scenario Outline: faker data genetation
Scenario Outline: faker data generation
Given I sold the "<product>" car to "<customer>" for "<price>"
When customer "<customer>" paid "<price>" for car "<product>" in "<cashier>"
Then "<cashier>" returned "<change>" in change to "<customer>"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Feature: Include Examples in dataTtable placeholder

@IncludeExamplesIndataTtable
Scenario Outline: order a product with discount
Scenario Outline: order a product with discount - <name> - <price>
Given I have this product in my cart
| data | value |
| name | <name> |
Expand Down
2 changes: 1 addition & 1 deletion test/data/sandbox/features/examples.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ Feature: Checkout examples process
| 20 | 20.0 |
| 21 | 18.9 |
| 30 | 27.0 |
| 50 | 45.0 |
| 50 | 45.0 |
12 changes: 12 additions & 0 deletions test/runner/bdd_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ describe('BDD Gherkin', () => {
});
});

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) => { //eslint-disable-line
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) => { //eslint-disable-line
stdout.should.include('Given I have products in my cart');
Expand Down