Skip to main content

Selenium Framework, Data Driven, Keyword and Hybrid Framework Tutorials by Shiva Sir


It provides predefined libraries to implement a test script with a design pattern.
The framework uses an external file to take test data which will be implemented into the test script.
We will perform file handling operations using the Apache POI library by Jar integration or Maven.
Type of Selenium Framework:-
1 Data-Driven Framework:-    
we will create an external excel file or CSV file and define all Test data which will be read by File Handling operation and implemented in Test Script.
1.1 Create Environment using APACHE POI, SELENIUM, TestNG
Download apache poi using the following link
https://archive.apache.org/dist/poi/release/bin/
1.2 Create Excel File I have created scs.excel


1.3 Write the following Code
Data Driven Framework Code using Maven Project;-
Java File:-
package com.scs;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFCreationHelper;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.common.collect.Table.Cell;
public class CheckTestData {
ChromeDriver driver;
XSSFWorkbook workbook;
XSSFSheet sheet;
XSSFCell cell;
@BeforeTest
  public void TestSetup()
{
    System.setProperty("webdriver.chrome.driver", "c://chromedriver.exe");
   driver = new ChromeDriver();
   driver.get("https://eroomrent.in/ownerlogin.php");
   driver.manage().window().maximize();
      }
  @Test
  public void f() {
  try
  {
   File src=new File("d://testdata.xlsx"); 
   FileInputStream finput = new FileInputStream(src);
  
   workbook = new XSSFWorkbook(finput);
   sheet=  workbook.getSheetAt(0);
   for(int i=1; i<=sheet.getLastRowNum(); i++)
   {
   cell = sheet.getRow(i).getCell(0);
 
//   cell.setCellType(CellType.STRING); 
   driver.findElement(By.name("txtEmail")).sendKeys(cell.getStringCellValue());
  
   cell = sheet.getRow(i).getCell(1);
  // cell.setCellType(XSSFCell.CELL_TYPE_STRING);
   cell.setCellType(CellType.STRING); 
   driver.findElement(By.name("txtPassword")).sendKeys(cell.getStringCellValue());
   cell.setCellType(CellType.STRING); 
   WebElement we = driver.findElement(By.name("btnsubmit"));
   we.click();
   String s1 = "";
   s1 = "pass";
    
   XSSFRow row = sheet.getRow(1);
//  int rowCount = sheet.getLastRowNum()-sheet.getFirstRowNum();
//  XSSFRow newRow = sheet.createRow(1);
     XSSFCell cell = row.createCell(2);
        cell.setCellValue(s1);
             finput.close();
FileOutputStream fout = new FileOutputStream(src); 
workbook.write(fout);
fout.close();
   }
  }
  catch(Exception ex)
  {
  System.out.print(ex.getMessage().toString());
  }
  }
}  
 
POM.XML
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.scs</groupId>
  <artifactId>Testproject</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Testproject</name>
  <url>http://maven.apache.org</url>
<properties>
     <maven.compiler.source>1.8</maven.compiler.source>
     <maven.compiler.target>1.8</maven.compiler.target>
</properties>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>7.6.1</version>
    <scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>4.4.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>5.2.2</version>
</dependency>
  </dependencies>
