i
WebDriver Introduction
Selenium WebDriver Architecture
Introduction to WebDriver API
Introduction to WebDriver – Code
Handling Dropdowns and Select class
Handling Multiple Dropdown values and Links
Handling Radio buttons and Checkboxes
Capture Screenshots and Email test results
Browser Navigation Methods
Handling tabs
Capturing screenshot, Handling tabs and pop-ups – Code
Handling tabs and Pop-ups – Code
Handling Alerts
Handling User Authentication and Input alerts
HtmlUnitDriver and Handling Captchas
Handling Web Tables
Synchronization
Handling WebTables, Synchronization issues, Firefoxprofiles – Code
Actions Class
Event Listeners, Event Firing Mouse, Coordinates – Code
Handling Mouse Hover in Selenium
JavascriptExecutor
Handling Iframes
IsElementPresent, IsEnabled, IsSelected
Working with Chrome Driver - Part 1
Working with FireFox Driver - Part 2
Working with Internet Explorer Driver - Part 3
Handling SSL Certificate
Desired Capabilities
How to Encode password in WebDriver
Handling JQuery Elements - Drag and Drop, Sliders, Resizable
Handling JQuery Elements - Drag and Drop, Sliders, Resizable – Code
Working on IE Browser using Actions
TestNG, Ant & Report Generation through XSLT
Introduction to TestNG and Annotations
TestNG Parameterization
Configuring ANT, Generating TestNG & XSLT Reports
Code for generating XSLT / Surefire Reports through MAVEN
TestNG Parameterization Excel Reading
Handling Multiple data providers
TestNG XSLT Jar, Build.xml & TestNG.xml file
Frameworks Introduction
Hybrid (DATA + KEYWORD) driven Framework
Framework Architecture
Reading Excel sheets
TestNG DataProvider
Data Provider with Hashtable
Handling Multiple Test Suites
Multiple DataProviders
Setting up Run-modes at Suite Level
Setting up Runmodes at TestCase Level
Creating a common utility for Run-modes
Hybrid Framework Code
As we can connect excel sheets using our Excel Reading utility, we can provide the data to the TestNG test cases using the data provider feature of TestNG.
Let us see how the excel file which we take the data from for our Hybrid Automation framework.
Test |
Keyword |
Object |
ObjectType |
Value |
Login |
|
|
|
|
|
OPENURL |
|
|
url |
|
ENTERTEXT |
userid |
XPATH |
user1 |
|
ENTERTEXT |
password |
XPATH |
password1 |
|
CLICK |
btnLogin |
XPATH |
|
As this is a Data + Keyword-driven approach, we need to pass all the values from the excel sheet to our test by using the data-provider. Let us see the TestNG test class for the implementation of a data-provider method for the same:
package TestSuite;
import java.io.IOException;
import java.util.Properties;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class TestNGTest {
WebDriver driver;
@Test(dataProvider="crendentialData")
public void testLogin(String testcaseName,String keyword,String objectName,String objectType,String value) throws Exception {
if(testcaseName!=null&&testcaseName.length()!=0){
System.setProperty("webdriver.chrome.driver",System.getProperty("user.dir"+"/testData.xlsx"));
this.driver= new ChromeDriver();
}
ObjectReader object = new ObjectReader();
Properties allObjects = object.getObjectRepository();
BaseActions operation = new BaseActions(driver);
//Use of perform method to perform actions on UI
operation.perform(allObjects, keyword, objectName,
objectType, value);
}
@DataProvider(name="crendentialData")
public Object[][] getDataFromDataprovider() throws IOException{
Object[][] object = null;
ExcelReader file = new ExcelReader();
//Reading the sheet for keywords and data
Sheet sheet = file.readExcel(System.getProperty("user.dir")+"\\","testData.xlsx" , "TestData");
// Number of rows in excel sheet
int rowCount = sheet.getLastRowNum()-sheet.getFirstRowNum();
object = new Object[rowCount][5];
for (int i = 0; i < rowCount; i++) {
//Loop to read all the rows
Row row = sheet.getRow(i+1);
//Create a loop to print cell values in a row
for (int j = 0; j < row.getLastCellNum(); j++) {
//Print excel data in console
object[i][j] = row.getCell(j).toString();
}
}
System.out.println("");
return object;
}
@AfterMethod
void cleanup()
{
driver.quit();
}
}
Here we can see that the data provider method is providing the data to the TestNG test method with the help of “readExcel” method of the Excel reading utility.
Don't miss out!