AspectJ Pointcut не запускается - PullRequest
0 голосов
/ 08 июня 2018

Я пытаюсь подключиться к библиотекам Cucumber-Serenity, которые работают с AspectJ, но мои точки запуска не запускаются.

SerenityAOP.java :

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

import gherkin.ast.Feature;
import gherkin.ast.ScenarioDefinition;
import net.thucydides.core.model.TestStep;
import net.thucydides.core.steps.StepEventBus;

@Aspect
public class SerenityAOP {    
    @Pointcut("execution(void cucumber.runtime.formatter.SerenityReporter.startOfScenarioLifeCycle(..))")
    public void beforeStartScenario() {}

    @Pointcut("execution(void cucumber.runtime.SerenityObjectFactory.stop())")
    public static void beforeStop(){}


    @Before("beforeStartScenario()")
    public void beforeStartScenarioAdvice(JoinPoint joinPoint) {
        Object[] signatureArgs = joinPoint.getArgs();

        Feature currentFeature = (Feature)signatureArgs[0];     
        String scenarioName = signatureArgs[1].toString();
        ScenarioDefinition scenarioDefinition = (ScenarioDefinition)signatureArgs[2];


        System.out.println("ASPECT: Starting test case for feature "+currentFeature+" with scneario: "+scenarioName);
    }

    @Before("beforeStop()")
    public void beforeStopAdvice() {
        boolean status = StepEventBus.getEventBus().aStepInTheCurrentTestHasFailed();
        String stepDescription = StepEventBus.getEventBus().getCurrentStep()
                .transform(TestStep::getDescription)
                .get();

        System.out.println("ASPECT: Testcase: "+stepDescription+" status = "+status);           
    }
}

Соответствующие зависимости :

     <dependency>
        <groupId>net.thucydides</groupId>
        <artifactId>thucydides-junit</artifactId>
        <version>0.9.275</version>
    </dependency>  
      <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
        <version>1.9.1</version>
    </dependency>
    <dependency>
      <groupId>org.assertj</groupId>
      <artifactId>assertj-core</artifactId>
      <version>3.9.0</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.6</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.5</version>
    </dependency>
    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-core</artifactId>
        <version>${serenity.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-junit</artifactId>
        <version>${serenity.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-cucumber</artifactId>
        <version>${serenity.cucumber.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <scope>test</scope>
        <version>3.8.1</version>
    </dependency>   

Но я не вижу своих печатных строк нигде во время выполнения.

Есть ли какой-то способ, которым мне нужно перехватитьв эти внутренние библиотечные вызовы по-разному?Или мои селекторы точек неправильны?

РЕДАКТИРОВАТЬ: Добавление комментария в случае удаления текущего ответа

С помощью крючков с огурцом я не могу обнаружить, когдановый feature запущен.Мне нужно получить имя feature и scenario, когда они начнутся.Я не нашел способа сделать это с помощью шины событий.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...