Search in sources :

Example 1 with TestCaseStarted

use of cucumber.api.event.TestCaseStarted 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)

Aggregations

cucumber.api (cucumber.api)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 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 FieldUtils (org.apache.commons.lang3.reflect.FieldUtils)1 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)1 Around (org.aspectj.lang.annotation.Around)1 Aspect (org.aspectj.lang.annotation.Aspect)1 Pointcut (org.aspectj.lang.annotation.Pointcut)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 DataReplacer (ru.sbtqa.tag.pagefactory.data.DataReplacer)1 DataUtils (ru.sbtqa.tag.pagefactory.data.DataUtils)1 PickleStepTag (ru.sbtqa.tag.pagefactory.optional.PickleStepTag)1