</project>
Complete Code of Data-Driven Framework:-
package datadrivenexample;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class DataDrivenExample {
ChromeDriver driver;
XSSFWorkbook workbook;
XSSFSheet sheet;
XSSFCell cell;
@BeforeTest
  public void TestSetup()
{   
   System.setProperty("webdriver.chrome.driver", "c://chromedriver.exe");
   driver = new ChromeDriver();
   driver.get("https://eroomrent.in/login.php");
   driver.manage().window().maximize();
   }
  @Test
  public void f() {
  try
  {
   File src=new File("d://test.xlsx"); 
   FileInputStream finput = new FileInputStream(src);
   workbook = new XSSFWorkbook(finput);
   sheet= workbook.getSheetAt(0);
   for(int i=1; i<=sheet.getLastRowNum(); i++)
   {
   cell = sheet.getRow(i).getCell(0);
   cell.setCellType(CellType.STRING);
   driver.findElement(By.name("txtEmail")).sendKeys(cell.getStringCellValue());
   cell = sheet.getRow(i).getCell(1);
   cell.setCellType(CellType.STRING);
  driver.findElement(By.name("txtPassword")).sendKeys(cell.getStringCellValue());
   WebElement we = driver.findElement(By.name("btnsubmit"));
   we.click();
   String s = driver.switchTo().alert().getText();
   driver.switchTo().alert().accept();
   System.out.println(s);
   if(s.equals("Invalid userid and password"))
   {
   System.out.println("fail");
   }
   else
   {
   System.out.println("pass");
   }
   finput.close();
   cell = sheet.getRow(i).createCell(2);
   //cell.setCellType(CellType.STRING);
   cell.setCellValue(s);
FileOutputStream fout = new FileOutputStream(src); 
workbook.write(fout);
fout.close();
   }
  }
  catch(Exception ex)
  {
  System.out.print(ex.getMessage().toString());
  }
  }
}
Another example of Data Driven Framework:-
package scs;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class Hello {
ChromeDriver driver;
  XSSFWorkbook workbook;
  XSSFSheet sheet;
  XSSFCell cell;
  @BeforeTest
  public void TestSetup()
{   
   System.setProperty("webdriver.chrome.driver", "d://chromedriver.exe");
   driver = new ChromeDriver();
   driver.get("https://eroomrent.in/login.php");
   driver.manage().window().maximize();
   
}
  @Test
  public void f() {
   try
   {
   File src=new File("d://scs.xlsx");
  
   // Load the file.
   FileInputStream finput = new FileInputStream(src);
  
   // Load he workbook.
  workbook = new XSSFWorkbook(finput);
  
      // Load the sheet in which data is stored.
   sheet= workbook.getSheetAt(0);
  
   for(int i=1; i<=sheet.getLastRowNum(); i++)
   {
    // Import data for Email.
    cell = sheet.getRow(i).getCell(0);
    cell.setCellType(CellType.STRING);
    driver.findElement(By.name("txtEmail")).sendKeys(cell.getStringCellValue());
   
    // Import data for the password.
    cell = sheet.getRow(i).getCell(1);
    cell.setCellType(CellType.STRING);
    driver.findElement(By.name("txtPassword")).sendKeys(cell.getStringCellValue());
    WebElement we = driver.findElement(By.name("btnsubmit"));
    we.click();
         }
   }
   catch(IOException ex)
   {    
   }
  }
}
Another Example of eroomrent.in owner login:-
package scs;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class DatadrivenExample {
ChromeDriver driver;
XSSFWorkbook workbook;
XSSFSheet sheet;
XSSFCell cell;
//HSSFWorkbook workbook;
   // HSSFSheet sheet;
   // HSSFCell cell;
@BeforeTest
  public void TestSetup()
{
      System.setProperty("webdriver.chrome.driver", "c://chromedriver.exe");
   driver = new ChromeDriver();
   driver.get("https://eroomrent.in/ownerlogin.php");
   driver.manage().window().maximize();
   
}
@Test
public void f() {
  try
  {
   File src=new File("d://Testdata1.xlsx"); 
   FileInputStream finput = new FileInputStream(src);
//  workbook = new HSSFWorkbook(finput);
  workbook = new XSSFWorkbook(finput);
   sheet= workbook.getSheetAt(0);
   for(int i=1; i<=sheet.getLastRowNum(); i++)
   {
   cell = sheet.getRow(i).getCell(0);
   cell.setCellType(CellType.STRING);
   driver.findElement(By.name("txtEmail")).sendKeys(cell.getStringCellValue());
   cell = sheet.getRow(i).getCell(1);
   cell.setCellType(CellType.STRING);
   driver.findElement(By.name("txtPassword")).sendKeys(cell.getStringCellValue());
   WebElement we = driver.findElement(By.name("btnsubmit"));
   we.click();
   String result="";
   if(driver.getCurrentUrl().toString().equals("https://eroomrent.in/ownerlogin.php"))
   {
   result = "fail";
   }
   else
   {
   result="pass";
   }
   FileOutputStream fout = new FileOutputStream("d://Testdata1.xlsx"); 
   cell = sheet.getRow(i).createCell(2);
   cell.setCellType(CellType.STRING);
  // sheet.getRow(i).createCell(2).setCellValue("pass"); 
   cell.setCellValue(result);
  
   workbook.write(fout);
   fout.close();
   }
  }
  catch(Exception ex)
  {
  System.out.print(ex.getMessage().toString());
  }
}
@AfterTest
public void TestSetupclose()
{
 driver.close();
}
}

