Configure Eclipse with Selenium WebDriver
- Create a workspace in Eclipse
- Create a New Project
- Create a New Package
- Create a New Class
- Add external libraries to the project
Create a workspace in Eclipse
- Launch Eclipse (eclipse.exe).
2. When you launch eclipse the first time – you will notice a popup asking you to select a directory as a workspace. When you develop Java applications in Eclipse, it stores all the created files in a directory called “workspace“. It’s nothing but a folder where all your eclipse data (including code) will be stored.
3. You can just use the default location or specify your preferred location.
4. Eclipse launched successfully
Create a new Project
Now that you’ve got Eclipse up and running, it’s time to create your first Java project. Hope you know what a project is? No? The next logical unit within workspace. A single workspace can have multiple projects. You can think of project as different automation assignments – a set of related code.
1. Select File > New > Java Project
2. Enter a Project Name. Here we have given ‘SeleniumTutorial’ as the project name. As you can see, the Java environment to be used for this project is selected by default under JRE section.
3. Click Finish and your first project is ready for experiments 🙂
Create a new Package
1. Select your project. Select File >> New >> Package
2. Enter the package name (e.g. automationPackage) >> Finish
3. A new package ‘automationPackage’ is now created under the project ‘SeleniumTutorial’
Create a new Class
Now it’s time to get started. Let’s create a class within the newly created package.
1. Right click on package >> New >> Class
2. A ‘New Java Class’ window is displayed. Enter the Class name (e.g. FirstScript) >> Select the public static void main(String args) checkbox >> Click Finish
public static void main(String args) – It defines that this will be your main class from where other classes / functions will be called.
3. Your FirstScript.java file is now ready for programming.
Add Selenium WebDriver External Jars to Java build path
Now we are ready with Eclipse & Java. But wait a minute, where is Selenium? Yeah! You need to add Selenium WebDriver’s Jar files in to Java build path.
1. Right click on ‘SeleniumTutorial’ >> Select Properties >> Java Build Path >> Libraries tab >> click ‘Add External JARs…’
2. Select & Add the Selenium Java jar file
3. Select all the jar files for the lib folder as well >> Open
Whoa! You have successfully learned how to configure Eclipse with Selenium WebDriver, i.e. you are all set for Selenium WebDriver automation scripting in Java using Eclipse 🙂