0

During my experience in Quality Assurance, especially automation testing, I have experienced two functional test tools(QTP and Selenium). In fact, I have noticed that Selenium have more strong points than QTP or it's much more dedicated for complicated web application. But still have one weak point : "Test Reports". For me, I find a big problem in generating reports related to Selenium Test. Otherwise, I find it very easy using QTP.

My question is, What's the best appropriate method used by Selenium Testers to generate tests reports?

  • Are looking for TestNG reports or Junit reports?. – Sachin Oct 7 '14 at 8:43
  • 1
    And testers will use the reporting technique based on there need. Not all testers are using same reporting technique's (Available more so). – Sachin Oct 7 '14 at 8:50
2

@Imen: I know below mentioned reporting techniques.

And more important is how you want your reports (Line by line/step by step execution report, class/method level report, etc..?).

What's the best appropriate method used by Selenium Testers to generate tests reports?

Selenium will support multiple reports generation techniques. Testers will be using different reporting techniques. The reports generation depend/based on the tester (If no specific requirement is from client/customer end), client requirement/request, etc...

Ex 1: You can use Log4j

Sample code:

DOMConfigurator.configure("log4j.xml");

Log.startTestCase("TestCase_001 Started");

driver = new FirefoxDriver();

Log.info("New driver instantiated");

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

Log.info("Implicit wait applied on the driver for 10 seconds");

driver.get("http://google.com");

For more details refer this link: Link

Ex 2: You can use TestRunner

public static void main(String[] args) {

//This result object has many methods and it is very useful

//Type result and press dot, all the methods will display

//This statement is to load all type of results in the result object

Result result = JUnitCore.runClasses(TestRunnerClass.class);

//Here it is getting the run count from the result object

System.out.println("Total number of tests: " + result.getRunCount());
//This is to get the failure count from the result object
System.out.println("Total number of tests failed: " + result.getFailureCount());
//This is to get the time count from the result object
System.out.println("Total time of tests: " + result.getRunTime());

for(Failure failure : result.getFailures())
{    
//This will print message only in case of failure
System.out.println(failure.getMessage());
}
//This will print the overall test result in boolean type
System.out.println(result.wasSuccessful());
}

Ex 3: Using .xml file

Sample Code:

import java.util.concurrent.TimeUnit;

 import org.openqa.selenium.By;

 import org.openqa.selenium.WebDriver;

 import org.openqa.selenium.firefox.FirefoxDriver;

 import org.testng.Assert;

 import org.testng.annotations.BeforeClass;

 import org.testng.annotations.Test;

 import org.testng.annotations.AfterClass;

 public class TestClass1 {

 protected static WebDriver wd;

 protected static String result;

 @BeforeClass

 public static void setup()  {

 wd = new FirefoxDriver();

 wd.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

 }

 @Test

 void Testcase1() {

 wd.get("http://www.floraindia.com");

 wd.findElement(By.id("kwsch")).sendKeys("Red");

 wd.findElement(By.xpath("//input[@src='images/go.gif']")).click();

 result = wd.findElement(By.xpath("//font[text()='Total Items :']//following::td[1]")).getText();

 Assert.assertEquals(result, "115");

  }

 @Test

 void Testcase2() {

 wd.get("http://www.floraindia.com");

 wd.findElement(By.id("kwsch")).sendKeys("Blue");

 wd.findElement(By.xpath("//input[@src='images/go.gif']")).click();

 result = wd.findElement(By.xpath("//font[text()='Total Items  :']//following::td[1]")).getText();

  Assert.assertEquals(result, "13");

 }
 @AfterClass

 public static void teardown()  {

 wd.close();

 wd.quit();

 }

}

.XML file sample:

<?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
 <suite name="My sample Suite">
  <test name="Search test">
    <classes>
      <class name="TestClass1" />
    </classes>
  </test>
 </suite>

For more details: Link 2

  • Thanks for your response and the explanations you provide – Imen CHOK Oct 7 '14 at 11:24
0

Talking about JUnit report, both XML and HTML reports can be added by editing Apache Ant build.xml file:

Test running target:

 <target name="tests" depends= "compile">
   <junit printsummary="yes" haltonfailure="no" showoutput="true">
    <classpath refid="junit.classpath"/>
      <formatter type="plain"/>
      <formatter type="xml"/>
  ...

Report target:

<target name="report">
  <junitreport todir="${junit.output.dir}">
    <fileset dir="${junit.output.dir}">
      <include name="TEST-*.xml"/>
    </fileset>
    <report format="noframes" todir="${junit.output.dir}"/>
  </junitreport>   
</target>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.