Integrating Bugzilla and Selenium in Java

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.

      Selenium Tests clas with TestNG Listener

      Selenium Tests clas with TestNG Listener

      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

      Operate on Bugzilla

      Operate on Bugzilla

      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.

      Test Listener Adapter

      Test Listener Adapter

      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

ReportNG plugin for TestNG Selenium html reporting

ReportNG is a simple HTML reporting plug-in for the TestNGunit-testing framework. It is intended as a replacement for the default TestNG HTML report. The default report is comprehensive but is not so easy to understand at-a-glance. ReportNG provides a simple, colour-coded view of the test results.

Steps to use the plugin

1. Download the plugin from http://reportng.uncommons.org/

2. Add the downloaded jars in the class-path

3. Add following the ant target

<testng classpathref=”TestNgSelenium.classpath”
outputDir=”outputFromAnt”
haltOnfailure=”true”
useDefaultListeners=”false”
listeners=”org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter”>
<xmlfileset dir=”.” includes=”testng.xml”/> <sysproperty key=”org.uncommons.reportng.title” value=”My Test Report”/>
</testng>

useDefaultListeners – This will disable the default the TestNG reports

reportslisteners – Will use the new plugin

Following is the example of sample report :- http://reportng.uncommons.org/sample/index.html

Getting started with automation testing

In this post I’m trying to suggest the steps which can help in performing automation from scratch.

  1. Understand the Application Under Test(AUT) for automation testing. Ask following questions.
  • Is web application or desktop or mobile app?
  • What are various kind of testing required like UI, Functional, Web service, Performance
  • Get details for technology on which the application is built like HTML5 or Java or .NET or WPF

All the above questions will help do the next step

  1. Analyze tools according to inputs from above step – Following are some of the tools that I have used
  • Selenium – Only web application automation. Open source tool which allows coding in many languages this helps in using any existing knowledge with in the team. Following frameworks help when using selenium are TestNG, JUnit.
  • QTP – One of the most known tools in the market can be used for web as well as desktop and i think lately for mobile also. Scripting language is VB script.
  • SilkTest – Used it for Desktop application uses own 4T scripting language
  • TestComplete – Used for automation of Silverlight application. Can code using many languages VB Script, Java Script. Excellent tool easy to use and cheaper compared to QTP
  • Some of the other tools are
    • Webservice testing – SoapUI, JMeter.
    • Performance testing – Jmeter, SilkPerformer
  1. Design automation framework – Structuring the automation tasks in way that it helps reusability, easy of test case scripting, better reporting. This part in itself can be discussed in details which will be done in coming posts.