I am trying to use aspectJ with cucumber project to add conditional statements with cucumber(you may think why.. but I am). It intercepts the cucumber step definitions that I have in my current project but I have dependency jars as well that I want to weave, I am weaving it using aspectj-maven plugin but then my code is not able to use glue code in this dependency, I believe that is because the code has been modified due to weaving. How should I be doing it instead?
this is maven-aspectj plugin:
<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>
the dependency:
<groupId>com.tsb.gen</groupId>
<artifactId>gen-selenium</artifactId>
is also used by my glue code that I have in my project. If I remove , then I am able to use the glue code and anything else thats in my project with aspectj but I cant use anything thats inside this base dependency. i want to use that.
My Aspect is like:
@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;
}
What am trying to do with cucumber is something like :
When If variable '${name}' equals to 'myname'
Then print 'Hey its me'
EndIf
I am able to work it out in the things that belong to my project, but when I am trying to include the step definitions or glue code in the dependencies it doesnt recognize any step definitions. I tried using load time weaving but I am not sure I totally get how to accomplish both the things.