Skip to content

Commit

Permalink
[Core] Make Scenario.getId() return the actual scenario id
Browse files Browse the repository at this point in the history
To obtain the original `<uri>:<line-number>` identifier use
`scenario.getUri() + ":" + scenario.getLine()`.

Closes: #2254
  • Loading branch information
mpkorstanje committed Aug 17, 2021
1 parent 393a787 commit 6c59124
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 15 deletions.
10 changes: 6 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Replace `DataTable.asMaps()` with -> `DataTable.entries()`
* [TestNG] Automatically pick up properties from `testng.xml` ([#2354](https://github.com/cucumber/cucumber-jvm/pull/2354) M.P. Korstanje, Gayan Sandaruwan)
* [Core] Pretty formatter to print step DataTables ([#2330](https://github.com/cucumber/cucumber-jvm/pull/2330) Arty Sidorenko)
* [Core] `Scenario.getId()` returns the actual scenario id ([#2366](https://github.com/cucumber/cucumber-jvm/issues/2366) M.P. Korstanje)
- To obtain the original `<uri>:<line-number>` identifier use `scenario.getUri() + ":" + scenario.getLine()`.

### Deprecated

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

### Fixed
* [Core] Emit step hook messages ([#2009](https://github.com/cucumber/cucumber-jvm/issues/2093) Grasshopper)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public String getName() {

@Override
public String getId() {
return testCase.getUri() + ":" + getLine();
return testCase.getId().toString();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
import io.cucumber.messages.types.Attachment.ContentEncoding;
import io.cucumber.messages.types.Envelope;
import io.cucumber.plugin.event.EmbedEvent;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.time.Clock;
import java.util.ArrayList;
import java.util.Base64;
Expand Down Expand Up @@ -84,7 +82,7 @@ void provides_the_uri_and_scenario_line_as_unique_id() {

TestCaseState state = createTestCaseState(feature);

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

@Test
Expand All @@ -98,7 +96,7 @@ void provides_the_uri_and_example_row_line_as_unique_id_for_scenarios_from_scena
" | cuke | \n");
TestCaseState state = createTestCaseState(feature);

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

@Test
Expand Down
18 changes: 15 additions & 3 deletions java/src/main/java/io/cucumber/java/Scenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ public String getName() {
}

/**
* Returns the unique identifier for this scenario.
* <p>
* If this is a Scenario from Scenario Outlines this will return the id of
* the example row in the Scenario Outline.
* <p>
* The id is not stable across multiple executions of Cucumber but does
* correlate with ids used in messages output. Use the uri + line number to
* obtain a somewhat stable identifier of a scenario.
*
* @return the id of the Scenario.
*/
public String getId() {
Expand All @@ -122,9 +131,12 @@ public URI getUri() {
}

/**
* @return the line in the feature file of the Scenario. If this is a
* Scenario from Scenario Outlines this will return the line of the
* example row in the Scenario Outline.
* Returns the line in the feature file of the Scenario.
* <p>
* If this is a Scenario from Scenario Outlines this will return the line of
* the example row in the Scenario Outline.
*
* @return the line in the feature file of the Scenario
*/
public Integer getLine() {
return delegate.getLine();
Expand Down
18 changes: 15 additions & 3 deletions java8/src/main/java/io/cucumber/java8/Scenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ public String getName() {
}

/**
* Returns the unique identifier for this scenario.
* <p>
* If this is a Scenario from Scenario Outlines this will return the id of
* the example row in the Scenario Outline.
* <p>
* The id is not stable across multiple executions of Cucumber but does
* correlate with ids used in messages output. Use the uri + line number to
* obtain a somewhat stable identifier of a scenario.
*
* @return the id of the Scenario.
*/
public String getId() {
Expand All @@ -120,9 +129,12 @@ public URI getUri() {
}

/**
* @return the line in the feature file of the Scenario. If this is a
* Scenario from Scenario Outlines this will return the line of the
* example row in the Scenario Outline.
* Returns the line in the feature file of the Scenario.
* <p>
* If this is a Scenario from Scenario Outlines this will return the line of
* the example row in the Scenario Outline.
*
* @return the line in the feature file of the Scenario
*/
public Integer getLine() {
return delegate.getLine();
Expand Down

0 comments on commit 6c59124

Please sign in to comment.