/**
* This script attaches the screenshot of a failing Selenium test to the failed test's description.
* The screenshot is preserved after the workspace gets cleared by a new build.
*/
def attachScreenshotToFailingTests() {
def channel = manager.build.workspace.channel;
def workspace = manager.build.workspace.toString();
def testResults = manager.build.testResultAction;
if (testResults == null) {
// No tests were run in this build, nothing left to do.
return;
}
// Go through each failed test in the current build.
def failedTests = testResults.getFailedTests();
for (def failedTest : failedTests) {
// Compute the test's screenshot file name.
def testClass = failedTest.getClassName();
def testSimpleClass = failedTest.getSimpleName();
def testExample = failedTest.getName();
def suiteResultFile = failedTest.getSuiteResult().getFile();
if (suiteResultFile == null) {
// No results available. Go to the next test.
continue;
}
// Compute the screenshot's location on the build agent.
def targetFolderPath = new hudson.FilePath(channel, suiteResultFile).getParent().getParent();
// The screenshot can have 2 possible file names and locations, we have to look for both.
// Selenium 1 test screenshots.
def imageAbsolutePath1 = new hudson.FilePath(targetFolderPath, "selenium-screenshots/${testClass}-${testExample}.png");
// Selenium 2 test screenshots.
def imageAbsolutePath2 = new hudson.FilePath(targetFolderPath, "screenshots/${testSimpleClass}-${testExample}.png");
// Determine which one exists, if any.
def imageAbsolutePath = imageAbsolutePath1.exists() ? imageAbsolutePath1 : (imageAbsolutePath2.exists() ? imageAbsolutePath2 : null);
// If the screenshot exists...
if (imageAbsolutePath != null) {
// Build a base64 string of the image's content.
def imageDataStream = imageAbsolutePath.read();
byte[] imageData = IOUtils.toByteArray(imageDataStream);
def imageDataString = "data:image/png;base64," + DatatypeConverter.printBase64Binary(imageData);
def testResultAction = failedTest.getParentAction();
def testResult = testResultAction.getResult();
// Build a description HTML to be set for the failing test that includes the image in Data URI format.
def description = "<h3>Screenshot</h3>";
description += "<a href=\"" + imageDataString + "\"><img style=\"width: 800px\" src=\"" + imageDataString + "\" /></a>";
// Set the description to the failing test and save it to disk.
testResultAction.setDescription(failedTest, description);
// Note: the owner field is marked as deprecated and it might go away. It should be replaced by an instance of Run in the future,
// but FTM, I do not know how to access it. For the future, in case descriptions start not getting stored, this might cause it.
testResultAction.owner.save();
}
}
}
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/15ee3c93-8849-492a-8355-3b2e11c05ada%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
> To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/15ee3c93-8849-492a-8355-3b2e11c05ada%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
> Dick Ginga
> Build Engineer
> rgi...@disruptorbeam.com
>
>
> --
> You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/IJYJx6hXhBc/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAL3PpaUykt14Nrg1GuhYqy7H0Aaq%3D4QL42YO3%2B%3DQZq--%2B4H4iA%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/D35787B8-4085-4EDA-94CE-BBE145D577CA%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
> > To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
> > To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/15ee3c93-8849-492a-8355-3b2e11c05ada%40googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
> >
> >
> >
> > --
> > Dick Ginga
> > Build Engineer
> > rgi...@disruptorbeam.com
> >
> >
> > --
> > You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
> > To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/IJYJx6hXhBc/unsubscribe.
> > To unsubscribe from this group and all its topics, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
> > To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAL3PpaUykt14Nrg1GuhYqy7H0Aaq%3D4QL42YO3%2B%3DQZq--%2B4H4iA%40mail.gmail.com.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/D35787B8-4085-4EDA-94CE-BBE145D577CA%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
> Dick Ginga
> Build Engineer
> rgi...@disruptorbeam.com
>
>
> --
> You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/IJYJx6hXhBc/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAL3PpaWcZqJeHQ%2B5eGWid4KHM1QYUxT66Vzwx9C0o4ZJgvVgmg%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/D55E2C5F-29A8-4654-B984-A7079262D6FB%40gmail.com.
manager.addShortText("${APPLY_TAG}")
http://MY_HOST/Jenkins/job/MY_PIPELINE_JOB/pipeline-syntax/globals