sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #42150
Re: [Question #614515]: Sikuli xmlrunner/htmlrunner with try catch in test cases
Question #614515 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/614515
Status: Open => Answered
RaiMan proposed the following answer:
Since you are really ambitious and willing to learn ;-)
... here is a working example with all your aspects:
- I am using the bundled XMLTestRunner
- the log and xml files are written to the folder where the script is located
- everything in one script for demo only - you might push things to subscripts as needed (test cases, helpers, ...)
- to tell UnitTest (and hence XMLTestRunner) about test case success you have to use appropriate assert statements
from sikuli import *
import unittest
import logging
import traceback
import XMLTestRunner1
logFile = os.path.join(getParentPath(), "log.txt")
xmlFile = os.path.join(getParentPath(), "mytest.xml")
def logWrite(text):
file = open(logFile, 'a')
file.write(text + "\n")
file.close()
def logReset():
file = open(logFile, 'w')
file.close()
class MyTest(unittest.TestCase):
def setUp(self):
logWrite("Starting")
wait(1)
def tearDown(self):
logWrite("Ending")
def test1(self):
try:
1/0 # gives runtime exception
except:
var = traceback.format_exc()
logWrite(var)
assert false
logReset()
suite = unittest.TestLoader().loadTestsFromTestCase(MyTest)
result = XMLTestRunner1.XMLTestRunner(file(xmlFile, "w")).run(suite)
--
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.