Facing issue while taking screenshots for failed cases using Sikulix1.1.1

Asked by Milind Warade on 2018-03-13

@Raiman:

I am facing issue while taking screenshots for failed cases.
I have went through : https://answers.launchpad.net/sikuli/+question/259679

Code-
from sikuli import *
import unittest
import sys
_path = r"D:\Sikulix\HTMLTestRunner"
sys.path.append(_path)
import HTMLTestRunner

class TestDemo(unittest.TestCase):
    def testA(self):
        click("1520869861593.png")

    def testB(self):
        click("1520958741130.png") //This is wrong image

class TestDemo2(unittest.TestCase):
    def testC(self):
        click("1520869861593.png")
    def testD(self):
        click("1520869861593.png")

def suite():
    suite = unittest.TestSuite()
    # TestDemo
    suite.addTest(TestDemo('testA'))
    suite.addTest(TestDemo('testB'))
    # TestDemo2
    suite.addTest(TestDemo2('testC'))
    suite.addTest(TestDemo2('testD'))

    return suite

suite = unittest.TestLoader().loadTestsFromTestCase(TestDemo)
outfile = open("D:\\Sikulix\\HTMLTestRunner\\report.html", "w") # path to report folder
runner = HTMLTestRunner.HTMLTestRunner(stream=outfile, title=' Test project', description='Test Report' )
runner.run(suite)

I have taken htmltestrunner.py from Sikulix 1.1.1 (\\sikulix\Lib\htmltestrunner.py)
 where below part is there for taking screenshot of failed cases-

     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')

    # added by RaiMan
    def generateTestScreenshot(self, test):
        imgdir = ''
        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

But when I am executing test suite, it was not taking screenshots of failed cases. Please help me in this case.

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2018-03-13
Last reply:
2018-03-14
RaiMan (raimund-hocke) said : #1

you have to use assert, to signal failed cases

try:
   click(someImage)
   assert true
except:
   assert false

Milind Warade (warademilind) said : #2

Thanks Raiman. Will check.

Can you help with this problem?

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

To post a message you must log in.