Beginners guide -Test automation environment setup — Eclipse -Java, Selenium, Maven

BuddhiK
10 min readNov 13, 2022

Eclipse— Java, Selenium, Maven

In this guide, I will walk you through the test automation project environment setup using Eclipse(IDE), Maven, java, and Selenium stack.

Following this guide, you can set up a project environment and run simple test automation.

What is Eclipse?

Eclipse logo

Eclipse is an open-source Integrated Development Environment (IDE) used for developing computer software. Eclipse contains a base workspace as well as extensible additional plugins to customize the environment. It is popular mostly among java developers. But it supports C/C++, Python, PERL, Ruby, etc. Eclipse always release under a public license so it is free to download and installed.

Below I’m explaining just the steps to follow to make a new project in Eclipse beginning with installing the required software packages.

Step 01: Install Java and Configure the java path.

Step 02: Install Eclipse

Step 03: Create a Java Project in Eclipse

Step 04: Add Selenium JARs to the project

Step 05: First Selenium Java code to land on a web page

STEP 06 : Add Geko Web Driver (GekoDriver — Mozzila firefox) / Webdrivermanager

Step 01: Install Java and Configure the java path.

Go to the command prompt and type,

java -version

If it is already installed will display the version below.(fig 01)

fig 01

Or else you have to install java first.

Here I’m using the Windows platform. So I’m downloading java for windows.

  • Java for Windows /Linux

Configure java path

  1. Right-click on MyComputer → Go to properties → Go to Advanced system settings. (fig 02)
fig 02

2. Click on Environment Variables

Select the path variable and click on edit.

Then add the variable value to your jdk bin folder at the end of the path. (fig 03)

ex :

C:\Users\Praba\projects\drivers;C:\Program Files\JetBrains\PyCharm CommunityEdition2020.3.3\bin;C:\Program Files\Java\jdk-11.0.2\bin;

fig 03

3. Make new System variables for Java. (fig 05)

System variable section → New → Give the variable name → Variable value → Ok

example :(fig 04)

Variable name: JAVA_HOME

Value: C:\Program Files\Java\jdk-11.0.2\bin

fig 04
fig 05

Point the variable into the jdk bin folder.

  • JAVA_HOME should point to a JDK(Development kit), not a JRE(Java Run time Environment)

Step 02: Install Eclipse

Select the Download Packages.

fig 06

Then you will land on a page which contains different package downloading options for Eclipse. Select the required download option according to your OS and the system type from the “Eclipse IDE for Java Developers” section shown below. (fig 07)

fig 07

Then it will navigate you to the download page as below.(fig 08) Select the zip file and it will download to your machine. (fig 09)

fig 08
fig 09

After completing the download go to your downloads and move your downloaded eclipse zip file to any required folder you want and extract the zip file. Then go into the extracted folder. Double-click on eclips.exe to launch.(fig 10)

fig 10

Then it will ask for a specific directory to use as the eclipse workspace.(fig 11)

fig 11

You can change your desired workspace here and press launch.Work space will create according to the locations you have given.See below my workspace in my C:\Users\Praba\eclipse-workspace.(fig 12)

fig 12

Then the eclipse welcome page will appear as below.You can explore the eclipse with overview , tutorials, samples and etc.(fig 13)

fig 13

Step 03: Create a Java Project in Eclipse

  1. Go to the package explorer → Create Java project(fig 14) or go to the File → New →Java Project (fig 15)
fig 14
fig 15

Then the new Java Project window will appear.Give a name for your project and press Finish.(fig 16)

fig 16

Then your first java project created as below.(fig 17)

fig 17

Step 04 : Add Selenium JARs to the project

To download the selenium JARs go to

Get the latest stable version of selenium.

fig 18
fig 19

Or else you can only download the selenium client and webdriver bindings.

fig 20

To add the jars to the project go to your project → Rightclick on your project → Build Path → Configure Build Path

fig 21

Then the properties for your java project will appear.In there Select Java build path’s Libraries section → Classpath → Add External JARs → Select the Selenium Jars → Apply and Close.(fig 22)

fig 22

Go to your project and see the JARs added successfully under the reference lib section.

