Closed rupalJ closed 8 years ago
Hi,
Not sure but it might be related to an issue I had before.
If you use your own cucumber commandline to kick of the feature files (instead Cucumber runner class see [1]). Then you will run into the NPE because not extent is being set. This is caused by a combination of the ExtentCucumberFormatter having 2 constuctor and Cucumber itself using the first one that matches.
For the CucumberExtentReporter this results in Cucumber using the default constructor instead of one with the File argument.
This all cause the cucumber commandline with the following argument to result in the NPE.
--plugin com.cucumber.listener.ExtentCucumberFormatter: <your output file>
I fixed this in my own project by wrapping the cucumber CLI Main method in my own and CLI Main method and call one of the static initiateExtentCucumberFormatter methods.
This is not best fix, but helped me to proceed without upstream changes. I can see 2 solutions to fix this:
1) Change the order in which Cucumber looks for constructor. Default constructor should be last instead of first.
2) Fix ExtentCucumberFormatter to remove the default constructor and have all static initiateExtentCucumberFormatter use the existing/old File arg constructor.
Hope this helps.
Regards,
Misl
[1] https://github.com/email2vimalraj/CucumberExtentReporter
From: rupalJ notifications@github.com Sent: 11 August 2016 11:03 To: email2vimalraj/CucumberExtentReporter Subject: [email2vimalraj/CucumberExtentReporter] Nll Pointer Exception - via build.gradle file (#19)
Hi Vimal,
I have a java/cucumber/gradle project setup where I am setting my cucumber configurations and plugins from the build.gradle file.
When I try to add the plugin within my build.gradle file then I am getting a null pointer exception; However when I execute my cucumber files outside the build.gradle file (i.e how you have done your setup in your example) then the reports work fine.
can you please help me how i can use this plugin via my build.gradle file?
You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/email2vimalraj/CucumberExtentReporter/issues/19, or mute the threadhttps://github.com/notifications/unsubscribe-auth/APPgqv-rJ2XugFtkQU_0suX3hC-t3PDyks5qeuVfgaJpZM4Jh7EF.
This email (including any attachments to it) is confidential, legally privileged, subject to copyright and is sent for the personal attention of the intended recipient only. If you have received this email in error, please advise us immediately and delete it. You are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. Although we have taken reasonable precautions to ensure no viruses are present in this email, we cannot accept responsibility for any loss or damage arising from the viruses in this email or attachments. We exclude any liability for the content of this email, or for the consequences of any actions taken on the basis of the information provided in this email or its attachments, unless that information is subsequently confirmed in writing.
Interesting, never executed tests through Cucumber CLI. Let me try and comment back.
Some additional info:
Have a look at Cucumber-jvm class PluginFactory at
On line 50 you can see CTOR_ARGS being defined with the order in which Formatter constructors are being searched for. Null (no-arg) first and File.class last. These are actually the 2 constructors present in ExtentCucumberFormatter.
On line 96 the actual search for the contructor using the CTOR_ARGS order. The first one found (in our case the no-arg constructor) is being used. Which as stated in my previous email results in a NPE since no extent is being created.
Regards,
Minto
From: VimalRaj Selvam notifications@github.com Sent: 11 August 2016 21:25 To: email2vimalraj/CucumberExtentReporter Cc: Sluis van der, M (Minto); Comment Subject: Re: [email2vimalraj/CucumberExtentReporter] Nll Pointer Exception - via build.gradle file (#19)
Interesting, never executed tests through Cucumber CLI. Let me try and comment back.
You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/email2vimalraj/CucumberExtentReporter/issues/19#issuecomment-239264851, or mute the threadhttps://github.com/notifications/unsubscribe-auth/APPgqqpw4cZmz_wrRTZdKn61b3ejqg3Kks5qe3c0gaJpZM4Jh7EF.
This email (including any attachments to it) is confidential, legally privileged, subject to copyright and is sent for the personal attention of the intended recipient only. If you have received this email in error, please advise us immediately and delete it. You are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. Although we have taken reasonable precautions to ensure no viruses are present in this email, we cannot accept responsibility for any loss or damage arising from the viruses in this email or attachments. We exclude any liability for the content of this email, or for the consequences of any actions taken on the basis of the information provided in this email or its attachments, unless that information is subsequently confirmed in writing.
I ran into the same issue yesterday. Is there a workaround for this?
@chOOnz : Are you facing this issue when using gradle or CLI?
@email2vimalraj I'm facing the issue when using my custom gradle plugin with a custom task which executes cucumber via the commandline. I just add --plugin com.cucumber.listener.ExtentCucumberFormatter
as argument for cucumber and at this point I get the NPE. I'm using the JavaExec
class to run and execute my code. Here a small example:
class CucumberTask extends JavaExec {
boolean extentReport = true
int extentInterval = 1
boolean prettyOutput = true
List<File> features = new ArrayList<>()
List<String> glue = new ArrayList<>()
CucumberTask() {
setMain('cucumber.api.cli.Main')
setEnableAssertions(true)
}
@Override
void exec() {
def args = []
def tags = getTagsArg()
def names = getNamesArg()
if (names != null) {
args << '--name' << names
} else if (tags != null) {
args << '--tags' << tags
}
if (extentReport) {
args << '--plugin' << 'com.cucumber.listener.ExtentCucumberFormatter'
}
if (prettyOutput) {
args << '--plugin' << 'pretty'
}
getGlueArgs().each { args << '--glue' << it }
args += features.findAll{ it.directory }*.absolutePath
super.setArgs(args)
super.exec()
}
I'm pretty sure it's exactly the problem described above.
My workaround is/was overload the cucumber CLI with my own CLI. I used the following code:
public final class TestAutomation {
// ------------------------------------------------------------------------
// Constants
// ------------------------------------------------------------------------
private static final Pattern PATTERN_PLUGIN_DETECT = Pattern.compile("com.cucumber.listener.ExtentCucumberFormatter:(.*)");
private static final String OPTION_PLUGIN = "--plugin";
// ------------------------------------------------------------------------
// Entry point
// ------------------------------------------------------------------------
public static void main(final String[] argv) throws Throwable {
// Properly initialize ExtentCucumberFormatter
final String extendFormatterArg = getExtentCucumberFormatterArg(Arrays.asList(argv));
if (extendFormatterArg != null) {
if (extendFormatterArg.isEmpty()) {
ExtentCucumberFormatter.initiateExtentCucumberFormatter();
} else {
ExtentCucumberFormatter.initiateExtentCucumberFormatter(new File(extendFormatterArg));
}
}
// Pass on to cucumber's own cli.
Main.main(argv);
}
// ------------------------------------------------------------------------
// Private methods
// ------------------------------------------------------------------------
private static String getExtentCucumberFormatterArg(final List<String> args) {
boolean pluginArgument = false;
for (final String arg : args) {
if (OPTION_PLUGIN.equalsIgnoreCase(arg)) {
pluginArgument = true;
continue;
}
if (pluginArgument) {
final Matcher matcher = PATTERN_PLUGIN_DETECT.matcher(arg);
if (matcher.matches()) {
return matcher.group(1).trim();
}
}
pluginArgument = false;
}
return null;
}
}
@misl Thanks for sharing this! I will try it out tomorrow.
@misl Works like a charm. Thanks!
Happy I could help :-)
On 05-10-16 11:12, chOOnz wrote:
@misl https://github.com/misl Works like a charm. Thanks!
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/email2vimalraj/CucumberExtentReporter/issues/19#issuecomment-251622950, or mute the thread https://github.com/notifications/unsubscribe-auth/AB8iTJx04NL2N6Y6v7-zbRMWmmVzFhboks5qw2oKgaJpZM4Jh7EF.
Thanks @misl for helping the community. Appreciate your effort.
Glad I could be of help :-)
This email (including any attachments to it) is confidential, legally privileged, subject to copyright and is sent for the personal attention of the intended recipient only. If you have received this email in error, please advise us immediately and delete it. You are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. Although we have taken reasonable precautions to ensure no viruses are present in this email, we cannot accept responsibility for any loss or damage arising from the viruses in this email or attachments. We exclude any liability for the content of this email, or for the consequences of any actions taken on the basis of the information provided in this email or its attachments, unless that information is subsequently confirmed in writing.
Hi Vimal,
I have a java/cucumber/gradle project setup where I am setting my cucumber configurations and plugins from the build.gradle file.
When I try to add the plugin within my build.gradle file then I am getting a null pointer exception; However when I execute my cucumber files outside the build.gradle file (i.e how you have done your setup in your example) then the reports work fine.
can you please help me how i can use this plugin via my build.gradle file?