Latest Example of Data Driven:

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>


<groupId>com.scs.datadriven</groupId>

<artifactId>seleniumframework</artifactId>

<version>0.0.1-SNAPSHOT</version>

<packaging>jar</packaging>


<name>seleniumframework</name>

<url>http://maven.apache.org</url>


<properties>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

</properties>


<dependencies>

<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->

<dependency>

<groupId>org.apache.poi</groupId>

<artifactId>poi</artifactId>

<version>5.2.2</version>

</dependency>

<dependency>

<groupId>org.apache.poi</groupId>

<artifactId>poi-ooxml</artifactId>

<version>5.2.2</version>

</dependency>

<!-- https://mvnrepository.com/artifact/org.testng/testng -->

<dependency>

<groupId>org.testng</groupId>

<artifactId>testng</artifactId>

<version>7.11.0</version>

<scope>test</scope>

</dependency>

<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->

<dependency>

<groupId>org.seleniumhq.selenium</groupId>

<artifactId>selenium-java</artifactId>

<version>4.33.0</version>

</dependency>

<dependency>

<groupId>junit</groupId>

<artifactId>junit</artifactId>

<version>3.8.1</version>

<scope>test</scope>

</dependency>

</dependencies>

</project>


Source code for data driven:

package com.scs.datadriven.seleniumframework; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; public class Hello { WebDriver driver; Workbook workbook; Sheet sheet; Cell cell; @BeforeTest public void TestSetup() { driver = new ChromeDriver(); driver.get("https://eroomrent.in/login.php"); driver.manage().window().maximize(); } @Test public void f() { FileInputStream finput = null; FileOutputStream fout = null; try { File src = new File("d://test.xlsx"); finput = new FileInputStream(src); workbook = new XSSFWorkbook(finput); sheet = workbook.getSheetAt(0); for (int i = 0; i <= sheet.getLastRowNum(); i++) { // Read email cell = sheet.getRow(i).getCell(0); cell.setCellType(CellType.STRING); String email = cell.getStringCellValue(); // Read password cell = sheet.getRow(i).getCell(1); cell.setCellType(CellType.STRING); String password = cell.getStringCellValue(); // Perform login driver.findElement(By.name("txtEmail")).clear(); driver.findElement(By.name("txtEmail")).sendKeys(email); driver.findElement(By.name("txtPassword")).clear(); driver.findElement(By.name("txtPassword")).sendKeys(password); WebElement we = driver.findElement(By.name("btnsubmit")); we.click(); System.out.println("Attempt " + i ); // Write result to Excel Row row = sheet.getRow(i); if (row == null) { row = sheet.createRow(i); } Cell resultCell = row.createCell(2); resultCell.setCellValue("Attempt " + i); // Optional: reset between attempts driver.manage().deleteAllCookies(); driver.navigate().refresh(); Thread.sleep(1000); // Small pause between attempts } finput.close(); // Close input stream before writing fout = new FileOutputStream(src); workbook.write(fout); } catch (Exception ex) { System.out.println("Error: " + ex.getMessage()); ex.printStackTrace(); } finally { try { if (finput != null) finput.close(); if (fout != null) fout.close(); if (driver != null) driver.quit(); } catch (Exception e) { e.printStackTrace(); } } } }



 2 Keyword-driven Framework:-


Create an Excel file with this structure


IT Provide Set of Keywords which contains Object, Object Type, Value, and connected with the repository.
step for keyword:-
1 Create Environment using APACHE POI, SELENIUM, TestNG
2 Create ReadExcel class:-
first, create a package then create a class in eclipse:-
package readexcel;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ReadExcel {
public Sheet readExcel(String filePath,String fileName,String sheetName) throws IOException{
//Create a object of File class to open xlsx file
File file = new File(filePath+"\\"+fileName);
//Create an object of FileInputStream class to read excel file
FileInputStream inputStream = new FileInputStream(file);
Workbook guru99Workbook = null;
//Find the file extension by spliting file name in substing and getting only extension name
String fileExtensionName = fileName.substring(fileName.indexOf("."));
//Check condition if the file is xlsx file
if(fileExtensionName.equals(".xlsx")){
//If it is xlsx file then create object of XSSFWorkbook class
guru99Workbook = new XSSFWorkbook(inputStream);
}
//Check condition if the file is xls file
else if(fileExtensionName.equals(".xls")){
//If it is xls file then create object of XSSFWorkbook class
guru99Workbook = new HSSFWorkbook(inputStream);
}
//Read sheet inside the workbook by its name
Sheet  guru99Sheet = guru99Workbook.getSheet(sheetName);
return guru99Sheet;
}
}
3)  create objects package and create the file with object.properties and define all object value:-
url=http://newtours.demoaut.com/
username=userName
password=password
loginButton=login


4)  create ReadObject class using operation package:-

package operation;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class ReadObject {
Properties p = new Properties();
public Properties getObjectRepository() throws IOException{
//Read object repository file
InputStream stream = new FileInputStream(new File(System.getProperty("user.dir")+"\\src\\objects\\object.properties"));
//load all objects
p.load(stream);
return p;
}
}
create UIOperation.java in the same package:-
package operation;
import java.util.Properties;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class UIOperation {
WebDriver driver;
public UIOperation(WebDriver driver){
this.driver = driver;
}
public void perform(Properties p,String operation,String objectName,String objectType,String value) throws Exception{
System.out.println("");
switch (operation.toUpperCase()) {
case "CLICK":
//Perform click
driver.findElement(this.getObject(p,objectName,objectType)).click();
break;
case "SETTEXT":
//Set text on control
driver.findElement(this.getObject(p,objectName,objectType)).sendKeys(value);
break;
case "GOTOURL":
//Get url of application
driver.get(p.getProperty(value));
break;
case "GETTEXT":
//Get text of an element
driver.findElement(this.getObject(p,objectName,objectType)).getText();
break;

default:
break;
}
}
/**
* Find element BY using object type and value
* @param p
* @param objectName
* @param objectType
* @return
* @throws Exception
*/
private By getObject(Properties p,String objectName,String objectType) throws Exception{
//Find by xpath
if(objectType.equalsIgnoreCase("XPATH")){
return By.xpath(p.getProperty(objectName));
}
else if(objectType.equalsIgnoreCase("ID")){
return By.id(p.getProperty(objectName));
}
//find by class
else if(objectType.equalsIgnoreCase("CLASSNAME")){
return By.className(p.getProperty(objectName));
}
//find by name
else if(objectType.equalsIgnoreCase("NAME")){
return By.name(p.getProperty(objectName));
}
//Find by css
else if(objectType.equalsIgnoreCase("CSS")){
return By.cssSelector(p.getProperty(objectName));
}
//find by link
else if(objectType.equalsIgnoreCase("LINK")){
return By.linkText(p.getProperty(objectName));
}
//find by partial link
else if(objectType.equalsIgnoreCase("PARTIALLINK")){
return By.partialLinkText(p.getProperty(objectName));
}else
{
throw new Exception("Wrong object type");
}
}
}
5)  Create Executor.java file to execute operation using TestNG Class:-
package keyworddriven;
import org.testng.annotations.Test;
import readexcel.ReadExcel;
import operation.*;
import org.testng.annotations.BeforeMethod;
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;
public class ExecuteTest {
WebDriver driver;
@BeforeMethod
  public void beforeMethod() {
System.setProperty("webdriver.chrome.driver", "C://chromedriver.exe");
driver = new ChromeDriver();
  }
  @Test
  public void f() throws Exception {
  ReadExcel file = new ReadExcel();
      ReadObject object = new ReadObject();
      Properties allObjects =  object.getObjectRepository();
      UIOperation operation = new UIOperation(driver);
      Sheet guru99Sheet = file.readExcel(System.getProperty("user.dir")+"\\","TestCase.xlsx" , "KeywordFramework");
      //Find number of rows in excel file
    int rowCount = guru99Sheet.getLastRowNum()-guru99Sheet.getFirstRowNum();
    //Create a loop over all the rows of excel file to read it
    for (int i = 1; i < rowCount+1; i++) {
    //Loop over all the rows
    Row row = guru99Sheet.getRow(i);
    //Check if the first cell contain a value, if yes, That means it is the new testcase name
    if(row.getCell(0).toString().length()==0){
    //Print testcase detail on console
    System.out.println(row.getCell(1).toString()+"----"+ row.getCell(2).toString()+"----"+
    row.getCell(3).toString()+"----"+ row.getCell(4).toString());
    //Call perform function to perform operation on UI
    operation.perform(allObjects, row.getCell(1).toString(), row.getCell(2).toString(),
    row.getCell(3).toString(), row.getCell(4).toString());
        }
    else{
    //Print the new  testcase name when it started
    System.out.println("New Testcase->"+row.getCell(0).toString() +" Started");
    }
    }
  }
  @AfterMethod
  public void afterMethod() {
  }
}
3 Hybrid   Framework:-  

it is a combination of a data-driven and keyword-based framework. if you will combine both examples then it will be called the Hybrid framework.



Comments

  1. you have written an excellent blog.. keep sharing your knowledge...
    Selenium with Python Training
    Selenium with Python Course

    ReplyDelete
  2. event management. Doubling down on becoming the leading networking-focused hybrid event platform and They continue to build an impressive client list that includes some of the largest companies in B2B events. invitation text sample and thank you for the meeting email

    ReplyDelete
  3. event management. Doubling down on becoming the leading networking-focused hybrid event platform and They continue to build an impressive client list that includes some of the largest companies in B2B events. invitation text sample and thank you for the meeting email

    ReplyDelete

Post a Comment

POST Answer of Questions and ASK to Doubt

Popular posts from this blog

Uncontrolled form input in React-JS

  Uncontrolled form input in React-JS? If we want to take input from users without any separate event handling then we can uncontrolled the data binding technique. The uncontrolled input is similar to the traditional HTML form inputs. The DOM itself handles the form data. Here, the HTML elements maintain their own state that will be updated when the input value changes. To write an uncontrolled component, you need to use a ref to get form values from the DOM. In other words, there is no need to write an event handler for every state update. You can use a ref to access the input field value of the form from the DOM. Example of Uncontrolled Form Input:- import React from "react" ; export class Info extends React . Component {     constructor ( props )     {         super ( props );         this . fun = this . fun . bind ( this ); //event method binding         this . input = React . createRef ();...

JSP Page design using Internal CSS

  JSP is used to design the user interface of an application, CSS is used to provide set of properties. Jsp provide proper page template to create user interface of dynamic web application. We can write CSS using three different ways 1)  inline CSS:-   we will write CSS tag under HTML elements <div style="width:200px; height:100px; background-color:green;"></div> 2)  Internal CSS:-  we will write CSS under <style> block. <style type="text/css"> #abc { width:200px;  height:100px;  background-color:green; } </style> <div id="abc"></div> 3) External CSS:-  we will write CSS to create a separate file and link it into HTML Web pages. create a separate file and named it style.css #abc { width:200px;  height:100px;  background-color:green; } go into Jsp page and link style.css <link href="style.css"  type="text/css" rel="stylesheet"   /> <div id="abc"> </div> Exam...

JDBC using JSP and Servlet

JDBC means Java Database Connectivity ,It is intermediates from Application to database. JDBC has different type of divers and provides to communicate from database server. JDBC contain four different type of approach to communicate with Database Type 1:- JDBC-ODBC Driver Type2:- JDBC Vendor specific Type3 :- JDBC Network Specific Type4:- JDBC Client-Server based Driver  or JAVA thin driver:- Mostly we prefer Type 4 type of Driver to communicate with database server. Step for JDBC:- 1  Create Database using MYSQL ,ORACLE ,MS-SQL or any other database 2   Create Table using database server 3   Create Form according to database table 4  Submit Form and get form data into servlet 5  write JDBC Code:-     5.1)   import package    import java.sql.*     5.2)  Add JDBC Driver according to database ide tools     5.3)  call driver in program         ...