I’ve gone through various tutorials and Stack Overflow posts and understand that Selenium can output XML test results in a way that Hudson can read/report them in HTML format.
What I don’t understand is the syntax to use in Python, to get the results to look something like:
Testcase_LoginPage.VerifyButton1Present fail
Testcase_LoginPage.VerifyButton2Present pass
Currently, when I drill down the results in Hudson, they won’t be formatted in a useful way as I described above, and also it will report that it only ran ONE test, even though it ran multiple assert Tests:
Traceback (most recent call last):
File “D:\Temp\1TestingApps\Selenium\Scripts\SampleScripts\SamCodeSample\test\SOreports.py”, line 22, in tearDown
self.assertEqual([], self.verificationErrors)
AssertionError: Lists differ: [] != [‘Sign Up button issue2’]
Second list contains 1 additional elements.
First extra element 0:
Sign Up button issue2
- []
- [‘Sign Up button issue2’]
Ran 1 test in 13.610s
FAILED (errors=1)
Generating XML reports…
Code is below. Thanks in advance for the help!
from selenium import selenium
import unittest, xmlrunner, os, re
class Demo(unittest.TestCase):
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", 4444, "*chrome", "https://workflowy.com/")
self.selenium.start()
def test_hh(self):
sel = self.selenium
sel.open("/accounts/register/")
try: self.assertEqual("Sign Up FAIL", "Sign Up FAIL","Sign Up button issue1")
except AssertionError, e: self.verificationErrors.append(str(e))
try: self.assertEqual("Sign Up FAIL", "Sign Up FAIL1","Sign Up button issue2")
except AssertionError, e: self.verificationErrors.append(str(e))
def tearDown(self):
self.selenium.stop()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
#have to format the code this way as SO is complaining about 'bad indent'
unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'))
I’ve finally figured out how to make the verifications and assertions get reported in a useful format for my needs. The problem is that the default structure of the tests when simply exporting a Selenium IDE recorded script into a Python RC file lacks a lot of detail I needed.
What I changed:
– Placed the Selenium start and stop methods in the Setup and tearDown classes which prevented Selenium from restarting the browser with each newly defined verification/assertion method
– Added error descriptions that include the testcase name via inspect.stack()