Skip to content

Commit f6d6ad4

Browse files
GalyRainGalina Tarasevich
andauthored
Fix for @Testid tag handling in Scenario Outline (issue #215) (#240)
* test(FRT-3058): fixed bug 215 * fix: commit that triggers release for #240 --------- Co-authored-by: Galina Tarasevich <[email protected]>
1 parent 4e0637f commit f6d6ad4

File tree

5 files changed

+74
-47
lines changed

5 files changed

+74
-47
lines changed

CONTRIBUTING.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,3 @@ Fixes: #123
123123
```
124124

125125
A tool like [Commitizen](https://github.com/commitizen/cz-cli) can be used to help with formatting commit messages.
126-

cypress/e2e/cucumber/allure.feature

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,30 @@
55
Feature: AllureAPI
66
I want to use allure api in cypress tests
77

8-
@tagForRule
9-
Rule: TestRule
8+
@tagForRule
9+
Rule: TestRule
1010

11-
@testID("12345")
12-
@issue("jira","tmsLink")
13-
@tms("tms","tmsLink")
14-
@link("example","https://example.com")
15-
@severity("minor")
16-
@tagForTest
17-
Scenario: Cucumber tags should work
18-
Given I have allure tags set for Feature
19-
When I run any test
20-
Then I should see allure api working properly
21-
And Tags from test should overwrite tags from feature
11+
@testID("12345")
12+
@issue("jira", "tmsLink")
13+
@tms("tms", "tmsLink")
14+
@link("example", "https://example.com")
15+
@severity("minor")
16+
@tagForTest
17+
Scenario: Cucumber tags should work
18+
Given I have allure tags set for Feature
19+
When I run any test
20+
Then I should see allure api working properly
21+
And Tags from test should overwrite tags from feature
22+
23+
24+
@testID("111|222")
25+
Scenario Outline: Cucumber tags should work
26+
Given I have allure tags set for Feature
27+
When I run any test with "<Value>"
28+
Then I should see allure api working properly
29+
And Tags from test should overwrite tags from feature
30+
31+
Examples:
32+
| Value |
33+
| 1111 |
34+
| 2222 |

cypress/e2e/cucumber/allure/steps.cy.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ When('I run any test', () => {
88
cy.log('child command for when');
99
});
1010

11+
When('I run any test with {string}', (value) => {
12+
cy.log(`child command for when ${value}`);
13+
});
14+
1115
Then('I should see allure api working properly', () => {
1216
cy.log('child command for allure api "then" step');
1317
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@
6565
"nonGlobalStepDefinitions": true,
6666
"stepDefinitions": "cypress/e2e/cucumber"
6767
}
68-
}
68+
}

reporter/allure-cypress/CucumberHandler.js

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,17 @@ class CucumberHandler {
8383
get outlineExampleIndex() {
8484
if (this.isNewFormat) {
8585
const [, exampleId] = this.state.pickle.astNodeIds;
86-
if (
87-
!this.currentScenario.examples ||
88-
!this.currentScenario.examples.length
89-
) {
90-
return -1;
86+
const examples = this.currentScenario.examples || [];
87+
88+
for (const example of examples) {
89+
const index = example.tableBody.findIndex(
90+
(item) => item.id === exampleId
91+
);
92+
if (index !== -1) {
93+
return index;
94+
}
9195
}
92-
return this.currentScenario.examples[0].tableBody.findIndex(
93-
(item) => item.id === exampleId
94-
);
96+
return -1;
9597
}
9698
const num = parseInt(
9799
exampleNumber.exec(this.currentScenario.name).pop()
@@ -113,7 +115,7 @@ class CucumberHandler {
113115
}
114116

115117
const newTags = [
116-
...currentTags.filter((t) => !t.type && !t.type !== 'Tag'),
118+
...currentTags.filter((t) => !(t && t.type === 'Tag')),
117119
tag
118120
];
119121

@@ -220,29 +222,38 @@ class CucumberHandler {
220222
}
221223

222224
kind.tags
223-
.filter(function ({ name }) {
224-
const match = tagToLabel.exec(name);
225-
if (match) {
226-
const [, command, value] = match;
227-
// feature and suite should be overwritten to avoid duplicates
228-
if (['feature', 'suite'].includes(command)) {
229-
const index = currentTest.info.labels.findIndex(
230-
(label) => label.name === command
231-
);
232-
currentTest.info.labels[index] = {
233-
name: command,
234-
value: value
235-
};
236-
} else {
237-
// handle renaming label for testID, or just use label name
238-
currentTest.addLabel(
239-
command === 'testID' ? 'AS_ID' : command,
240-
value
241-
);
225+
.filter(
226+
function ({ name }) {
227+
const match = tagToLabel.exec(name);
228+
if (match) {
229+
const [, command, value] = match;
230+
231+
// testID handling with outline index support
232+
if (command === 'testID') {
233+
const ids = value.split('|');
234+
const index = this.outlineExampleIndex ?? 0;
235+
const id = ids[index] || ids[0];
236+
currentTest.addLabel('AS_ID', id);
237+
} else if (
238+
['feature', 'suite'].includes(command)
239+
) {
240+
// feature and suite should be overwritten to avoid duplicates
241+
const labelIndex =
242+
currentTest.info.labels.findIndex(
243+
(label) => label.name === command
244+
);
245+
currentTest.info.labels[labelIndex] = {
246+
name: command,
247+
value: value
248+
};
249+
} else {
250+
// use label name
251+
currentTest.addLabel(command, value);
252+
}
242253
}
243-
}
244-
return !match;
245-
})
254+
return !match;
255+
}.bind(this) // bind context to access this.outlineExampleIndex inside callback
256+
)
246257
// check for links
247258
.filter(function ({ name }) {
248259
const match = tagToLink.exec(name);
@@ -276,7 +287,7 @@ class CucumberHandler {
276287
.forEach(function ({ name }) {
277288
currentTest.addLabel('tag', name.replace('@', ''));
278289
});
279-
}
290+
}.bind(this)
280291
);
281292
}
282293
}

0 commit comments

Comments
 (0)