-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ability to embed attachments and make them available on TestNG XML report #2171
Comments
@bitcoder why not build a custom XML report by implementing |
hi @krmahadevan , well that could be a possibility; however, it would be mostly duplicating the current XML Reporter and extend current TestNG API in order to support adding attachments on the result object; don't you think having this built-in makes more sense, as it broadens its usage? Besides, this is not really something specific for a given user; I see this as something quite valuable and common amongst users. |
@bitcoder - I hear you. There are many such generic use cases that can be embedded into TestNG. But I think that's perhaps not what TestNG is expected to do. Instead it's expected to enable customisation. Would you be interested in submitting a PR that lets people customise the current XML report ? That way there won't be any duplication of code etc and specifics such as addition of attachments etc can still live and be maintained outside of TestNG. @juherr thoughts? |
I agree. The team is not big enough to support all needs. Instead, we are trying to allow "plugins". About reporter, a lot exists and maybe one of them is already doing what you expect: https://github.com/cbeust/testng/wiki/3rd-party-extensions#reporters--loggers |
thanks @juherr , I've went over them and I don't think any supports it though. |
@bitcoder It depends on the size of the PR :) |
@bitcoder - Do you mind showing us how the end report would look like (which includes the attachments embedded) ? That way, we can try figuring out how do we enrich |
@krmahadevan , sure :) What many users would love to have is something like what is possible with Cucumber, which is able to embed attachments, such as screenshots, at each step/gherkin sentence level. |
@bitcoder - I was hoping that you would share the contents of how the xml (the one which has screenshots embedded into it) should look like ? |
oh @krmahadevan , I was thinking more on the end result :) <test-method status="FAIL" signature="CanAddNumbersFromGivenData(int, int, int)[pri:0, instance:com.xpand.java.CalcTest@36d4b5c]" name="CanAddNumbersFromGivenData" duration-ms="1" started-at="2018-03-07T14:42:27Z" data-provider="ValidDataProvider" finished-at="2018-03-07T14:42:27Z">
<attachments>
<attachment>
<name>screenshot1.png</name>
<description>whatever</description>
<rawcontent>...base64 enconded content...</rawcontent>
</attachment>
...
</attachments>
...
</test-method> Eventually, it could be more flexible to also support remote references instead of embedded content. |
Closes testng-team#2171 In order for one to be able to generate their own customized version of testng-results.xml without a lot of code duplication, the following should be done. 1. Extend org.testng.reporters.XMLReporter 2. Override “fileName()” method and provide your own file name. 3. Override “addCustomTagsFor()” method and plugin your implementation which will add one or more tags to the xml file. 4. Add the newly created class as one of the listeners via “@listeners” annotation or via “<listeners>” tag or via SPI approach. For a sample of how the customized listener can look like, take a look at the sample that resides in “src/test/java/test/reports/issue2171/MyExampleListener.java”
Closes testng-team#2171 In order for one to be able to generate their own customized version of testng-results.xml without a lot of code duplication, the following should be done. 1. Extend org.testng.reporters.XMLReporter 2. Override “fileName()” method and provide your own file name. 3. Override “addCustomTagsFor()” method and plugin your implementation which will add one or more tags to the xml file. 4. Add the newly created class as one of the listeners via “@listeners” annotation or via “<listeners>” tag or via SPI approach. For a sample of how the customized listener can look like, take a look at the sample that resides in “src/test/java/test/reports/issue2171/MyExampleListener.java”
Closes #2171 In order for one to be able to generate their own customized version of testng-results.xml without a lot of code duplication, the following should be done. 1. Extend org.testng.reporters.XMLReporter 2. Override “fileName()” method and provide your own file name. 3. Override “addCustomTagsFor()” method and plugin your implementation which will add one or more tags to the xml file. 4. Add the newly created class as one of the listeners via “@listeners” annotation or via “<listeners>” tag or via SPI approach. For a sample of how the customized listener can look like, take a look at the sample that resides in “src/test/java/test/reports/issue2171/MyExampleListener.java”
thanks @krmahadevan for your work!
For this, however, I would need to change the ITestResult and also the implementation to have new methods. Looking forward for your comments and also from @juherr :) |
On the following of my previous comment, namely related with b), on a given Test method we could do something like:
and then process it in the report class side. The only (very minor) drawback that I see after implementing it is that the attribute would also be logged in the tag as addTestResultAttributes() iterates over it. |
@bitcoder - A few things. Did you take a look at the PR that I raised to fix this issue ? If not, please start from the changeset #2174 The commit message has some details in terms of the general customization support. You can also take a look at the sample custom listener that I built for testing purposes to give you an idea on how to tweak this here. I still dont think attachments support needs to be part of TestNG and it can very well reside as customizations which reside outside of the codebase. If storing custom values via attributes on an ITestResult object is not something that you would want, then you can very well maintain your own map of key/value pairs wherein the keys represent the ITestResult object and the values represent whatever you would want as additional attributes. Now this map you could query in your child class of |
hi @krmahadevan , yes I did look at it. I made my code on top of it in order to extend the builtin XML report capabilities (https://github.com/bitcoder/xray-testng-extensions/blob/master/README.md) |
TestNG Version
7.0
Expected behavior
It should be possible to attach a file (e.g. screenshot) and make it available in the TestNG XML output report, preferably embedded.
This would be great for tools that parse TestNG results from the XML report file and showing them, along with relevant attachments/screenshots) in test management tools (e.g. Xray for Jira).
Actual behavior
TestNG XML report schema seems to not support attachments at all (either as references or embedded).
Note: I'm unsure if TestNG supports adding attachments at all in its public API.
The text was updated successfully, but these errors were encountered: