Required tools/programs/jar files
- JDK
- Eclipse
- Selenium Jar files
- Browser driver for Chrome, Safari, IE, Firefox
Download Java 8 (you can go for latest compatible version), Selenium, Browser drivers and run your first Selenium Test.
Downloading JDK
Open this link
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
It will take you to below screen, Click on Download Tab. Based on your windows system type (64 bit or 32 bit) it will show the download exe file, I am using 64 bit system I will get to see jdk-8u181-windows-x64.exe
It may take few minutes to download, after down is complete go to your Download folder you will get to see jdk-8u181-windows-x64.exe file. Double click on the file and and in few seconds it will be installed.
Setting the Environment variable
Go to My computer and open the folder C:\Program Files\Java\jdk1.8.0_181\bin and Copy this path shown in following screen shot
Now Right click on MyComputer> Click on Properties > Follow the steps given in below screenshot. 1.Click on Advanced System settings > 2.Click on Advance Tab> 3.Click on Environment Variables > 4.Double click Path > 5.Click on New button > 6.paste the copied path
Click Ok…Ok…Ok on all the windows. Now your Java Environment variable setting is done
Down Eclipse IDE
Open this link and download http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/oxygen/3a/eclipse-java-oxygen-3a-win32-x86_64.zip
Following screen will appear, Click on eclipse-java-oxygen-3a-win32-x86_64.zip
Now Eclipse down load will start and after few minutes eclipse-java-oxygen-3a-win32-x86_64.zip file will be download as zip file, Open Download folder and unzip it. Go inside the Eclipse folder and double click on eclipse.exe As shown in below screen
Your eclipse IDE Oxygen 3 will be opened, Now we need to create a java project and our first java program in order to make sure our setup is succesful
Creating Project, Package, Class and writing our first java program
Click on File > New > Java Project
Enter the project name in text box and Choose the location to save the project and Click on Finish button. Look at below screen
Create a package: Right click on Project > Click on New > Click on package and enter the package name in lower case and click on Finish button (Look at below screen)
Create a Class: Right click on package > Click on New > Click on Class and enter class name and click on Finish button
(Look at below screen)
Write our first java program and Run it
package testpackage;
public class TestClass {
public static void main(String[] args) {
System.out.println(“Hello World”);
}
}
Running the program: Right click and click on Run As > Java Application
Java program will be executed and you can see the output on console as Hello World [Look at below screen] which means our java setup is successful and running.
Download Selenium Jar
Open the link: https://docs.seleniumhq.org/download/
Since we are using Java language so we will download Java client
Go to Client version section and click on Download (3.13.0 is the latest Selenium version for java), now your download will start and in sometimes it will be completed depending on your internet speed. It will be downloaded as selenium-java-3.13.0.zip unzip it and keep it some folder.
[Look at below screen]
Download BrowserDrivers
Chrome (This link is for 2.8 version): https://chromedriver.storage.googleapis.com/index.html?path=2.8/
For chrome there is single zip file which works for 32 bit system as well as 64 bit system, click on download link as shown in below screen
Firefox: The name of firefox driver is Geckodriver the likn is https://github.com/mozilla/geckodriver/releases
Open the link and download based on your system because there are two separate files for 32 bit and 64 bit system. I will download geckodriver-v0.21.0-win64.zip since my system is 64 but.
[Look at below screen]
IE Driver download
Open this link https://docs.seleniumhq.org/download/
IE also has separate drivers for 32 and 64 bit system so download according to your system configuration
[Look at below screenshot]
All the downloads are completed, now extract Selenium jars, Chromedriver, Firefoxdriver, IEDriver and keep all in a folder so that it will be easier while adding those into our project.
I am keeping all browser drivers inside E:\qa\softwares\BrowserDriver and **
Selenium jars inside **E:\qa\softwares\selenium-java-3.13.0 (inside selenium you can see folder lib which has 10 jar files, copy all jar and past it in selenium-java-3.13.0 so you will get to see total 12 jar files in selenium-java-3.13.0 folder )
Folders will look like
Set the environment variable for BrowserDrivers
Open the folder where all the browser drivers are available and copy the path, in my case it is E:\qa\softwares\BrowserDriver
Now Right click on MyComputer> Click on Properties > Follow the steps given in below screenshot. 1.Click on Advanced System settings > 2.Click on Advance Tab> 3.Click on Environment Variables > 4.Double click Path > 5.Click on New button > 6.paste the copied path “E:\qa\softwares\BrowserDriver”
Adding the Selenium jars into project and running firt Selenium script
- Open eclipse
- Right Click on Project
- Click on BuildPath > Click on Configure Build Path… > Click on Libraries Tab > Click on Add External JARs… button > File explorer window will appear > Choose the location where we have saved the Selenium jar files E:\qa\softwares\selenium-java-3.13.0 > Select all jar files and click on Open button.
[Look at below screenshot]
All the choosen jar files will be added, Click on “Apply and Close” button
Look at Package explorer in left side > one Reference Libraries will be added with your project
Create a Java Class and write our first Selenium script
Right click on package which we had created earlier “testpackage” and click on New > Click on Class > Enter the class name as “SeleniumDemo” and click on Finish button
write a small script which will launch chrome browser and open the URL “http://www.google.com”
package testpackage;
import org.openqa.selenium.WebDriver; //this will import webdriver
import org.openqa.selenium.chrome.ChromeDriver; //this will import ChromeDriver
public class SeleniumDemo {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new ChromeDriver(); //creating the object of ChromeDriver
driver.get(“http://www.google.com”); //opening the URL
Thread.sleep(3000); //waiting for 3000 miliseconds
driver.quit(); //closing the browser
}
}
Running the program:
Right click and click on Run As > Java Application
Output:
- It will launch Chrome browser
- Open the url http://www.google.com
- wait for 3000 miliseconds
- Close the browser
Please feel free to suggest some additional points to make it more clear and understandable
Happy Testing!