gherkin.ast.Step Java Examples

The following examples show how to use gherkin.ast.Step. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExtentCucumberAdapter.java    From extentreports-cucumber4-adapter with Apache License 2.0 6 votes vote down vote up
private synchronized void createTestStep(PickleStepTestStep testStep) {
    String stepName = testStep.getStepText();
    TestSourcesModel.AstNode astNode = testSources.getAstNode(currentFeatureFile.get(), testStep.getStepLine());
    if (astNode != null) {
        Step step = (Step) astNode.node;
        try {
            String name = stepName == null || stepName.isEmpty() 
                    ? step.getText().replace("<", "&lt;").replace(">", "&gt;")
                    : stepName;
            ExtentTest t = scenarioThreadLocal.get()
                    .createNode(new GherkinKeyword(step.getKeyword().trim()), step.getKeyword() + name, testStep.getCodeLocation());
            stepTestThreadLocal.set(t);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    if (!testStep.getStepArgument().isEmpty()) {
        Argument argument = testStep.getStepArgument().get(0);
        if (argument instanceof PickleString) {
            createDocStringMap((PickleString)argument);
        } else if (argument instanceof PickleTable) {
            List<PickleRow> rows = ((PickleTable) argument).getRows();
            stepTestThreadLocal.get().pass(MarkupHelper.createTable(getPickleTable(rows)).getMarkup());
        }
    }
}
 
Example #2
Source File: BddParser.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
private void createTestCases(Scenario scenario, Feature feature) {
    for (ScenarioDefinition scenarioDef : feature.getChildren()) {
        String scenDefName = scenarioDef.getName();
        TestCase testCase = updateInfo(createTestCase(scenario, scenDefName), scenarioDef);
        testCase.clearSteps();
        for (Step step : scenarioDef.getSteps()) {
            String reusableName = convert(step.getText());
            TestCase reusable = updateInfo(createReusable(create("StepDefinitions"), reusableName), step);
            if (reusable != null) {
                reusable.addNewStep()
                        .setInput(getInputField(testCase.getName(), step.getText()))
                        .setDescription(getDescription(step));
            }
            testCase.addNewStep()
                    .asReusableStep("StepDefinitions", reusableName)
                    .setDescription(getDescription(step));
        }
        if (scenarioDef instanceof ScenarioOutline) {
            ScenarioOutline scOutline = (ScenarioOutline) scenarioDef;
            createTestData(testCase, scOutline.getExamples());
        }
    }
}
 
Example #3
Source File: BddParser.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
private TestCase updateInfo(TestCase tc, Step step) {
    if (tc != null) {
        DataItem tcInfo = pModel().getData().find(tc.getName(), tc.getScenario().getName())
                .orElseGet(() -> {
                    DataItem di = DataItem.createTestCase(tc.getName(), tc.getScenario().getName());
                    pModel().addData(di);
                    return di;
                });

        tcInfo.getAttributes().update(Attribute.create("feature.children.step.line", step.getLocation().getLine()));
        tcInfo.getAttributes().update(Attribute.create("feature.children.step.text", step.getText()));
        tcInfo.getAttributes().update(Attribute.create("feature.children.step.argument", step.getArgument()));
        tcInfo.getAttributes().update(Attribute.create("feature.children.step.keyword", step.getKeyword()));
        pModel().addData(tcInfo);
    }
    return tc;
}
 
Example #4
Source File: TestCommand.java    From rug-cli with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void stepFailed(Step s, Throwable t) {
    // The additional " " is expected
    if (!"When ".equals(s.getKeyword())) {
        if (CommandLineOptions.hasOption("error")) {
            StringWriter errors = new StringWriter();
            t.printStackTrace(new PrintWriter(errors));
            reporter.report("    Step " + s.getText() + " " + Style.red("failed") + ":\n"
                    + errors.toString());
        }
        else {
            reporter.report("    Step " + s.getText() + " " + Style.red("failed")
                    + ":    \n" + t.getMessage());
        }
    }
}
 
Example #5
Source File: TestSourcesModel.java    From extentreports-cucumber4-adapter with Apache License 2.0 5 votes vote down vote up
private void processScenarioDefinition(Map<Integer, AstNode> nodeMap, ScenarioDefinition child, AstNode currentParent) {
    AstNode childNode = new AstNode(child, currentParent);
    nodeMap.put(child.getLocation().getLine(), childNode);
    for (Step step : child.getSteps()) {
        nodeMap.put(step.getLocation().getLine(), new AstNode(step, childNode));
    }
    if (child instanceof ScenarioOutline) {
        processScenarioOutlineExamples(nodeMap, (ScenarioOutline) child, childNode);
    }
}
 
Example #6
Source File: ExtentCucumberAdapter.java    From extentreports-cucumber4-adapter with Apache License 2.0 5 votes vote down vote up
private synchronized void addOutlineStepsToReport(ScenarioOutline scenarioOutline) {
    for (Step step : scenarioOutline.getSteps()) {
        if (step.getArgument() != null) {
            Node argument = step.getArgument();
            if (argument instanceof DocString) {
                createDocStringMap((DocString)argument);
            } else if (argument instanceof DataTable) {
                
            }
        }
    }
}
 
Example #7
Source File: TestSourcesModel.java    From allure-java with Apache License 2.0 5 votes vote down vote up
private void processScenarioDefinition(final Map<Integer, AstNode> nodeMap, final ScenarioDefinition child,
                                       final AstNode currentParent) {
    final AstNode childNode = new AstNode(child, currentParent);
    nodeMap.put(child.getLocation().getLine(), childNode);
    for (Step step : child.getSteps()) {
        nodeMap.put(step.getLocation().getLine(), createAstNode(step, childNode));
    }
    if (child instanceof ScenarioOutline) {
        processScenarioOutlineExamples(nodeMap, (ScenarioOutline) child, childNode);
    }
}
 
Example #8
Source File: BddParser.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 4 votes vote down vote up
private String getDescription(Step step) {
    if (step.getArgument() != null && step.getArgument() instanceof DocString) {
        return ((DocString) step.getArgument()).getContent();
    }
    return step.getKeyword() + " " + step.getText();
}
 
Example #9
Source File: TestCommand.java    From rug-cli with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void stepCompleted(Step s) {
}
 
Example #10
Source File: TestCommand.java    From rug-cli with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void stepStarting(Step s) {
}