How to execute selenium test cases using bat file.

Selenium using bat file

how to Run selenium test cases using bat file.

Step 1: Create a simple Java project and add TestNG class.
Step 2: Write some simple selenium code.

Step 3: Now select option convert to TestNg as shown in below screenshot.

Step 4: Click on finish

Step 5: It will create a testng.xml file as shown below:

Step 6: We are done with project setup steps, Lets create a bat now:
set projectLocation=G:\JavaPractice\Cmd_Testng
cd %projectLocation%
set classpath=%projectLocation%\bin;%projectLocation%\lib\*
java org.testng.TestNG %projectLocation%\testng.xml

Step 7 : Double click on bat file to execute the test cases


Selenium Webdriver Framework01

In this framework we will try to cover all the basic component of a selenium as listed below:

1. TestNg demonstration
2.POM- Page Object Model
3.Code separation
4.Cross Browser Testing
5.External Data Source

Step 1 Create a Java project and Name it as “seleniumBasicFramework”

2. Create three package as shown below:

objectRepository- It will contain all the static data(object identifier and Application url )
operations– It will contain all frequently used functions used in our testing like- screenshots, external data reading etc.
searchFlight– It will contain the set of code responsible for testing with the help previously defined packages.

Step3 : We will create some folders to save results and to keep our external data source:
a) To add a folder , select project and right click , choose new option and a folder as shown below:

b) We will add three folders as shown below:

Step 4 : Now we will add all the required Jar files(Seelenium webDriver, Apache POI, TestNg Library)
a) TestNg library: Select project->right click-> Java build path->library->add library-> TestNg.
Follow below screenshots:-

b)Selenium WebDriver:- Add selenium WebDriver jar, to download click here and for more detail about it click here

c)Apache POI :- Add POI jar to the project as shown below, for more detail about it click here.

Step 5) Now we will place external drivers and Data source in folders we have mentioned earlier:
ExternalDataSource->excel file having test data.(named as TestData.xlsx)
ExternalDrivers- required external driver for the cross browser testing(chrome driver)

We are done with all basic setup required, let’s create TestNG Class to perform functional testing in package searchFlight:

Step 6 : Select package “searchFlight” ->right click-> new->others->TestNg Class->Next->Finish


c)Provide the name of the class as SearchFlight and click on finish.


Step 7) Add a class in operations name it as “”

Step 8) Add methods to Operations class to perform basic functions:

package operations;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.TakesScreenshot;

public class Operations {
public static void takesScreenshots(WebDriver driver, String name){
TakesScreenshot ts=(TakesScreenshot)driver;
File source=ts.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(source,new File(“./screenshots/”+name+”.png”));
catch(Exception e){
System.out.println(“Error while taking Screenshots ->”+e.getMessage());
public static String readExternalData(int i, int j){
String s=null;
File fs = new File(“./ExternalDataSource/TestData.xlsx”);
FileInputStream fis= new FileInputStream(fs);

Workbook workbook= new XSSFWorkbook(fis);
XSSFSheet sheet= (XSSFSheet) workbook.getSheetAt(0);
catch(Exception e){
System.out.println(“Error while Reading external data ->”+e.getMessage());
return s;

9) Add object identifiers to Util class.
package objectRepository;

public class Util {

public static final String baseUrl=””;

// page options:
//public static final String oneay_id=”OneWay”;

public static final String from_xp=”//*[@id=’FromTag’]”;
public static final String to_xp=”//*[@id=’ToTag’]”;
public static final String selectedDate_xp=”//*[@id=’ui-datepicker-div’]/div[1]/table/tbody/tr[4]/td[7]/a”;
public static final String searchbtn_id=”SearchBtn”;

10) Add code in
package searchFlight;

import java.util.concurrent.TimeUnit;

import objectRepository.Util;
import operations.Operations;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class SearchFlight {

WebDriver driver;// global variable- webdriver reference
public void selectBrowser(String browserName){
if(browserName.equalsIgnoreCase(“firefox”)){//takes screenshots with the name passed while function call
DesiredCapabilities dc =new DesiredCapabilities();
dc.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
driver= new FirefoxDriver(dc);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.MILLISECONDS);
System.out.println(“Opening firefox with desired capabilities”);
DesiredCapabilities dc= new DesiredCapabilities();
dc.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
driver =new ChromeDriver(dc);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.MILLISECONDS);
catch(Exception e){
System.out.println(“unable to launch browser”+e.getMessage());
public void flightSearch() {// reads data from excel sheet from the specified cell
String from= Operations.readExternalData(1, 0);
String to= Operations.readExternalData(1, 1);
System.out.println(Operations.readExternalData(1, 0)+” is selected as a source”);
System.out.println(Operations.readExternalData(1, 1)+” is selected as destination”);
Operations.takesScreenshots(driver,”Selected cities”);

Step 11)Create XML file to run the test suite.

As shown screenshot:

Step 12) Once xml is created replace the content with below code:

Steps 13)

Run the test suite by using xml file as shown in below screenshot:

To download complete file click here

Installing Maven in local system

Installing Maven in local system.

In this article we will install Maven, will create dependency and run a simple Selenium test case using  TestNG.

  1. Click here to download Maven jar files from Apache official website.Installing Maven in local system.

2.Unzip the downloaded file and place it in separate folder.


Installing Maven in local system.


3.Folder Structure

Installing Maven in local system.


4. Set Environment variable & path variable.

5.Check Maven version using cmd:- mvn -v

Installing Maven in local system.

6. Now lets create a simple project in eclipse as shown below:

7. Project will be created with folder structure as shown below:

8. Replace Pom.xml content with below provided details:

<project xmlns=”″ xmlns:xsi=”” xsi:schemaLocation=””>





<!– Adding Selenium dependency –>












9. Create a simple Selenium test case to open a link in firefox:

Sample code:


10. Use mvn clean command to clear all the previous setting.

Installing Maven in local system.

11. Use mvn install command to install missing files as shown in below screenshot:

Installing Maven in local system.

12. Use mvn test command to run the test cases created under maven project:

Installing the M2Eclipse Plugin.

We will complete this in two part – In 1st part we will discuss how to add Maven plug-in

  1. Installing the M2Eclipse Plugin.
  2. Installing Maven in local system.

In this article we will see the 1st part only

Below steps to follow to install Maven on Eclipse IDE :

  1. Open your Eclipse IDE and click Help-> Install New Software…
  2. On the opened pop-up, click on the Addbutton to add a new repository
  3. Fill the form with the information below and press Ok
    Name : M2Eclipse
    Location :
Maven Eclipse plugin
Maven Eclipse plugin

4.After the Pending finish, select all the Plugins and press Next >

Maven Eclipse plugin
Maven Eclipse plugin

5.Accept the terms of the license agreement and click Finish

6. At the end of the installation, you will be asked to restart your Eclipse. Click Yes to perform the restart.

Apache Maven is now integrated to your IDE.


Checking if Maven has been successfully installed

To check if whether or not Maven has been successfully installed on Eclipse follow these steps:

  1.  Open your Eclipse IDE and click Help -> About Eclipse
  2. Check the presence of the M2Ecplise icon as below
Maven Eclipse plugin
Maven Eclipse plugin