How to append saved screenshot to htmltestrunner report

Asked by JP

Hi,

I have a working htmltestrunner report I want to find out how do I display the screenshot I saved on a failed test? I think I am using the htmltestrunner with the screenshot for failed tests but when I run my code it doesn't seem to display the screenshot on the report.

Here is the code from the htmltestrunner:

   def addFailure(self, test, err):
        self.failure_count += 1
        TestResult.addFailure(self, test, err)
        _, _exc_str = self.failures[-1]
        output = self.complete_output()
        self.result.append((1, test, output, _exc_str, self.generateTestScreenshot(test))) # modified by RaiMan
        if self.verbosity > 1:
            sys.stderr.write('F ')
            sys.stderr.write(str(test))
            sys.stderr.write('\n')
        else:
            sys.stderr.write('F')

My script:

from sikuli import *
import sys
import HTMLTestRunner
import unittest
import shutil

class ReturnToHomePage(unittest.TestCase):

    def testA_ReturnHome(self):
        click(Location(300, 247))
        wait(3)
        click(Location(425, 489))
        wait(5)
        click(Location(92, 326))
        wait(3)
        screenshotsDir = "C:/Sikuli/ReturnHome.sikuli"
        img = capture(Region(3,5,1021,760))
        shutil.move(img, os.path.join(screenshotsDir, "1.png"))
        assert exists(Images.homePage)

suite = unittest.TestLoader().loadTestsFromTestCase(ReturnToHomePage)
outfile = open('C:\jenkins\workspace\UAT\TestReport.html', 'w')
myrunner = HTMLTestRunner.HTMLTestRunner(stream=outfile, title='', description ='' )
myrunner.run(suite)

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
JP (jpergega) said :
#1

I have amended my code like this but still doesn't seem to append any screenshot on failed test case with the HTMLTestRunner:

#from sikuli import *
import sys
import HTMLTestRunner
import unittest

class ReturnToHome(unittest.TestCase):

    def setUp(self):
        click(Images.chrome)
        wait(5)

    def test_aReturnToHome(self):
        click(Location(300, 247))
        wait(3)
        if exists(Images.xl): #it will fail becuase is not present
            assert True, "Image found"
        else:
            assert False, "Image not found"

    def tearDown(self):
        print 'Test Failed'

suite = unittest.TestLoader().loadTestsFromTestCase(ReturnToHome)
outfile = open('C:\jenkins\workspace\ReturnToHome\TestReport.html', 'w')
myrunner = HTMLTestRunner.HTMLTestRunner(stream=outfile, title='Return to Home', description ='' )
myrunner.run(suite)

I'm using the HTMLTesteRunner located in the AppData folder and it is the version modified by Raiman.

Does anyone have any idea why is not appending the screenshot?

Thank you

Revision history for this message
Launchpad Janitor (janitor) said :
#2

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
RaiMan (raimund-hocke) said :
#3

Still under investigation

Revision history for this message
RaiMan (raimund-hocke) said :
#4

You have to specify a directory, where the screenshots are to be stored (automatically taken inside).

myrunner = HTMLTestRunner.HTMLTestRunner(stream=outfile, title='', description ='' , dirTestScreenshots='someFolder')

Only with this parameter given, the feature is switched on.

Can you help with this problem?

Provide an answer of your own, or ask JP for more information if necessary.

To post a message you must log in.