I have was able to successfully integrate Bugzilla and Selenium using j2bugzilla API. When I say integrate it means that when executing Selenium tests using TestNG framework and if a test method fails then a defect will be reported in Bugzilla with a screenshot attached for the failure.
Following are the libraries used.
-
1. Selenium Webdriver Java – This library is used to test Application under tests
2. TestNG – This framework is used to execute Selenium with enhanced flexibility. I make special use of TestListenerAdapter where override its method of onTestFailure where all the cool stuff reporting bug and creating screenshot happens
3. j2bugzilla – This API is used to communicate with my Bugzilla instance. It is really cool API using which allows me to do following
-
a. Login to Bugzilla
b. Report Bug
c. Add Attachment
d. Logout of Bugzilla
Following are the steps I followed to achieve above mentioned scenario
-
1. Test Listener: Add a to the class which has Selenium tests for application under test. Class with selenium test looks something like below.
2. Implement the connect Bugzilla : This class which will be used by the listener for communicating with Bugzilla and performing operations on the same. Using j2bugzilla the class looks as follows
3. Implement RaiseDefectWithScreenShotOnFailure class : This extends TestListenerAdapter and overrides the method onTestFailure(ITestResult tr)this uses connect Bugzilla class to Add a new bug every time tests fails. It will also capture screenshot and add it as an attachment to the defect.
Some of the details in bug
1. Title – is same as the Name of the test and timestamp of its execution TestMethodName_timeStamp
2. Description – String which is passed in Assert methods. This string is same which is used in TestNG results
3. Priority – Same as the Priority of the tests
All the details above are fetched with use of ITestNGMethod testMethod = tr.getMethod() and Map parameters = testMethod.getXmlTest().getAllParameters();
I have used the information provided from following links