How to use HTMLTestRunner to create a test report

Asked by BenjaminWang on 2018-06-29

@ Raiman

sorry
I’ve tried a month in vain to look for the solutions of similar problems.
I’m still a newbie in many ways.
I’d like to ask about how to use HTMLTestRunner to create a test report.

Version:sikulixIDE 1.1.2
OS:Windows 10

Suppose there are 3 files A.sikuli, B.sikuli and C.sikuli under folder c://sikuli.

The content of file A.sikuli is

click("image a")
if not exists ("image a-2",5)
    popup("fail message a")

The content of file B.sikuli is

click("image b")
if not exists ("image b-2",5)
    popup("fail message b")

The content of file C.sikuli is

click("image c")
if not exists ("image c-2",5)
    popup("fail message c")

How to modify the contents of A.sikuli, B.sikuli and C.sikuli
to create a D.sikuli file to import HTMLTestRunner.
Then use D.sikuli to execute the test result of A.sikuli, B.sikuli and C.sikuli one time only.
Suppose the route to create the report is also under c://sikuli.

I need the modified full codes of each A.sikuli, B.sikuli, C.sikuli and D.sikuli.
Please help me, thank you so much.

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2018-07-10
Last query:
2018-07-10
Last reply:
2018-06-29
Best RaiMan (raimund-hocke) said : #1

This is a tested example:

import unittest
import HTMLTestRunner

testReport = file(os.path.join(getParentPath(), 'testReport.html'), 'wb')
# the report file will be in the same folder as the script
# open with a browser

class MyTest(unittest.TestCase):
  def setUp(self):
    print "MyTest: setUp"

  def testA(self):
    print "running testA"
    click("imageA")
    assert exists("imageA2",5)

  def testB(self):
    print "running testB"
    click("imageB")
    assert exists("imageB2",5)

  def testC(self):
    print "running testC"
    click("imageC")
    assert exists("imageC2",5)

  def tearDown(self):
    print "MyTest: tearDown"

testSuite = unittest.TestLoader().loadTestsFromTestCase(MyTest)
runner = HTMLTestRunner.HTMLTestRunner(stream = testReport)
runner.run(testSuite)

Besides copying and pasting other people's code snippets, I recommend to learn about the Python unittest feature, that is the background on that HTMLTestRunner works.

BenjaminWang (evilgamesx4) said : #2

Thanks RaiMan, that solved my question.