Search in sources :

Example 1 with PickleStepTag

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

the class DataReplacer method replacePickleArguments.

private void replacePickleArguments(PickleStepTestStep currentStep, boolean isStash) throws IllegalAccessException {
    PickleStepTag pickleStepTag = (PickleStepTag) currentStep.getPickleStep();
    for (gherkin.pickles.Argument argument : currentStep.getPickleStep().getArgument()) {
        if (argument.getClass().equals(PickleTable.class)) {
            replacePickleTable(pickleStepTag, (PickleTable) argument, isStash);
        } else if (argument.getClass().equals(PickleString.class)) {
            String content = replaceData(pickleStepTag, ((PickleString) argument).getContent(), isStash);
            FieldUtils.writeField(argument, "content", content, true);
        }
    }
    Object definitionMatchArguments = FieldUtils.readField(FieldUtils.readField(currentStep, "definitionMatch", true), "arguments", true);
    if (definitionMatchArguments instanceof ArrayList) {
        for (Object definitionMatchArgument : (ArrayList) definitionMatchArguments) {
            if (definitionMatchArgument instanceof DataTableArgument) {
                List<List<String>> newDefinitionMatchArgument = replaceDataTable(definitionMatchArgument, currentStep, isStash);
                FieldUtils.writeField(definitionMatchArgument, "argument", newDefinitionMatchArgument, true);
            } else if (definitionMatchArgument instanceof DocStringArgument) {
                String newDefinitionMatchArgument = replaceData((PickleStepTag) currentStep.getPickleStep(), ((DocStringArgument) definitionMatchArgument).getValue().toString(), isStash);
                FieldUtils.writeField(definitionMatchArgument, "argument", newDefinitionMatchArgument, true);
            }
        }
    }
}
Also used : PickleStepTag(ru.sbtqa.tag.pagefactory.optional.PickleStepTag) ArrayList(java.util.ArrayList) DataTableArgument(io.cucumber.stepexpression.DataTableArgument) ArrayList(java.util.ArrayList) List(java.util.List) PickleString(gherkin.pickles.PickleString) PickleString(gherkin.pickles.PickleString) DocStringArgument(io.cucumber.stepexpression.DocStringArgument)

Example 2 with PickleStepTag

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

the class CriticalStepAspect method removeNonCriticalSign.

@Around(value = "removeNonCriticalSign(featurePath, step)")
public Object removeNonCriticalSign(ProceedingJoinPoint joinPoint, String featurePath, PickleStep step) throws Throwable {
    PickleStepTag pickleStepTag = step instanceof PickleStepTag ? (PickleStepTag) step : new PickleStepTag(step);
    pickleStepTag.removeNonCriticalSign();
    return joinPoint.proceed(new Object[] { featurePath, pickleStepTag });
}
Also used : PickleStepTag(ru.sbtqa.tag.pagefactory.optional.PickleStepTag) Around(org.aspectj.lang.annotation.Around)

Example 3 with PickleStepTag

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

the class DataAspect method run.

@Around("run(testCase,bus,scenario,skipSteps)")
public Object run(ProceedingJoinPoint joinPoint, TestCase testCase, EventBus bus, cucumber.api.Scenario scenario, boolean skipSteps) throws Throwable {
    TestStep testStep = (TestStep) joinPoint.getThis();
    if (!(testStep instanceof HookTestStep)) {
        PickleStepTestStep pickleStepTestStep = (PickleStepTestStep) testStep;
        PickleStepTag stepCustom = getPickleStepTag(pickleStepTestStep);
        stepCustom.setSkipped(skipSteps);
        replaceByPickleStepTag(pickleStepTestStep, stepCustom);
    }
    return joinPoint.proceed();
}
Also used : PickleStepTag(ru.sbtqa.tag.pagefactory.optional.PickleStepTag) Around(org.aspectj.lang.annotation.Around)

Example 4 with PickleStepTag

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

the class DataAspect method run.

@Around("sendCaseStart(event)")
public Object run(ProceedingJoinPoint joinPoint, TestCaseStarted event) throws Throwable {
    List<PickleTag> tags = event.testCase.getTags().stream().filter(pickleTag -> pickleTag.getName().startsWith(DataUtils.DATA_TAG)).collect(Collectors.toList());
    if (!tags.isEmpty()) {
        String dataTagName = tags.get(tags.size() - 1).getName();
        String data = DataUtils.getDataTagValue(dataTagName);
        for (TestStep testStep : event.testCase.getTestSteps()) {
            if (!(testStep instanceof HookTestStep)) {
                PickleStepTestStep pickleStepTestStep = (PickleStepTestStep) testStep;
                PickleStepTag stepCustom = getPickleStepTag(pickleStepTestStep);
                stepCustom.setDataTag(data);
                replaceByPickleStepTag(pickleStepTestStep, stepCustom);
            }
        }
    }
    return joinPoint.proceed();
}
Also used : Logger(org.slf4j.Logger) TestCaseStarted(cucumber.api.event.TestCaseStarted) LoggerFactory(org.slf4j.LoggerFactory) TestStepStarted(cucumber.api.event.TestStepStarted) Pointcut(org.aspectj.lang.annotation.Pointcut) StepDefinitionMatch(cucumber.runtime.StepDefinitionMatch) cucumber.api(cucumber.api) Collectors(java.util.stream.Collectors) Around(org.aspectj.lang.annotation.Around) PickleStep(gherkin.pickles.PickleStep) EventBus(cucumber.runner.EventBus) DataUtils(ru.sbtqa.tag.pagefactory.data.DataUtils) List(java.util.List) PickleStepTag(ru.sbtqa.tag.pagefactory.optional.PickleStepTag) TestStepFinished(cucumber.api.event.TestStepFinished) Aspect(org.aspectj.lang.annotation.Aspect) PickleTag(gherkin.pickles.PickleTag) FieldUtils(org.apache.commons.lang3.reflect.FieldUtils) DataReplacer(ru.sbtqa.tag.pagefactory.data.DataReplacer) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) PickleStepTag(ru.sbtqa.tag.pagefactory.optional.PickleStepTag) PickleTag(gherkin.pickles.PickleTag) Around(org.aspectj.lang.annotation.Around)

Example 5 with PickleStepTag

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

the class PrintSteps method sendStepStarted.

@Around("sendStepStarted(event)")
public void sendStepStarted(ProceedingJoinPoint joinPoint, Event event) throws Throwable {
    PickleStepTestStep testStep = (PickleStepTestStep) ((TestStepStarted) event).testStep;
    String stepText = testStep.getStepText();
    if (!previous.equals(stepText) && testStep.getPickleStep() instanceof PickleStepTag && !((PickleStepTag) testStep.getPickleStep()).isSkipped()) {
        System.out.println("    * " + stepText);
        previous = stepText;
    }
    joinPoint.proceed();
}
Also used : PickleStepTestStep(cucumber.api.PickleStepTestStep) PickleStepTag(ru.sbtqa.tag.pagefactory.optional.PickleStepTag) Around(org.aspectj.lang.annotation.Around)

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