@venkateshinakollu9681

Selenium Class 35 - TestNG Testing Framework for Selenium Part-3
------------------------------------------------------------------------
6) Grouping Test Cases

XML file for Grouping Test Cases:
-----------------------------------
<suit name="Suite Name">
<test name="Test Name">
<groups>
<run>
<include name="Group Name"/>
</run>
<classes>
<class name="Package.Class1Name"/>
<class name="Package.Class2Name"/>
</classes>
</groups>
</test>
</suite>
-----------------------------------
1) Sanity Testing (1st Group)

login()
search()
prepaidrecharge()
logout()

2) Regression Testing (2nd Group)

login()
advancedsearch()
billpayment()
prepaidrecharge()
logout()
-----------------------------------
Create XML file

<suite name="Ecommerce" parallel="false">
  <test name="Test">
  <groups>
  <run>
  <include name = "Sanity"/>
  </run>
    <classes>
      <class name="TestNG_XML_Practice.Sample"/>
    </classes>
    </groups>
  </test> 
</suite>
-----------------------------------
Class File :

package TestNG_XML_Practice;

import org.testng.annotations.Test;

public class Sample {

@Test (groups= {"Sanity", "Regression"}, priority=1)
public void login() {
System.out.println("Login is Successful"); 
}
@Test (groups= {"Sanity", "Regression"}, priority=6)
public void logout() {
System.out.println("Logout is Successful");
}
@Test (groups= {"Sanity"}, priority=2)
public void search() {
System.out.println("Search is Successful"); 
}
@Test (groups= {"Regression"}, priority=3)
public void advancedsearch() {
System.out.println("Advanced Search is successful"); 
}
@Test (groups= {"Sanity", "Regression"}, priority=3)
public void prepaidrecharge() {
System.out.println("Prepaid Recharge is successful"); 
}
@Test (groups= {"Regression"}, priority=5)
public void billpayment() {
System.out.println("Bill Payment is Successful"); 
}
}
---------------------------------------------------------------------------
7) Data Driven Testing Using @DataProvider Annotation

1. Read Test Data (String Type Data) from an Excel file and conduct Data Driven
Testing for Admin Login Functionality

2. Read Test Data (Integer Type Data) from and Excel file and conduct Data Driven Testing
---------------------------------------------------------------------------
Java Programming has 3 types of features support

1. Built-in Features (Predefined and Built-in)
conditional statements, 
loops,
Arrays,
System.out.println,
Etc.,

2. Predefined Features (import and use)
File Class,
Scanner, 
Etc.,

3. External Feature (download third party jars, add to Java project, import in the Java Class 

and Use)
1. To Use Excel File for this we need to download from Excel Jar from internet
2. SQL Jar for Databases
Etc.,
---------------------------------------------------------------------------
Admin Login Functionality

1. Launch the Browser
2. Navigate to gcrShop Admin Interface (http://www.gcrit.com/build3/admin/login.php)
3. Enter Username
4. Enter Password
5. Click "Login" Button
---------------------------------------------------------------------------
Verification Point/s:

1. Capture the URL and compare with Expected URL 

Expected URL:
"http://www.gcrit.com/build3/admin/index.php"

Input Data/Test Data
Ref: data.xls
---------------------------------------------------------------------------
Steps for Data Driven Testing: 

1. Create Selenium Test Case
2. Create Test Data File (Excel)
3. Download Excel Jar From Internet, Add to Java Project in Eclipse IDE, Import & Use
4. Import Test Data from an Excel and connect the data to the Test Case
---------------------------------------------------------------------------
Selenium Data Driven Test Case:

package TestNG_XML_Practice;

import java.io.File;
import java.io.IOException;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class DataDriven {
WebDriver driver;

@Test (dataProvider="testdata")
public void adminLogin (String Uname, String Pwd) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "E:/chromedriver.exe");
driver = new ChromeDriver();
driver.get("http://www.gcrit.com/build3/admin/index.php");
driver.findElement(By.name("username")).sendKeys(Uname);
driver.findElement(By.name("password")).sendKeys(Pwd);
driver.findElement(By.id("tdb1")).click();
Thread.sleep(3000);
Assert.assertEquals(driver.getCurrentUrl(), "http://www.gcrit.com/build3/admin/index.php");
}
@AfterMethod
public void closeApp () {
driver.close(); 
}
@DataProvider (name="testdata")
public Object [] [] readExcel() throws BiffException, IOException {
File file=new File ("C:\\Users\\good\\Desktop\\data.xls");
Workbook w=Workbook.getWorkbook(file);
Sheet s=w.getSheet("Sheet1");

int rows=s.getRows();
int columns=s.getColumns();
System.out.println(rows + ", " + columns);
 
String inputData [][]=new String [rows][columns];

for (int i=1; i<rows; i++) {
for (int j=0; j<columns; j++) {
Cell c=s.getCell(j,i);
inputData [i][j]=c.getContents();
System.out.println(inputData [i] [j]);
}
}
return inputData;
}
}
-----------------------------------------------------------------------------------
Note: your going to use 10 fields for Data Driven Testing, read Excel, and mention all 
fields/arguments in the Test Method.
-----------------------------------------------------------------------------------

@JagadeshDJ

within same source & creating different pack then different class can be used to execute in same xml

@soujanyatsk555

sir,Can you please provide class notes.Thank You

@dhirenderyadav3367

Can you please provide class notes