HTMLTestRunner: Failure Screenshots with timestamp

Asked by sathya

@Raiman:

I am using your modified version of html test runner which takes screenshots on failures.
The thing is screenshots are replaced and overwritten on every run of the sikuli report.

Can you help me to keep the failure screenshot names unique with a timestamp or something? so that the previous screenshots will not be overwritten and i can keep those for future reference.

    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)))
        if self.verbosity > 1:
            sys.stderr.write('F ')
            sys.stderr.write(str(test))
            sys.stderr.write('\n')
        else:
            sys.stderr.write('F')

Do i have to make any modifications in html test runner?

   # added by RaiMan
    def generateTestScreenshot(self, test):
        imgdir = self.dirTestScreenshots
        imgpath = ''
        if imgdir:
            x = str(test).split()
            tf = x[0]
            tc = x[1].split('.')[1][:-1]
            imgpath = os.path.join(imgdir, "%s-%s.png"%(tc, tf))
   shutil.move(capture(SCREEN), imgpath)
        return imgpath

Thanks in Advance!!

Cheers :)

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

yes, you might modify the function generateTestScreenshot like this:

   # added by RaiMan
    def generateTestScreenshot(self, test):
        imgdir = self.dirTestScreenshots
        imgpath = ''
        if imgdir:
            x = str(test).split()
            tf = x[0]
            tc = x[1].split('.')[1][:-1]
            tt = int(time.time()*100)
            imgpath = os.path.join(imgdir, "%s-%s-%s.png"%(tc, tf, tt))
            shutil.move(capture(SCREEN), imgpath)
        return imgpath

which will add a timestamp to the filename (stepping is 0.01 seconds, which should be sufficient)

Revision history for this message
sathya (bksathyamoorthy) said :
#2

Thanks RaiMan, that solved my question.

Revision history for this message
sathya (bksathyamoorthy) said :
#3

@Raiman:

Sorry for the delayed response.

This worked like a charm :)
Thanks and a Happy New Year !!