我正在尝试将 aspectJ 与 cucumber 项目一起使用来添加带有 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
我能够在属于我的项目的东西中解决它,但是当我尝试在依赖项中包含步骤定义或粘合代码时,它无法识别任何步骤定义。我尝试使用加载时间编织,但我不确定我是否完全了解如何完成这两件事。