Play Around Data and Keyword – Hybrid Driven Framework – Devstringx

Back to Blog
Hybrid Driven Framework

Play Around Data and Keyword – Hybrid Driven Framework – Devstringx

Hybrid Framework

Hybrid Driven Framework is an ideal framework for manual testers who have no programming knowledge. This concept takes advantage of the Keyword-driven framework and the Information-driven framework.

Ingredients

JAVA, Selenium, IDE (any)

Directions

# Sauté Keywords

publicclass Keywords {

publicvoidclick(RemoteWebDriverdriver, String ObjectName, String locatorType)

throwsIOException, InterruptedException{

Thread.sleep(1000);

try {

driver.findElement(this.getObject(ObjectName, locatorType)).click();

}catch (Exception e) {

//

}

}

publicvoidenter(RemoteWebDriverdriver, String ObjectName, String locatorType, String value) throwsInterruptedException {

Thread.sleep(1000);

try {

WebDriverWaitwebDriverWait = newWebDriverWait(driver, 20);

webDriverWait.until(ExpectedConditions.elementToBeClickable(this.getObject(ObjectName, locatorType)));

driver.findElement(this.getObject(ObjectName, locatorType)).click();

new Actions(driver).sendKeys(value).build().perform();

} catch (Exception e) {

//

}

}

publicvoidassertion(RemoteWebDriverdriver, String ObjectName, String locatorType, String Expected, String value) throwsInterruptedException, IOException {

booleanpresent = false;

try {

WebDriverWaitwebDriverWait = newWebDriverWait(driver, 20);

webDriverWait.until(ExpectedConditions.visibilityOfElementLocated(this.getObject(ObjectName, locatorType)));

if (driver.findElement(this.getObject(ObjectName, locatorType)).getText().contains(value))

present = true;

}

catch (Exception e) {

//

}

if(Expected.contains(“true”))

Assert.assertTrue(present);

elseAssert.assertFalse(present);

}

By getObject(String ObjectName, String locatorType) throws

IOException{

//Object Repository is opened

File file = newFile(Path.CONFIG_OR_FILE_PATH);

FileInputStreamfileInput = newFileInputStream(file);

Read Also:- Key Benefits of Test Driven Development (TDD)

//Properties file is read

Properties prop = newProperties();

prop.load(fileInput);

//find by xpath

if(locatorType.equalsIgnoreCase(“XPATH”)){

returnBy.xpath(prop.getProperty(ObjectName));

}

//find by class

elseif(locatorType.equalsIgnoreCase(“ID”)){

return By.id(prop.getProperty(ObjectName));

}

//find by name

elseif(locatorType.equalsIgnoreCase(“NAME”)){

return By.name(prop.getProperty(ObjectName));

 

}else {

}

return null;

}

}

# Assemble Steps

public class Steps {

Keywords keyword = newKeywords();

publicvoidperform(RemoteWebDriverdriver,Stringoperation, String objectName, String typeLocator,Stringexpected, String testdata) throwsInterruptedException, IOException {

switch (operation) {

case“Enter_URL”:

driver.get(testdata);

break;

 

case“Enter”:

keyword.enter(driver, objectName, typeLocator, testdata);

 

case“Click”:

keyword.click(driver, objectName, typeLocator);

 

default:

break;

}

 

if(operation.contains(“AssertElement”)){

 

––                          keyword.assertion(driver,objectName, typeLocator, expected, testdata);

}

}

}

Read Also:- Robot Automation Framework and Features

# Mix and Serve

publicvoidExecuteStepsFromExcel(RemoteWebDriverdriver, intcount) throwsInterruptedException, IOException {

File file = newFile(filePath + File.separator + fileName);

String value = null;

FileInputStreaminputStream;

Workbook workbook = null;

try {

inputStream = newFileInputStream(file);

workbook = WorkbookFactory.create(inputStream);

} catch (Exception e) {

}

Sheet worksheet = workbook.getSheet(readSuiteNameUsingKeyFromExcel().get(count));

Row firstRow = worksheet.getRow(0);

introw = worksheet.getLastRowNum();

intcolumn = worksheet.getRow(1).getLastCellNum();

String Testdata = null;

for (inti = 1; i<= row; i++) {

LinkedList<String>Testexecution = new LinkedList<>();

 

for (intj = 0; j<column; j++) {

Cell Criteria = worksheet.getRow(i).getCell(j);

 

String CriteriaText;

if (Criteria == null) {

CriteriaText = null;

} else {

CriteriaText = Criteria.getStringCellValue();

}

Testexecution.add(CriteriaText);

Cell cell = worksheet.getRow(i).getCell(j);

switch (cell.getCellType()) {

caseCell.CELL_TYPE_STRING:

value = cell.getRichStringCellValue().getString();

break;

caseCell.CELL_TYPE_NUMERIC:

value = Integer.toString(((int) cell.getNumericCellValue()));

break;

caseCell.CELL_TYPE_BLANK:

value = “”;

break;

}

}

String Keyword = Testexecution.get(0);

String TypeLocator = Testexecution.get(1);

String ObjectName = Testexecution.get(2);

String Expected = Testexecution.get(3);

String Testdata = Testexecution.get(4);

if (i==1) {

if(!Testdata.isBlank())

step.perform(driver, Keyword, ObjectName, TypeLocator, Expected, Testdata);

} elseif (i> 1) {

step.perform(driver, Keyword, ObjectName, TypeLocator, Expected, Testdata);

}

System.out.println(“Row” + i + ” is read and action performed”);

}

System.out.println(“****TEST CASE ” + worksheet.getSheetName() + ” is executed*****”);

}

Read Also:- Ultimate Guide On Behavior Driven Development Testing

Stir Excel

# RoastTestcase

RoastTestcase

# Garnish Keywords

Garnish Keywords

Expert Tips

– Use Maven for dependencies

– Choose TestNG for reports

Share this post

Back to Blog

Hire A Resource