Skip to content

[Core] Make Scenario.getId() return the actual scenario id #2366

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
merged 1 commit into from
Aug 17, 2021
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
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