Let us write our own first selenium program by creating new Java Project in Eclipse editor tool...
First step is to create a new Java Project in Eclipse to write our own first selenium webdriver program, for this we need below prerequisites software
First step is to create a new Java Project in Eclipse to write our own first selenium webdriver program, for this we need below prerequisites software
Pre-Condition:
- Eclipse
Installation download
here
- JDK
Installation
After installing above softwares,user needs to follow the below process:
First create “New Folder” with name as like “automation_Workspace”
folder in user machine, like
- Example
for Windows: Create automation_Workspace under this
directory D:/automation_Workspace
- Example
for Mac: Create automation_Workspace under this directory
/Users/<<username>>/Documents/automation_Workspace
Step
1:
Click
on Eclipse icon and click on browse, navigate upto
automation_Workspace folder
Step
2:
Go
to File >>New >> Project
Select
Java Project
Click
next button
Enter
project name as “SeleniumTraining”
Click
finish button
User
can see the “SeleniumTraining” folder at left side of
eclipse screen
Step
3:
Right
click on “SeleniumTraining” folder
Click
New>>Folder
Give
folder name as “lib”
Step
4:
Download
latest selenium-standalone-server.jar from here
By
default, the selenium-standalone-server.jarJar will downloaded in downloads folder.
Copy
the downloaded selenium-standalone-server.jar and place it in “lib” folder which user created in above Step 4
Step
5:
Create
a New class file under “SeleniumTraining>>src” folder
Right
click on src folder, go to New>>Class
Give
name as FirstSeleniumProgram
Click
Finish button
Step 6:
Now copy the below code and paste inside the
FirstSeleniumProgram.javapublic class FirstSeleniumProgram {
static WebDriver driver = null;
public static void main(String[] args) {
// Invoke the Firefox Browser using selenium webdriver
driver = new FirefoxDriver();
// Maximize the firefox window using selenium webdriver
driver.manage().window().maximize();
// Access the gmail url in firefox browser using selenium webdriver
driver.get("http://gmail.com");
}
}
Step
7:
Once
user paste the above code in FirstSeleniumProgram.java file,
Eclipse automatically will show the error indications with Red color.
These
errors are because, user didn't add the
selenium-standalone-server.jar to SeleniumTraining java project
Step 8:
To
import the downloaded selenium-standalone-server.jar into the
java project.
Right
click on src folder, Select on Build Path >>
Configure Build Path.
A
new window open with name “Java Build Path”, click on Libraries
button.
Click on “Add External JARs” button, navigate to the
folders “SeleniumTraining>>lib” select selenium-standalone-server.jar.
Click Ok
button.
Import the below packages into FirstSeleniumProgram.java
public class FirstSeleniumProgram {
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
Now all the Errors will gone and everything looks good
Complete
code looks like below:
public class FirstSeleniumProgram {
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class FirstSeleniumProgram {
static WebDriver driver = null;
public static void main(String[] args) {
// Invoke the Firefox Browser using selenium webdriver
driver = new FirefoxDriver();
// Maximize the firefox window using selenium webdriver
driver.manage().window().maximize();
// Access the gmail url in firefox browser using selenium webdriver
driver.get("http://gmail.com");
}
}
Step
9:
Right
click on FirstSeleniumProgram.java file and select Run
As>>Java Application
Hope you are able to run your own selenium program using java :)
Hope you are able to run your own selenium program using java :)