Selenium-Testng examples to execute multiple classes

Selenium – TESTNG examples to execute multiple Classes,Most of the time we will face problem while executing the multiple test cases from multiple classes using TESTNG,In order to overcome those problem i am explaining with real time examples using TestNG with selenium webdriver.

Here we are creating three classes as Selewebinitiate , Login and Logout classes.Let’s create the classes and create Testng.xml file as below and also read Execution of multiple Classes with TestNG

Generate HTML Reports using Selenium
Selenium WebDriver Methods
Read Data From properties file using Selenium
Launch Firefox Browser using GeckoDriver

Selewebinitiate java Class:

package com.Bazaar.Purchase; 
import org.openqa.selenium.WebDriver;
import org.testng.annotations.BeforeTest;
public Class Selewebinitiate(){ 
//Declare the driver variables
Webdriver driver;
String baseUrl; 

//Now Create TestNG annotation to run before Test
public void setup(){
//I am using chrome driver to run the script in google chrome browser
extent = new ExtentReports("E:\\Automation_Testing\\FutureBazaar\\FutureBazaar_Results\\FB_TestResults.html",true);
test=extent.startTest("Selenium Web driver initialization");
//Chrome browser initialization
File ChromeDriver = new File("F:\\Java_Applications\\Zip Files\\chromedriver.exe");
driver = new ChromeDriver(options);

2.Login java class:

Now we will create Login class with TestNG annotation as below and we will use extends option to pass Selewebinitiate objects in this class.Let’s create the class

package com.Bazaar.Purchase;
import org.testng.annotations.Test;

public class StoreLogin extends Selewebinitiate {

public void custLogin(){

String username=driver.findElement("userEmailId")).getAttribute("value");
test.log(LogStatus.PASS,"Username is entered");
test.log(LogStatus.FAIL, "Username is not entered");
String password=driver.findElement("passwordId")).getAttribute("value");
System.out.println("user enter Password.Test Case is Pass");
test.log("user not enter password,Test Case is Fail");


3.Logout class

In this class we will logout the application,let’s create the class and passing Selewebinitiate class

package com.Bazaar.Purchase;
import org.testng.annotations.Test;

public class Logout extends Selewebinitiate {

public void appLogout(){



Now create TestNG.xml file as below here we are using : Name in Testng xml file indicates Name of the Test as below i.e <test name=”Bazaar App”>
2.verbose=”2″ :This indicates write the execution log details to console of Eclipse where we are able to see Test Execution results.This verbose can indicates from 1 to 9 numbers.According to numbers it displays different log details in console.
3.parallel=”tests” : It is a mode in parallel and having different types of modes those are Tests,methods,classes and none.

Testng.xml file as below

 <suite name="Test Suite" parallel="tests" verbose="2">  
 <test name="Bazaar App">  
 <class name="com.Bazaar.Purchase.StoreLogin">  
 <class name="com.Bazaar.Purchase.Logout">  

Now run the testng.xml file by right click on it TestNG–TestNG Suite.It will automatically execute the tests within single browser.Thank you for reading ,please provide your valuable comments on this posts.Please share my post to help other people.

Test Results:

Test NG Test Results

Please provide your valuable comments on this posts and please share with social media sites.

Post a comment