将AspectJ与黄瓜一起使用

时间:2019-01-03 13:48:43

标签: cucumber aop aspectj load-time-weaving compile-time-weaving

我正在尝试使用带有黄瓜项目的AspectJ来添加带有黄瓜的条件语句(您可能会想为什么。但是我是)。它截取了我在当前项目中拥有的Cucumber步骤定义,但是我也有要编织的依赖项jar,我使用Aspectj-maven插件进行编织,但是我的代码无法在此依赖项中使用粘合代码,我相信这是因为代码已因编织而被修改。我应该怎么做呢?

这是maven-aspectj插件:

<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>aspectj-maven-plugin</artifactId>
        <version>1.8</version>
        <configuration>
           <complianceLevel>1.8</complianceLevel>
           <source>1.8</source>
           <target>1.8</target>
           <weaveDependencies>
              <weaveDependency>
                 <groupId>com.tsb.gen</groupId>
                 <artifactId>gen-selenium</artifactId>
              </weaveDependency>
           </weaveDependencies>
        </configuration>
        <executions>
           <execution>
              <goals>
                  <goal>compile</goal>
                 <goal>test-compile</goal>
              </goals>
           </execution>
        </executions>
        <dependencies>
           <dependency>
              <groupId>org.aspectj</groupId>
              <artifactId>aspectjrt</artifactId>
              <version>${aspectj.version}</version>
           </dependency>
           <dependency>
              <groupId>org.aspectj</groupId>
              <artifactId>aspectjtools</artifactId>
              <version>${aspectj.version}</version>
           </dependency>
        </dependencies>
     </plugin>

依赖项:

<groupId>com.tsb.gen</groupId>
<artifactId>gen-selenium</artifactId>
我的项目中的粘合代码也使用

。 如果删除,则可以使用Aspectj在我的项目中使用粘合代码和其他多数民众赞成,但是我不能在此基本依赖项中使用任何多数民众赞成。我想用那个。

我的长相就像:

@Around("execution(* *(..)) && " +
        "( @annotation(cucumber.api.java.en.And) " +
        "|| @annotation(cucumber.api.java.en.But) " +
        "|| @annotation(cucumber.api.java.en.Given) " +
        "|| @annotation(cucumber.api.java.en.Then) " +
        "|| @annotation(cucumber.api.java.en.When) " +
        ")")
public Object aroundGlueMethod(ProceedingJoinPoint joinPoint) throws Throwable {
    ScenarioContext.checkForProgressDisplay();
    //ScenarioContext.logToGenieReport("aroundGlueMethod aspect");
    //System.out.println("\"aroundGlueMethod aspect\"");
    Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
    Object[] args;
    Object obj=null;

    // process arguments
    args = processArgs(joinPoint.getArgs(),joinPoint.getTarget().getClass().getName());
    if (methodHasAnnotation(method, SkipConditionalChecking.class)) {
        obj=joinPoint.proceed(args);
    } else {
        if (ScenarioContext.shouldNextStepGetExecuted()) {
            obj=joinPoint.proceed(args);
        } else {
            writeMessageToCurrentScenario("skipped as condition is false");
            logger.info("step skipped as condition is false: {}", joinPoint.getSignature());
        }
    }
    return obj;

}

黄瓜要做什么:

 When If variable '${name}' equals to 'myname'
    Then print 'Hey its me'
 EndIf

我能够在属于我的项目中解决这个问题,但是当我尝试在依赖项中包括步骤定义或粘合代码时,它无法识别任何步骤定义。 我尝试使用加载时间编织,但不确定是否完全了解如何完成这两项工作。

0 个答案:

没有答案