fig 23

Step 05 : First Selenium Java code to land on a web page

Right click on the project → New → Class

fig 23

Give a name for your class → tick public static void main(String[] args) to make your class the main class.

fig 24

Then the main testCaseOne class appear as below.(fig 25)

fig 25

STEP 06 : Add Geko Web Driver (GekoDriver — Mozzila firefox)

GeckoDriver is a link between Selenium tests and the Firefox browser.

For Mozilla Firefox till version 47, we never needed GeckoDriver. But Mozilla Firefox after version 47, comes with Marionette, which is an automation driver for Mozilla.

  1. Download Gekodriver for your computer.
  2. Restore the .exe file in the GekoDriver package

If you want to download Chrome Driver instead of Geko driver go to the Selenium dev site.

Lets start to code .

fig 26

Here I have set the system property key-value pair to key as geko driver and the value to the path to where the geko driver exe located in the project.

Then created a Firefoxdriver new object and as it to get the required URL. Then maximize the window.

To run the class right click on the class → Run As → Java Application.

fig 27

Then the automated browser will appear as below. You can note that the browser is under remote control. (reason marionette)

fig 28

Maven

Maven is by default in eclipse preference. To see go to Windows → Preferences

fig 29

Creating Maven Project

What is Maven?

Apache Maven is a software project management and comprehension tool based on a Project Object Model (POM) concept. Maven can

  • manage a project’s build
  • reporting and documentation from a central piece of information.

Go to eclipse → New → Project → Maven Project → Next

fig 30

Go next and fill required field below and press finish.

fig 31

Then you can see the well structured handy project created as shown in fig 32 below.

fig 32

pom.xml File

fig 33

pom. xml is an XML file located in the root directory of your project. The pom.xml file contains

  • information about the project
  • packages we used in the project
  • and various configuration detail used by Maven to build the project

To add selenium dependencies go to the selenium download page → Maven Information → MVNRepository.

fig 33

It will redirect you to

https://mvnrepository.com/artifact/org.seleniumhq.selenium

fig 34

Select Selenium Java.

fig 35

Select stable version and copy the code as shown as below.

fig 36

Go to your pom.xml file in the project and add a dependencies tag. Inside the dependencies, tag adds the new dependency you have copied. (fig 37)

fig 37

Once you save the pom.xml file the maven dependencies are added to the local automatically from the central repository.

fig 38

Go to your Project → Src/test/java → Crate new main class very similar as shown in the example above. Then add the piece of code below to automate the browser.

fig 39

Right-click on the class and run it as a java application. Then you will see the automated browser landing on the amazon.com site and automatically search for apple watches as per our piece of code in the TestCaseOne.java.

fig 40

Manage browser drivers -Webdrivermanager

In our TestCaseOne.java we provide the path to the browser driver exe. This is not much practicable when we working on a project. So Webdrivermanager will make it easy and automate manual downloads and locating on your locals and much more.

  • It verifies the version of the browser(eg chrome, firefox, Edge, etc.)
  • If it is unknown then it automatically uses the latest version of the driver(chromedriver, geckodriver, etc.)
  • It downloads the webdriver binary if it is not available in the cache.
  • It will export proper webdriver java environment variables required for selenium.

For further studies go to,

Steps to add Wedrivermanager to your project

  1. Go to

https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager

2. Select the latest and most stable version of the webdrivermanager . Copy the code.

3. Go to your pom.xml.Place your copied codes within the dependencies tags and save.

4. Go to your test case and remove your code part of System.setProerty .

5. Save and run it as a java application. You will see the same outcome as before.

fig 41 — pom.xml
fig 42 — TestcaseOne.java

A most common error you might face

- Project cannot be built until build path errors are resolved eclipse

This is the most common error you will get into. This is actually due to jre version mismatch. To correct it go to yours go to ,

Package Explorer → Right Click → Build Path → Configure Build Path → Libraries

Check whether the version of the jre library is correct.

If not Delete the appeared library in the window and then press

Add Library → JRE System Library → Environments → <Select your required library> → Finish.

So hope you understand the environment setup clearly. Stay connected for upcoming tech stories!

--

--

No responses yet