Welcome to this article in our Selenium Tutorial series. In our previous articles in this tutorial series, you learnt how to download chromedriver and selenium jar files. In this article, you will see how you can create a selenium project in Eclipse.
Topics that we will cover in this article
In this article, you will learn about the following two topics –
- Create new java project for Selenium in eclipse
- Add all Selenium jar files to this project
Important Note: As we had mentioned earlier in the tutorial series, we will start with creating this project as a normal java project. Once the selenium setup is complete, we have few working scripts, then we will convert this project into a maven project.
Let us now start with the first topic of this article, which is, creating a new selenium project.
Open Eclipse IDE
Follow the steps given below to open Eclipse IDE (if you have not followed this tutorial series from beginning and you don’t have Eclipse, then you can follow this link to download Eclipse IDE) –
1) Open the folder location where you have the unzipped Eclipse folder. Double click on eclipse.exe to open it
2) Once Eclipse starts opening, you would see the Eclipse logo
3) Next you would see Eclipse Launcher popup box. Leave the default workspace folder location as it is
4) Click on Launch button. Eclipse would start loading all the files. Once its done, you will see the Eclipse IDE Welcome page like this
Create new Selenium project in Eclipse
Now it’s time to create a project for Selenium in Eclipse. This will be a normal java project, which you can create by following the steps given below –
1) Select File -> New -> Project… option from Eclipse IDE
2) In the New Project popup box, select Java Project and then click on Next button
3) In the New Java Project popup box, write the project name as SeleniumTutorial.
4) Uncheck Create module-info.java file checkbox. Leave all the other fields as it is and then click on Finish button
5) Eclipse IDE would now open. If the panel at the left side is collapsed, then you can restore it by clicking on the icon shown below
6) Eclipse IDE should now look like something as shown below. It would display your newly created project in the left side pane. If there are some additional panes on the right side (Tasks List, Welcome screen etc), then you can close those so that Eclipse IDE looks uncluttered
From the above image, you can see that SeleniumTutorial project has been created and is displayed in the left-hand side pane.
Contents inside SeleniumTutorial project
If you expand the SeleniumTutorial project, you will see that it contains JRE System Library and src folders. You can check that src folder is currently blank. But if you expand JRE System Library, you will see that it has some JAR files already added as shown in the below image. This is the minimum set of JAR files that is required to run a basic Java program.
Important Note: You might have noticed that the path of the jar files in JRE System Library is actually pointing to a folder location within the eclipse folder that you downloaded. And this is not the same location where you had downloaded and installed Java.
What has happened here is that when you download Eclipse, it itself comes with all the Java jar files. And when you create a new Java project, Eclipse by default points to the Java jar files that’s present within its own folders. For now, we will leave it as it is (we have another article in this Selenium Tutorial series where we would point Eclipse to the Java jar files that we have downloaded separately)
Now we already have Java jar files added to the project, but before we start writing code, we need to add the selenium webdriver jar files as well to the project. Let’s see how this is done.
Add all the Selenium jar files to the project
Follow the steps given below to add all the selenium webdriver jars to the eclipse project –
1) Right click on the Project. Then select Build Path > Configure Build Path… option
2) Properties window will get opened as shown below. From the Libraries tab, first select on Classpath and then click on Add External JARS… button.
3) Now navigate to the folder where you had downloaded Selenium WebDriver jar files. Select all the jar files from the selenium folder and click on Open button
4) Do the same for all the jar files in the lib folder
5) Now click on Apply and Close button to close the Properties window. Notice that a new sub-section called Referenced Libraries is created inside the project folder. Expand this Referenced Libraries section. You will see that it lists down all the JAR files that you had added in the above steps
With this, our article for creating a Selenium project is now complete. We have created a new project in eclipse, and added all the Selenium jar files. In our next article, we will cover the detailed steps on how to write your first Selenium test script. If you have any doubts with this article, then please feel free to contact us using the comments section.