How to write my first Test Case using Selenium in Eclipse?

We are already finished with the prerequisite for starting with “Selenium”.Now we are taking a step further towards learning “Selenium”.
You can also check how to write first program in Eclipse.

Requirement:-Configuring Selenium Webdriver Jar files in Eclipse to write our first Selenium Program.

Step1:-Adding Jar files to Eclipse

Right Click “Java Project” in Package Explorer ->Build Path ->Configure Build Path

Opening add JAR dialog
Configure Build Path

Select Libraries Tab ->Click Add External JAR’s

Window to Add JAR files
Add External JAR’s

Browse to Selenium JAR files (For DownloadProcess) ->Add the Selenium JAR (We can add source JAR also) , Open the Lib folder to add all the JAR files.

Selenium JAR selection
Browse the Selenium JAR location

Click OK button to Add all the selected JAR files

Add JAR from Libraries
Adding JAR to Project

Note :- One’s JAR files are added, we can confirm it, under Reference in Project Explorer

Step2:- Writing and Running our first line of Selenium Code.(For running the First Java Program)

Flow :- Launching the firefox browser -> open the URL -> fetch the Title details.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class LearnSelenium {

public static void main(String[] args) {
//Creating WebDriver Object
System.out.println("Launching the Browser");
WebDriver driver = new FirefoxDriver();
//Opens the given URL
System.out.println("Fetching the Title");
System.out.println("Please Wait!!");
//Returns the Title of Current Page
String sTitle = driver.getTitle();
System.out.println("My First Selenium Program");
System.out.println("Title is = '"+sTitle+"'" );
//Closing the Browser


Add the above lines of code and Run it to success (CTRL + F11)

Result in Console 

Console in eclipse
Console Results

How to run the above code in Google Chrome?


3 thoughts on “How to write my first Test Case using Selenium in Eclipse?

Leave a Reply

Your email address will not be published. Required fields are marked *