Using aspectJ with Cucumber





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















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.










share|improve this question























  • Well I've never seen anybody try to do this before. I really don't know. If you can point to a specific point where it goes wrong people might be able to help you better.

    – mpkorstanje
    Jan 3 at 16:53











  • The point it goes wrong is that it cannot call the glue codes inside the woven dependency. It says the step is undefined. It cant find methods in it. If I remove the woven dependency in aspectj plugin, I can easily access point cuts inside my project. I want a way to weave the dependency and use its contents.

    – MagicBeans
    Jan 4 at 5:07













  • When you say It says the step is undefined this means that Cucumber can't find your step. You'll have to work out why this no longer works after weaving. I believe MethodScanner would be a good place to start: github.com/cucumber/cucumber-jvm/blob/master/java/src/main/java/…

    – mpkorstanje
    Jan 4 at 16:06






  • 1





    This setup is way too complex to expect to get an answer here without providing an MCVE reproducing the problem, ideally on GitHub. If you do provide one, I will take a look.

    – kriegaex
    Jan 6 at 3:08


















0















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.










share|improve this question























  • Well I've never seen anybody try to do this before. I really don't know. If you can point to a specific point where it goes wrong people might be able to help you better.

    – mpkorstanje
    Jan 3 at 16:53











  • The point it goes wrong is that it cannot call the glue codes inside the woven dependency. It says the step is undefined. It cant find methods in it. If I remove the woven dependency in aspectj plugin, I can easily access point cuts inside my project. I want a way to weave the dependency and use its contents.

    – MagicBeans
    Jan 4 at 5:07













  • When you say It says the step is undefined this means that Cucumber can't find your step. You'll have to work out why this no longer works after weaving. I believe MethodScanner would be a good place to start: github.com/cucumber/cucumber-jvm/blob/master/java/src/main/java/…

    – mpkorstanje
    Jan 4 at 16:06






  • 1





    This setup is way too complex to expect to get an answer here without providing an MCVE reproducing the problem, ideally on GitHub. If you do provide one, I will take a look.

    – kriegaex
    Jan 6 at 3:08














0












0








0








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.










share|improve this question














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.







cucumber aop aspectj load-time-weaving compile-time-weaving






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 3 at 13:48









MagicBeansMagicBeans

49213




49213













  • Well I've never seen anybody try to do this before. I really don't know. If you can point to a specific point where it goes wrong people might be able to help you better.

    – mpkorstanje
    Jan 3 at 16:53











  • The point it goes wrong is that it cannot call the glue codes inside the woven dependency. It says the step is undefined. It cant find methods in it. If I remove the woven dependency in aspectj plugin, I can easily access point cuts inside my project. I want a way to weave the dependency and use its contents.

    – MagicBeans
    Jan 4 at 5:07













  • When you say It says the step is undefined this means that Cucumber can't find your step. You'll have to work out why this no longer works after weaving. I believe MethodScanner would be a good place to start: github.com/cucumber/cucumber-jvm/blob/master/java/src/main/java/…

    – mpkorstanje
    Jan 4 at 16:06






  • 1





    This setup is way too complex to expect to get an answer here without providing an MCVE reproducing the problem, ideally on GitHub. If you do provide one, I will take a look.

    – kriegaex
    Jan 6 at 3:08



















  • Well I've never seen anybody try to do this before. I really don't know. If you can point to a specific point where it goes wrong people might be able to help you better.

    – mpkorstanje
    Jan 3 at 16:53











  • The point it goes wrong is that it cannot call the glue codes inside the woven dependency. It says the step is undefined. It cant find methods in it. If I remove the woven dependency in aspectj plugin, I can easily access point cuts inside my project. I want a way to weave the dependency and use its contents.

    – MagicBeans
    Jan 4 at 5:07













  • When you say It says the step is undefined this means that Cucumber can't find your step. You'll have to work out why this no longer works after weaving. I believe MethodScanner would be a good place to start: github.com/cucumber/cucumber-jvm/blob/master/java/src/main/java/…

    – mpkorstanje
    Jan 4 at 16:06






  • 1





    This setup is way too complex to expect to get an answer here without providing an MCVE reproducing the problem, ideally on GitHub. If you do provide one, I will take a look.

    – kriegaex
    Jan 6 at 3:08

















Well I've never seen anybody try to do this before. I really don't know. If you can point to a specific point where it goes wrong people might be able to help you better.

– mpkorstanje
Jan 3 at 16:53





Well I've never seen anybody try to do this before. I really don't know. If you can point to a specific point where it goes wrong people might be able to help you better.

– mpkorstanje
Jan 3 at 16:53













The point it goes wrong is that it cannot call the glue codes inside the woven dependency. It says the step is undefined. It cant find methods in it. If I remove the woven dependency in aspectj plugin, I can easily access point cuts inside my project. I want a way to weave the dependency and use its contents.

– MagicBeans
Jan 4 at 5:07







The point it goes wrong is that it cannot call the glue codes inside the woven dependency. It says the step is undefined. It cant find methods in it. If I remove the woven dependency in aspectj plugin, I can easily access point cuts inside my project. I want a way to weave the dependency and use its contents.

– MagicBeans
Jan 4 at 5:07















When you say It says the step is undefined this means that Cucumber can't find your step. You'll have to work out why this no longer works after weaving. I believe MethodScanner would be a good place to start: github.com/cucumber/cucumber-jvm/blob/master/java/src/main/java/…

– mpkorstanje
Jan 4 at 16:06





When you say It says the step is undefined this means that Cucumber can't find your step. You'll have to work out why this no longer works after weaving. I believe MethodScanner would be a good place to start: github.com/cucumber/cucumber-jvm/blob/master/java/src/main/java/…

– mpkorstanje
Jan 4 at 16:06




1




1





This setup is way too complex to expect to get an answer here without providing an MCVE reproducing the problem, ideally on GitHub. If you do provide one, I will take a look.

– kriegaex
Jan 6 at 3:08





This setup is way too complex to expect to get an answer here without providing an MCVE reproducing the problem, ideally on GitHub. If you do provide one, I will take a look.

– kriegaex
Jan 6 at 3:08












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54023583%2fusing-aspectj-with-cucumber%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54023583%2fusing-aspectj-with-cucumber%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

ts Property 'filter' does not exist on type '{}'

mat-slide-toggle shouldn't change it's state when I click cancel in confirmation window