Search in sources :

Example 6 with PickleStepTag

use of ru.sbtqa.tag.pagefactory.optional.PickleStepTag in project page-factory-2 by sbtqa.

the class DataReplacer method replace.

private void replace(PickleStepTestStep testStep, boolean isStash) throws IllegalAccessException {
    PickleStepTag step = (PickleStepTag) (testStep.getPickleStep());
    replacePickleArguments(testStep, isStash);
    replaceStepArguments(testStep, isStash);
    replaceStepText(step, isStash);
}
Also used : PickleStepTag(ru.sbtqa.tag.pagefactory.optional.PickleStepTag)

Example 7 with PickleStepTag

use of ru.sbtqa.tag.pagefactory.optional.PickleStepTag in project page-factory-2 by sbtqa.

the class DataReplacer method replaceStepArguments.

private void replaceStepArguments(PickleStepTestStep testStep, boolean isStash) throws IllegalAccessException {
    PickleStepTag step = (PickleStepTag) testStep.getPickleStep();
    String stepText = step.getText();
    String pattern = isStash ? STASH_PARSE_REGEX : PATH_PARSE_REGEX;
    Pattern stepDataPattern = Pattern.compile(pattern);
    Matcher stepDataMatcher = stepDataPattern.matcher(stepText);
    int offset = 0;
    for (Argument argument : testStep.getDefinitionArgument()) {
        String argVal = argument.getValue();
        if (argVal != null) {
            String data = replaceData(step, argVal, isStash);
            boolean isReplaceNeededParameter = stepDataPattern.matcher(argVal).find() && stepDataMatcher.find();
            Object group = FieldUtils.readField(argument, "group", true);
            if (isReplaceNeededParameter && offset == 0) {
                // this is first replace-needed parameter
                offset = data.length() - argVal.length();
                FieldUtils.writeField(group, "value", data, true);
                FieldUtils.writeField(group, "end", argument.getEnd() + offset, true);
            } else if (isReplaceNeededParameter) {
                // this is not first replace-needed parameter
                FieldUtils.writeField(group, "value", data, true);
                FieldUtils.writeField(group, "start", argument.getStart() + offset, true);
                int thisOffset = data.length() - argVal.length();
                FieldUtils.writeField(group, "end", argument.getEnd() + offset + thisOffset, true);
                offset += thisOffset;
            } else if (offset != 0) {
                // this is ordinary parameter
                FieldUtils.writeField(group, "start", argument.getStart() + offset, true);
                FieldUtils.writeField(group, "end", argument.getEnd() + offset, true);
            }
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) Argument(cucumber.api.Argument) DataTableArgument(io.cucumber.stepexpression.DataTableArgument) DocStringArgument(io.cucumber.stepexpression.DocStringArgument) Matcher(java.util.regex.Matcher) PickleStepTag(ru.sbtqa.tag.pagefactory.optional.PickleStepTag) PickleString(gherkin.pickles.PickleString)

Aggregations

PickleStepTag (ru.sbtqa.tag.pagefactory.optional.PickleStepTag)7 Around (org.aspectj.lang.annotation.Around)4 PickleString (gherkin.pickles.PickleString)2 DataTableArgument (io.cucumber.stepexpression.DataTableArgument)2 DocStringArgument (io.cucumber.stepexpression.DocStringArgument)2 List (java.util.List)2 cucumber.api (cucumber.api)1 Argument (cucumber.api.Argument)1 PickleStepTestStep (cucumber.api.PickleStepTestStep)1 TestCaseStarted (cucumber.api.event.TestCaseStarted)1 TestStepFinished (cucumber.api.event.TestStepFinished)1 TestStepStarted (cucumber.api.event.TestStepStarted)1 EventBus (cucumber.runner.EventBus)1 StepDefinitionMatch (cucumber.runtime.StepDefinitionMatch)1 PickleStep (gherkin.pickles.PickleStep)1 PickleTag (gherkin.pickles.PickleTag)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1