-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add afterScenarioOutline & karate.scenarioOutline #2636
Merged
ptrthomas
merged 4 commits into
karatelabs:develop
from
OwenK2:2634-scenario-outline-metadata
Jan 3, 2025
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
karate-core/src/main/java/com/intuit/karate/core/ScenarioOutlineResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2022 Karate Labs Inc. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nts: update date |
||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package com.intuit.karate.core; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* | ||
* @author OwenK2 | ||
*/ | ||
public class ScenarioOutlineResult { | ||
|
||
final private ScenarioOutline scenarioOutline; | ||
final private ScenarioRuntime runtime; | ||
|
||
public ScenarioOutlineResult(ScenarioOutline scenarioOutline, ScenarioRuntime runtime) { | ||
// NOTE: this value can be null, in which case the scenario is not from an outline | ||
this.scenarioOutline = scenarioOutline; | ||
this.runtime = runtime; | ||
} | ||
|
||
public Map<String, Object> toKarateJson() { | ||
if (scenarioOutline == null) return null; | ||
Map<String, Object> map = new HashMap(); | ||
map.put("name", scenarioOutline.getName()); | ||
map.put("description", scenarioOutline.getDescription()); | ||
map.put("line", scenarioOutline.getLine()); | ||
map.put("sectionIndex", scenarioOutline.getSection().getIndex()); | ||
map.put("exampleTableCount", scenarioOutline.getNumExampleTables()); | ||
map.put("exampleTables", scenarioOutline.getAllExampleData()); | ||
map.put("numScenariosToExecute", scenarioOutline.getNumScenarios()); | ||
|
||
// Get results of other examples in this outline | ||
List<Map<String, Object>> scenarioResults = new ArrayList(); | ||
if (runtime.featureRuntime != null && runtime.featureRuntime.result != null) { | ||
// Add all past results | ||
runtime.featureRuntime.result.getScenarioResults().forEach(result -> { | ||
if (result.getScenario().getSection().getIndex() == scenarioOutline.getSection().getIndex()) { | ||
scenarioResults.add(result.toInfoJson()); | ||
} | ||
}); | ||
|
||
// Add most recent result | ||
if (runtime.result != null) { | ||
scenarioResults.add(runtime.result.toInfoJson()); | ||
} | ||
} | ||
map.put("scenarioResults", scenarioResults); | ||
map.put("numScenariosExecuted", scenarioResults.size()); | ||
|
||
return map; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,10 @@ public int compareTo(ScenarioResult sr) { | |
if (delta != 0) { | ||
return delta; | ||
} | ||
delta = scenario.getExampleTableIndex() - sr.scenario.getExampleTableIndex(); | ||
if (delta != 0) { | ||
return delta; | ||
} | ||
return scenario.getExampleIndex() - sr.scenario.getExampleIndex(); | ||
} | ||
|
||
|
@@ -137,9 +141,10 @@ private List<Map> getStepResults(boolean background) { | |
|
||
public static ScenarioResult fromKarateJson(File workingDir, Feature feature, Map<String, Object> map) { | ||
int sectionIndex = (Integer) map.get("sectionIndex"); | ||
int exampleTableIndex = (Integer) map.get("exampleTableIndex"); | ||
int exampleIndex = (Integer) map.get("exampleIndex"); | ||
FeatureSection section = feature.getSection(sectionIndex); | ||
Scenario scenario = new Scenario(feature, section, exampleIndex); | ||
Scenario scenario = new Scenario(feature, section, exampleTableIndex, exampleIndex); | ||
if (section.isOutline()) { | ||
scenario.setTags(section.getScenarioOutline().getTags()); | ||
scenario.setDescription(section.getScenarioOutline().getDescription()); | ||
|
@@ -194,6 +199,7 @@ public Map<String, Object> toKarateJson() { | |
} | ||
//====================================================================== | ||
map.put("sectionIndex", scenario.getSection().getIndex()); | ||
map.put("exampleTableIndex", scenario.getExampleTableIndex()); | ||
map.put("exampleIndex", scenario.getExampleIndex()); | ||
Map<String, Object> exampleData = scenario.getExampleData(); | ||
if (exampleData != null) { | ||
|
@@ -213,6 +219,28 @@ public Map<String, Object> toKarateJson() { | |
return map; | ||
} | ||
|
||
// Paired down information for use in karate.scenarioOutline | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nts: pared |
||
public Map<String, Object> toInfoJson() { | ||
Map<String, Object> map = new HashMap(); | ||
map.put("durationMillis", getDurationMillis()); | ||
List<String> tags = scenario.getTagsEffective().getTags(); | ||
if (tags != null && !tags.isEmpty()) { | ||
map.put("tags", tags); | ||
} | ||
map.put("failed", isFailed()); | ||
map.put("refId", scenario.getRefId()); | ||
map.put("sectionIndex", scenario.getSection().getIndex()); | ||
map.put("exampleTableIndex", scenario.getExampleTableIndex()); | ||
map.put("exampleIndex", scenario.getExampleIndex()); | ||
map.put("name", scenario.getName()); | ||
map.put("description", scenario.getDescription()); | ||
map.put("line", scenario.getLine()); | ||
map.put("executorName", executorName); | ||
map.put("startTime", startTime); | ||
map.put("endTime", endTime); | ||
return map; | ||
} | ||
|
||
public Map<String, Object> toCucumberJson() { | ||
Map<String, Object> map = new HashMap(); | ||
map.put("name", scenario.getName()); | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so following up from my previous comment - suggest since in this loop we know how many examples and example tables are there - we will be able to emit an extra boolean if this is the last scenario selected for execution within an outline
if that solves your current ask - I would just do that, as I really don't see a need for tracking counts of examples and tables :|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good I can definitely make that simplification. What about the
scenarioResults
though? What do you feel would be the best way to get that information from an API perspective.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now I just removed the table index code in 6e84b5d. Didn't want to push too far ahead before we finalized something.