allure-framework / allure-cucumberjvm

Deprecated, use https://github.com/allure-framework/allure-java instead
Apache License 2.0
16 stars 13 forks source link

Attachment create and exist in folder allure-results but not present in Report #41

Closed shapovalovei closed 7 years ago

shapovalovei commented 7 years ago

I implements ITestListener and @Override onTestFailure(). In this function i take screenshot and attache him in report

@Attachment(value = "{0}", type = "image/png")
    public static byte[] attachScreenshot(String name) {
        return ((TakesScreenshot) DriverFactory.getDriver()).getScreenshotAs(OutputType.BYTES);
    }

In folder "allure-results" I see this screenshot. but In report attachment is empty

screen shot 2017-02-08 at 12 32 58 screen shot 2017-02-08 at 12 33 05

this is my pom.xml file: https://gist.github.com/shapovalovei/8419be48a69f3991874796830dcd205c

@clicman can you help me ?

Эту же проблему мне пытались помочь решить на форуме

clicman commented 7 years ago

Okay, to make screenshots you should extends of AllureReporter like this:

public class AllureReporterExt extends AllureReporter {
    @Override
    public void result(Result result) {
        if ("failed".equals(result.getStatus())) {
            attachScreenshot();
        }
        super.result(result);
    }

    @Attachment(type = "image/png")
    public static byte[] attachScreenshot() {
        return ((TakesScreenshot) DriverFactory.getDriver()).getScreenshotAs(OutputType.BYTES);
    }

}

And update your pom.xml to use new reporter: -Dcucumber.options="--plugin ru.yandex.qatools.allure.cucumberjvm.AllureReporterExt"

Do not close this issue, I'll implement handy callback which will make extending unnecessary.

shapovalovei commented 7 years ago

dosent work. I change my listener class

public class TestListener extends AllureReporter {
    private Log log = LogFactory.getLog(this.getClass());
    Allure lifecycle = Allure.LIFECYCLE;

    @Override
    public void result(Result result) {
        if ("failed".equals(result.getStatus())) {
            attachScreenshot("fail");
        }
        super.result(result);
    }

    @Attachment(value = "{0}", type = "image/png")
    public static byte[] attachScreenshot(String name) {
        return ((TakesScreenshot) DriverFactory.getDriver()).getScreenshotAs(OutputType.BYTES);
    }

}

Update pom.xml

<argLine>
-javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar
-Dcucumber.options="--plugin ru.yandex.qatools.allure.cucumberjvm.AllureReporterExt" 
</argLine>

After run test a have exceptions

[Error] java.lang.NullPointerException
        at cucumber.api.testng.AbstractTestNGCucumberTests.features(AbstractTestNGCucumberTests.java:29)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104)
        at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:55)
        at org.testng.internal.MethodInvocationHelper.invokeMethodNoCheckedException(MethodInvocationHelper.java:45)
        at org.testng.internal.MethodInvocationHelper.invokeDataProvider(MethodInvocationHelper.java:111)
        at org.testng.internal.Parameters.handleParameters(Parameters.java:509)
        at org.testng.internal.Invoker.handleParameters(Invoker.java:1293)
        at org.testng.internal.Invoker.createParameters(Invoker.java:1020)
        at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1110)
        at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
        at org.testng.TestRunner.privateRun(TestRunner.java:756)
        at org.testng.TestRunner.run(TestRunner.java:610)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:387)
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
        at org.testng.SuiteRunner.run(SuiteRunner.java:289)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
        at org.testng.TestNG.runSuites(TestNG.java:1133)
        at org.testng.TestNG.run(TestNG.java:1104)
        at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:281)
        at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:75)
        at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:121)
        at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)

@clicman My be I wrong ?

baev commented 7 years ago

That is how testNG works. Test case is finished before you saving an attachment, so Allure can't add it to test case result. That is why you can find an attachment in results folder, and why it is missed in the report

clicman commented 7 years ago

Ohh. You're using testNG. My solution tested on junit only. Could you push sample testNG project what reproduces this error? I will try to investigate issue with testNG.

clicman commented 7 years ago

https://github.com/clicman/TestNGScreensProof is how to make screenshot with allure, cucumber and testNG.

shapovalovei commented 7 years ago

@clicman Thank you very match for help. Worked of me : https://github.com/clicman/TestNGScreensProof

clicman commented 7 years ago

1.6.2 is released (wait some time to get in on central) Details: https://github.com/allure-framework/allure-cucumberjvm/releases/tag/untagged-36b97360440ee2d42267

sargissargsyan commented 6 years ago

Can you please post here the solution that worked for you with TestNG