Facing problem in generating reports through HTMLTestRunner

Asked by sravani

Can you please give a simple example for generating reports through HTMLTestRunner
A small example like, opening the calculator, do small addition and close it.
I have tried with all the answers you provided in last queries(asked by other users) and studied the document suggested by you:
https://docs.python.org/2/library/unittest.html
I hope that you give an example for generating reports, as I’m a tester so having less knowledge in coding that’s why I didn’t get much knowledge from the doc provided by you but I tried the script. Here is my script.

import unittest
import HTMLTestRunner

class Test(unittest.TestCase):
    def setUp(self):
        openApp("system32\\calc.exe")
        wait("1404975041498-1.png")
    def tearDown(self):
        closeApp("system32\\calc.exe")

    def testA(self):
        click("1404985458315.png")
        click("1404985487526.png")
        click("1404985502302.png")
        click("1404985577471.png")
        assert exists("1404985559335.png")
        print "Test case Pass"

    def testB(self):
        assert not exists("1404985559335.png")
        print "Test case Fail"
suite = unittest.TestLoader().loadTestsFromTestCase(Test)
outfile = open("PATH OF HTML FILE", "w")
runner = HTMLTestRunner.HTMLTestRunner(stream=outfile, title='Test Report', description='This is demo' )
runner.run(suite)

with this script I’m unable to generate the report

My questions and issues I’m facing

Question1:
When I used “import HTMLTestRunner” I’m getting the following error message:
ImportError ( No module named HTMLTestRunner )
 For this the solutions that I have tried are:
I have placed the HTMLTestRunner.py file in the same directory where sikuli.sikuli script file is residing.
Also I have placed the HTMLTestRunner.py file in a folder where ‘sikuli-setup.jar file is residing
Note: when I opened the HTMLTestRunner.py file its opening in note pad.

Question 2:
What is unittest in ‘import unittest’ statement
Was ‘unittest’ means another script.
Will this statement work in Sikuli IDE even if we are not using python/jython

Question 3:
For storing results the process which I’m following is
Taking a Notepad converting it to html file and giving this file properties in output file
i.e. outfile = open("Path of File", "w")

was this process correct?

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

?? 1.
HTMLTestRunner.py
must be in a folder Lib (might have to be created) in the folder where you have the SikuliX setup stuff and the jar files.
Otherwise you have to adjust sys.path.

?? 2.
import unittest
imports the standard Python/Jython unit test module, that is needed in the rest of the script (unittest. …)

--- Will this statement work in Sikuli IDE even if we are not using python/jython
of course only valid for python/jython scripts

?? 3.
You do not need to prepare a file, since this will be created in the script by
outfile = open("Path of File", "w")

Revision history for this message
sravani (sranu3333) said :
#2

Will "import unittest" statement work in Sikuli IDE even if i don't install Python in my PC.

Can you please give a simple example for generating reports through HTMLTestRunner
A small example like, opening the calculator, do small addition and close it.

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

--- Will "import unittest" statement work in Sikuli IDE even if i don't install Python in my PC.
SikuliX setup for SikuliX's IDE comes with the needed Jython bundled (jars: sikuli-ide, sikuli-script, sikulix)
So no need to have Python on the machine, which would not work anyway with SikuliX, since Jython is needed.

--- Example:
here you are
https://dl.dropboxusercontent.com/u/42895525/HTMLTestRunnerExample.zip

Revision history for this message
sravani (sranu3333) said :
#4

Thank you very much RaiMan , the code which i written is working fine as soon as the HTMLTestRunner.py problem is solved.
Thank you very much once again.

Revision history for this message
sravani (sranu3333) said :
#5

Thanks RaiMan, that solved my question.