Selenium tutorial for beginners

Here we are going to learn how to create a data driven framework in selenium.

Problem definition : gmail log in page testing.
Project Creation and setup:
Step 1. Download Maven2.

Step 2. Unzip the zip file we have downloaded above.
Step 3. Set MAVEN_HOME path.
            -> go to System Properties and click on Environment variables.
            -> Click on "New" Under System Variables.
            -> Enter Variable name as "MAVEN_HOME" and Variable Value as "Path of maven folder" and click on ok
            -> edit the path variable and append ;%MAVEN_HOME%\bin
            -> click ok.
Step 4. open command prompt.
Step 5. test whether path has set properly by below command.
            $mvn -version
Step 6. run below command to create a maven project.
"mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes  -DartifactId=gmailTest"
after this a project folder named gmailTest will be created.

Writing test:

Step 1. Open eclipse.

Step 2. Import the project we have created above.

Step 3. Create below 3 files.

Step 4.Create Excel data file.
In the above Excel file we have below three column.  
    a. Key : this column contains key word through which we can search locator.
    b. Properties : this column contains attribute of HTML Element through which selenium will find the element.
    c. Value : this column contains value of attribute.

Step 5. place the excel file under resource folder of project.

Step 6.

<pre class="prettyprint">

package BaseTest;


import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.WritableWorkbook;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class LoginPage {
private WebElement SignInButton;
private WebElement UserName;
private WebElement Password;

private static WebDriver driver;

public WebDriver LoginPage()

return driver;

public By getLocator(String key) throws BiffException, IOException
File file = new File("C:\\Users\\Shyam\\workspace1\\MavenWeb\\src\\main\\resources\\datasheet.xls");
String property, value;
By locator = null;
Workbook workbook = Workbook.getWorkbook(file);
//WritableWorkbook workbook = createWorkbook(file);
Sheet sheet = workbook.getSheet(0);
Cell cell = sheet.findCell(key);
int rowNum = cell.getRow();
System.out.println("rowNum : " + rowNum);

property = sheet.getCell(1,rowNum).getContents().toString();
value = sheet.getCell(2,rowNum).getContents().toString();

System.out.println("property :" + property + "Value :" + value);

locator = getBy(property,value);

return locator;

public By getBy(String property, String value)
By returnBy = null;
returnBy =;
return returnBy;

public void initpage()
System.out.println("Calling costruction.....");
driver = new FirefoxDriver();

public WebDriver driver()
driver = new FirefoxDriver();
return driver;
public WebElement getUserName() throws BiffException, IOException
UserName = driver.findElement(getLocator("UserNameTextBox"));
return UserName;

public WebElement getPassword() throws BiffException, IOException
Password = driver.findElement(getLocator("PasswordTextBox"));
return Password;
public WebElement getSignInButton() throws BiffException, IOException

SignInButton = driver.findElement(getLocator("LoginButton"));
return this.SignInButton;


Step 7.                             

Text Box

package myPackage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import BaseTest.LoginPage;

public class Gmail
public WebDriver driver;
public void login() throws BiffException, IOException
LoginPage loginPage = new LoginPage();