Search in sources :

Example 1 with Step

use of gherkin.ast.Step in project page-factory-2 by sbtqa.

the class StepReplacer method replaceWith.

List<Step> replaceWith(List<Step> replacementSteps) {
    List<Map<String, String>> dataTable = FragmentDataTableUtils.getDataTable(step);
    if (dataTable.isEmpty()) {
        addSteps(replacementSteps);
        return replacedSteps;
    }
    for (Map<String, String> dataTableRow : dataTable) {
        for (Step replacementStep : replacementSteps) {
            String text = FragmentDataTableUtils.applyToText(dataTableRow, replacementStep.getText());
            DataTable argument = null;
            if (replacementStep.getArgument() != null) {
                argument = FragmentDataTableUtils.applyToArgument(dataTableRow, replacementStep);
            }
            addStep(step.getLocation(), replacementStep.getKeyword(), text, argument);
        }
    }
    return replacedSteps;
}
Also used : DataTable(gherkin.ast.DataTable) Step(gherkin.ast.Step) Map(java.util.Map)

Example 2 with Step

use of gherkin.ast.Step in project page-factory-2 by sbtqa.

the class StepReplacer method addStep.

private void addStep(Location location, String keyword, String text, Node argument) {
    Step replacedStep = new Step(location, keyword, text, argument);
    replacedSteps.add(replacedStep);
}
Also used : Step(gherkin.ast.Step)

Example 3 with Step

use of gherkin.ast.Step in project cucable-plugin by trivago.

the class GherkinToCucableConverterTest method convertGherkinStepsToCucableStepsTest.

@Test
public void convertGherkinStepsToCucableStepsTest() {
    List<Step> gherkinSteps = Arrays.asList(new Step(new Location(1, 1), "Given ", "this is a test step", null), new Step(new Location(2, 1), "Then ", "I get a test result", null));
    List<com.trivago.vo.Step> steps = gherkinToCucableConverter.convertGherkinStepsToCucableSteps(gherkinSteps);
    assertThat(steps.size(), is(gherkinSteps.size()));
    com.trivago.vo.Step firstStep = steps.get(0);
    assertThat(firstStep.getName(), is("Given this is a test step"));
    com.trivago.vo.Step secondStep = steps.get(1);
    assertThat(secondStep.getName(), is("Then I get a test result"));
}
Also used : Step(gherkin.ast.Step) Location(gherkin.ast.Location) Test(org.junit.Test)

Example 4 with Step

use of gherkin.ast.Step in project cucable-plugin by trivago.

the class GherkinToCucableConverter method convertGherkinStepsToCucableSteps.

/**
 * Converts a list of Gherkin steps to Cucable steps including data tables.
 *
 * @param gherkinSteps a {@link Step} list.
 * @return a {@link com.trivago.rta.vo.Step} list.
 */
List<com.trivago.rta.vo.Step> convertGherkinStepsToCucableSteps(final List<Step> gherkinSteps) {
    List<com.trivago.rta.vo.Step> steps = new ArrayList<>();
    for (Step gherkinStep : gherkinSteps) {
        com.trivago.rta.vo.Step step;
        com.trivago.rta.vo.DataTable dataTable = null;
        String docString = null;
        Node argument = gherkinStep.getArgument();
        if (argument instanceof DataTable) {
            dataTable = convertGherkinDataTableToCucumberDataTable((DataTable) argument);
        } else if (argument instanceof DocString) {
            docString = ((DocString) argument).getContent();
        }
        String keywordAndName = gherkinStep.getKeyword().concat(gherkinStep.getText());
        step = new com.trivago.rta.vo.Step(keywordAndName, dataTable, docString);
        steps.add(step);
    }
    return steps;
}
Also used : DataTable(gherkin.ast.DataTable) Node(gherkin.ast.Node) ArrayList(java.util.ArrayList) Step(gherkin.ast.Step) DocString(gherkin.ast.DocString) DocString(gherkin.ast.DocString)

Example 5 with Step

use of gherkin.ast.Step in project cucable-plugin by trivago.

the class GherkinToCucableConverterTest method convertGherkinStepsToCucableStepsTest.

@Test
public void convertGherkinStepsToCucableStepsTest() {
    List<Step> gherkinSteps = Arrays.asList(new Step(new Location(1, 1), "Given ", "this is a test step", null), new Step(new Location(2, 1), "Then ", "I get a test result", null));
    List<com.trivago.rta.vo.Step> steps = gherkinToCucableConverter.convertGherkinStepsToCucableSteps(gherkinSteps);
    assertThat(steps.size(), is(gherkinSteps.size()));
    com.trivago.rta.vo.Step firstStep = steps.get(0);
    assertThat(firstStep.getName(), is("Given this is a test step"));
    com.trivago.rta.vo.Step secondStep = steps.get(1);
    assertThat(secondStep.getName(), is("Then I get a test result"));
}
Also used : Step(gherkin.ast.Step) Location(gherkin.ast.Location) Test(org.junit.Test)

Aggregations

Step (gherkin.ast.Step)8 DataTable (gherkin.ast.DataTable)3 ArrayList (java.util.ArrayList)3 DocString (gherkin.ast.DocString)2 Location (gherkin.ast.Location)2 Node (gherkin.ast.Node)2 Test (org.junit.Test)2 Map (java.util.Map)1 DataReplacer (ru.sbtqa.tag.pagefactory.data.DataReplacer)1