Friday, November 17, 2017

How to set up Selenium WebDriver Java project in Eclipse

To set up Selenium WebDriver Java project in Eclipse

Prerequisite:

➽ Eclipse is installed
➽ JDK is installed

Step 1: Creating Java Project in Eclipse

1. Open Eclipse
2. Click File -> Mouse over New -> Click Java Project
3. Enter a Project Name -> Click Next and then Finish

Step 2: Installing/Configuring Selenium WebDriver

1. Download Selenium WD Java client from http://www.seleniumhq.org/download/ at "Selenium Client & WebDriver Language Bindings" section (In my case it is selenium-java-3.7.1.zip)
2. Extract the Zip file in a folder/location of your choice
3. In Eclipse: Right click on Java Project you have created in Step 1 and click Properties
4. In Project Properties window: Click "Java Build Path" at the left -> Click Libraries tab -> Click "Add External JARs..." button at the right side
5. Select client-combined-3.7.1.jar and client-combined-3.7.1-sources.jar from the folder "selenium-java-3.7.1" -> Click Open button
6. Again click "Add External JARs..." button at the right side -> Select all the JARs from /selenium-java-3.7.1/libs folder and click Open button
7. Finally click OK

Step 3: Creating our first Test Script/Class

1. To create a package: Right click src -> Mouse over New -> Click Package. Enter a package Name and click Finish
2. To create a class: Right click on package name -> Mouse over New -> Click Class. Enter a Class Name and click Finish button

Step 4: Modifying the previous code to WD java

1. Modify the previous code to Selenium WD Java code to perform the following steps:
    1.1 Initialize FirefoxDriver
    1.2 Visit Google - https://www.google.com/ in Firefox
    1.3 Clear the Google search text field
    1.4 Enter search keyword in text field
    1.5 Press Enter key to view the search result
Step 5: Run the test

1. Right click on Java Class (GoogleSearch.java) at the left
2. Mouse over Run As -> Click Java Application

No comments:

Post a Comment