Skip to content

Commit c8b0a1a

Browse files
authored
[Core] Make Scenario.getId() return the actual scenario id (#2366)
To obtain the original `<uri>:<line-number>` identifier use `scenario.getUri() + ":" + scenario.getLine()`. Closes: #2254
1 parent a9aa7fb commit c8b0a1a

File tree

5 files changed

+39
-15
lines changed

5 files changed

+39
-15
lines changed

CHANGELOG.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3131
- Replace `DataTable.asMaps()` with -> `DataTable.entries()`
3232
* [TestNG] Automatically pick up properties from `testng.xml` ([#2354](https://github.com/cucumber/cucumber-jvm/pull/2354) M.P. Korstanje, Gayan Sandaruwan)
3333
* [Core] Pretty formatter to print step DataTables ([#2330](https://github.com/cucumber/cucumber-jvm/pull/2330) Arty Sidorenko)
34+
* [Core] `Scenario.getId()` returns the actual scenario id ([#2366](https://github.com/cucumber/cucumber-jvm/issues/2366) M.P. Korstanje)
35+
- To obtain the original `<uri>:<line-number>` identifier use `scenario.getUri() + ":" + scenario.getLine()`.
3436

3537
### Deprecated
3638

3739
### Removed
3840
* [Core] Removed `--strict` and `--no-strict` options ([#1788](https://github.com/cucumber/cucumber-jvm/issues/1788) M.P. Korstanje)
39-
- Cucumber executes scenarios in strict mode by default
41+
- Cucumber executes scenarios in strict mode by default
4042
* [Core] Removed deprecated `TypeRegistryConfigurer` ([#2356](https://github.com/cucumber/cucumber-jvm/issues/2356) M.P. Korstanje)
41-
- Use `@ParameterType` instead.
43+
- Use `@ParameterType` instead.
4244
* [Weld] Removed `cucumber-weld` ([#2276](https://github.com/cucumber/cucumber-jvm/issues/2276) M.P. Korstanje)
43-
- Consider using `cucumber-jakarta-cdi` or `cucumber-cdi2`.
45+
- Consider using `cucumber-jakarta-cdi` or `cucumber-cdi2`.
4446
* [Needle] Removed `cucumber-needled` ([#2276](https://github.com/cucumber/cucumber-jvm/issues/2276) M.P. Korstanje)
45-
- Consider using `cucumber-jakarta-cdi` or `cucumber-cdi2`.
47+
- Consider using `cucumber-jakarta-cdi` or `cucumber-cdi2`.
4648

4749
### Fixed
4850
* [Core] Emit step hook messages ([#2009](https://github.com/cucumber/cucumber-jvm/issues/2093) Grasshopper)

core/src/main/java/io/cucumber/core/runner/TestCaseState.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public String getName() {
130130

131131
@Override
132132
public String getId() {
133-
return testCase.getUri() + ":" + getLine();
133+
return testCase.getId().toString();
134134
}
135135

136136
@Override

core/src/test/java/io/cucumber/core/runner/TestCaseStateTest.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
import io.cucumber.messages.types.Attachment.ContentEncoding;
88
import io.cucumber.messages.types.Envelope;
99
import io.cucumber.plugin.event.EmbedEvent;
10-
import org.junit.jupiter.api.Assertions;
1110
import org.junit.jupiter.api.Test;
1211

1312
import java.io.File;
14-
import java.nio.charset.StandardCharsets;
1513
import java.time.Clock;
1614
import java.util.ArrayList;
1715
import java.util.Base64;
@@ -84,7 +82,7 @@ void provides_the_uri_and_scenario_line_as_unique_id() {
8482

8583
TestCaseState state = createTestCaseState(feature);
8684

87-
assertThat(state.getId(), is(new File("path/file.feature:2").toURI().toString()));
85+
assertThat(state.getUri() + ":" + state.getLine(), is(new File("path/file.feature:2").toURI().toString()));
8886
}
8987

9088
@Test
@@ -98,7 +96,7 @@ void provides_the_uri_and_example_row_line_as_unique_id_for_scenarios_from_scena
9896
" | cuke | \n");
9997
TestCaseState state = createTestCaseState(feature);
10098

101-
assertThat(state.getId(), is(new File("path/file.feature:6").toURI().toString()));
99+
assertThat(state.getUri() + ":" + state.getLine(), is(new File("path/file.feature:6").toURI().toString()));
102100
}
103101

104102
@Test

java/src/main/java/io/cucumber/java/Scenario.java

+15-3
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ public String getName() {
108108
}
109109

110110
/**
111+
* Returns the unique identifier for this scenario.
112+
* <p>
113+
* If this is a Scenario from Scenario Outlines this will return the id of
114+
* the example row in the Scenario Outline.
115+
* <p>
116+
* The id is not stable across multiple executions of Cucumber but does
117+
* correlate with ids used in messages output. Use the uri + line number to
118+
* obtain a somewhat stable identifier of a scenario.
119+
*
111120
* @return the id of the Scenario.
112121
*/
113122
public String getId() {
@@ -122,9 +131,12 @@ public URI getUri() {
122131
}
123132

124133
/**
125-
* @return the line in the feature file of the Scenario. If this is a
126-
* Scenario from Scenario Outlines this will return the line of the
127-
* example row in the Scenario Outline.
134+
* Returns the line in the feature file of the Scenario.
135+
* <p>
136+
* If this is a Scenario from Scenario Outlines this will return the line of
137+
* the example row in the Scenario Outline.
138+
*
139+
* @return the line in the feature file of the Scenario
128140
*/
129141
public Integer getLine() {
130142
return delegate.getLine();

java8/src/main/java/io/cucumber/java8/Scenario.java

+15-3
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ public String getName() {
106106
}
107107

108108
/**
109+
* Returns the unique identifier for this scenario.
110+
* <p>
111+
* If this is a Scenario from Scenario Outlines this will return the id of
112+
* the example row in the Scenario Outline.
113+
* <p>
114+
* The id is not stable across multiple executions of Cucumber but does
115+
* correlate with ids used in messages output. Use the uri + line number to
116+
* obtain a somewhat stable identifier of a scenario.
117+
*
109118
* @return the id of the Scenario.
110119
*/
111120
public String getId() {
@@ -120,9 +129,12 @@ public URI getUri() {
120129
}
121130

122131
/**
123-
* @return the line in the feature file of the Scenario. If this is a
124-
* Scenario from Scenario Outlines this will return the line of the
125-
* example row in the Scenario Outline.
132+
* Returns the line in the feature file of the Scenario.
133+
* <p>
134+
* If this is a Scenario from Scenario Outlines this will return the line of
135+
* the example row in the Scenario Outline.
136+
*
137+
* @return the line in the feature file of the Scenario
126138
*/
127139
public Integer getLine() {
128140
return delegate.getLine();

0 commit comments

Comments
 (0)