Search in sources :

Example 1 with Scenario

use of io.cucumber.messages.types.Scenario in project cucumber-jvm by cucumber.

the class JsonFormatter method createTestCase.

private Map<String, Object> createTestCase(TestCaseStarted event) {
    Map<String, Object> testCaseMap = new HashMap<>();
    testCaseMap.put("start_timestamp", getDateTimeFromTimeStamp(event.getInstant()));
    TestCase testCase = event.getTestCase();
    testCaseMap.put("name", testCase.getName());
    testCaseMap.put("line", testCase.getLine());
    testCaseMap.put("type", "scenario");
    TestSourcesModel.AstNode astNode = testSources.getAstNode(currentFeatureFile, testCase.getLine());
    if (astNode != null) {
        testCaseMap.put("id", TestSourcesModel.calculateId(astNode));
        Scenario scenarioDefinition = TestSourcesModel.getScenarioDefinition(astNode);
        testCaseMap.put("keyword", scenarioDefinition.getKeyword());
        testCaseMap.put("description", scenarioDefinition.getDescription() != null ? scenarioDefinition.getDescription() : "");
    }
    testCaseMap.put("steps", new ArrayList<Map<String, Object>>());
    if (!testCase.getTags().isEmpty()) {
        List<Map<String, Object>> tagList = new ArrayList<>();
        for (String tag : testCase.getTags()) {
            Map<String, Object> tagMap = new HashMap<>();
            tagMap.put("name", tag);
            tagList.add(tagMap);
        }
        testCaseMap.put("tags", tagList);
    }
    return testCaseMap;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TestCase(io.cucumber.plugin.event.TestCase) TestSourcesModel.getBackgroundForTestCase(io.cucumber.core.plugin.TestSourcesModel.getBackgroundForTestCase) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Scenario(io.cucumber.messages.types.Scenario)

Example 2 with Scenario

use of io.cucumber.messages.types.Scenario in project cucumber-jvm by cucumber.

the class GherkinMessagesPickle method getScenarioLocation.

@Override
public Location getScenarioLocation() {
    String sourceId = pickle.getAstNodeIds().get(0);
    Scenario scenario = cucumberQuery.getGherkinScenario(sourceId);
    io.cucumber.messages.types.Location location = scenario.getLocation();
    return GherkinMessagesLocation.from(location);
}
Also used : Scenario(io.cucumber.messages.types.Scenario)

Aggregations

Scenario (io.cucumber.messages.types.Scenario)2 TestSourcesModel.getBackgroundForTestCase (io.cucumber.core.plugin.TestSourcesModel.getBackgroundForTestCase)1 TestCase (io.cucumber.plugin.event.TestCase)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1