How to use HTMLTestRunner to create a test report

Asked by BenjaminWang

@ 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:
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

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.

Revision history for this message
BenjaminWang (evilgamesx4) said :
#2

Thanks RaiMan, that solved my question.

Revision history for this message
Thuraisingam (glardz98) said :
#3

when i put this line :

import unittest
import HTMLTestRunner

i have this error message :

 Error in file 'C:\Users\xx\Desktop\rainman_repport.sikuli.robot\rainman_repport.robot': Importing test library 'C:\Users\G5999988\Desktop\rainman_repport.sikuli.robot\LoginLibrary.py' failed: NameError: name 'unittest' is not defined
Traceback (most recent call last):
  File "C:\Users\xx\Desktop\rainman_repport.sikuli.robot\LoginLibrary.py", line 8, in <module>
    class MyTest(unittest.TestCase):
PYTHONPATH:
  C:\Users\xx\Desktop\rainman_repport.sikuli
  C:\Users\xx\AppData\Roaming\Sikulix\Lib
  C:\Users\xx\Desktop\New folder\Lib
  C:\Users\xx\Desktop\New folder\sikulix.jar\Lib
  __classpath__
  __pyclasspath__/
  C:\Users\xx\Desktop
CLASSPATH:
  C:\Users\xx\Desktop\New folder\sikulix.jar

do you have an idea ?

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

I do not understand, why you need unittest and HTMLTestRunner when working with Robotframework ????

the error:
the respective modules are not locatable on sys.path.

Revision history for this message
Thuraisingam (glardz98) said :
#5

yes i forgot, thanks

Revision history for this message
Thuraisingam (glardz98) said :
#6

currently i want test clic but i have this error :

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

what error?

what are you doing? code snippet please!

Revision history for this message
Thuraisingam (glardz98) said :
#8

runScript("""
robot
#*** Variables ***
#(charge library and initialise function, see below _
*** Settings ***
Library ./inline/LoginLibrary
Test Teardown stop firefox
#(name of each test)
*** Test Cases ***
titi toto
""")
class LoginLibrary(object):
  #def start_firefox_and_goto_testsite(self, page):
    #popup("start_firefox_and_goto_testsite")
  def stop_firefox(self):
    popup("toto")
    doubleClick("1558357917927.png")