How to Configure Webdriver-Selenium for Java in Eclipse on Windows
Sauce AI for Test Authoring: Move from intent to execution in min.|xBack to ResourcesBlogPosted March 19, 2019
How to Configure Webdriver-Selenium for Java in Eclipse on Windows
We ’ ll show you how to start with WebDriver apply Eclipse and the Java bindings on Windows, plus write and run one elementary test.
It ’ s easy to get up and lam with Selenium-WebDriver using Eclipse and the Java binding on Windows.In this clause we & # x27; ll demo you how to get the various parts and piece to configure selenium for Java, plus write and run one simple examination.
The Components You & # x27; ll Need
This tutorial will walk you through the total install process for every component, some of which you may have installed already. In some cases, you may desire to switch factor. This representative will include installs and configuration for:
Java
Eclipse
A examination framework (We ’ ll use JUnit; there are many you can use)
WebDriver ’ s Java bandaging
A Dependency Manager - examples will be in Maven
Google ’ s Browser Driving Engine - Chromedriver.exe
Regardless of what platform you ’ re on, there are many, many different environment setup for Java in Eclipse. Different teams will use different body-build and dependency systems such as Maven, Gradle, etc. The dependency for Webdriver are complex enough that we want to use one, so these examples will use Maven.
Getting Java
Naturally, WebDriver ’ s Java dressing require a version of Java to be on the system you ’ re running your tests from. WebDriver ’ s Java dressing require only the Java Runtime Environment (JRE), but you ’ ll be fine if you have either the Java Development Kit (JDK) or JRE installed. There are also different versions for Enterprise, SE, and other Java JRE/JDKs.
You can get Java from its download site. We ’ ll skip walking through Java installation in this article since it will vary based on the version you select. If you need advice, as of this authorship,use Java 8 Windows x84.
Getting Eclipse
Eclipse is one of respective widely popular editor for Java. It ’ s an open source undertaking maintained by the Eclipse Foundation, and has a huge market of add-ons, tools, and customizations. You can download the latest version ofEclipse for Java for Windows.

The installer is small utility that will configure, download, and install the particular Eclipse variant you ’ re looking for.
SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses.

For transience ’ s sake, and due to platform differences, we ’ ll cut the actual install steps in this guide.
Once Eclipse is installed you ’ re gratuitous to customize it as you care. There are a riches of themes and editor tweaks uncommitted both from the larger community and theEclipse Marketplace.

Creating The Project
Eclipse works with the concepts of workspaces—folders and infinite where you work with your projects. In this example, I ’ m utilise a pocket-size workspace I ’ ve merely make for example projects. Teams use different approaches for workspaces and project structures. Use whatever you like with your own small-scale sample projects; however, make sure to postdate your team ’ s pattern for real work. (Workspace and project structure is almost as hotly debated as tabs versus spaces. Be kind.)
This article uses a simple Java Project created by using the menu File = & gt; New = & gt; Java Project.

Fill out the basic information on the New Java Project dialog, so click Finish to proceed.

Adding WebDriver to Eclipse
As mentioned earlier, there are many ways to include WebDriver in your Eclipse projects. Most mature teams use a build and dependency management scheme like Maven or Gradle. This article uses Maven. To convert to Maven, right-click on the labor gens, select Configure, and convert to Maven Project.
This will bring up a dialog box to create a pom.xml file. Click “ Finish ” and you ’ ll be brought to a screen that bear the file. This file curb information on where to download extra libraries for the undertaking. We ’ ll add some XML code to the file, after and before. Here ’ s the code to add:
This code adds a new structure, called “ dependencies ”, and so two dependencies - Junit 5.1 (“ Jupiter ”) and selenium-java. Both of these are register with Maven. By adding them to the POM, the project becomes aware of them and can use the codification library as they were component of the project.
Browser Drive Engine
Finally, we ’ ll need to set up the browser driver engine. In the case of Chrome, this is a windows executable file called ChromeDriver.exe. The Java code will call this program, and the broadcast will manipulate the browser through its mechanisation engine. Firefox, Safari, and InternetExplorer/Edge all experience a like executable file. You ’ ll relieve the file in a exceptional directory, so tell the Java code how to detect the driver. In this case,download ChromeDriver‘ ve downloaded the zip file, expanded it, and put it in my “ home ” directory which is C: \users\matt. You ’ ll see that in the sample code below.
You ’ re done!
Writing Your First Test
WebDriver doesn ’ t know how to do anything other than talking to the browser driver. As a result, you ’ ll need some sort of examination framework to execute your tests, make assertions, and report trial status. We ’ ll use JUnit because 0) it ’ s very popular and 1) it ’ s included in Eclipse ’ s default installation.
Add a exam case to your Eclipse project via right click = & gt; New = & gt; JUnit Test Case.

Give your test case a full gens in the resulting dialogue and click Finish to create the file. Note I ’ ve used the default namespace for this test case—and that Eclipse is truly complaining about it. Again, be kind. Follow your team ’ standard practices for project organization and naming.

Note that Eclipse will helpfully add JUnit 5 (Jupiter) to your project if it ’ s not already on Eclipse ’ s build path.
You ’ ll find your first test instance set up and ready to author.
A Simple Test
Below is a complete tryout instance that starts a browser locally, execute a very bare exam, then closes out the browser example. The model is passing elementary and doesn ’ t follow normal practices like employ Page Object Patterns. This is example code, not production code!import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import stable org.junit.jupiter.api.Assertions. *;
importee org.junit.jupiter.api.Test;
meaning org.openqa.selenium.By;
importee org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
classSauceLabsHomePageTest {
@ BeforeEach
voidsetUp () {
}
@ BeforeEach
voidtearDown () {
}
@Test
public voidsite_header_is_on_home_page () {
System.setProperty(& quot; webdriver.chrome.driver & quot;, & quot; c\\users\\matt\\chromedriver.exe & quot;);
WebDriver browser = new ChromeDriver ();
browser.get (& quot; https: //www.saucelabs.com & quot;);
WebElement href = browser.findElement (By.xpath(& quot; //a [@ href= & # x27; /beta/login & # x27;] & quot;));assertTrue((href.isDisplayed ()));
browser.close ();
}
}
Running The Test
Execute the tryout by right-clicking in the test body and blue-ribbon Run As = & gt; JUnit Test Case. Alternatively, left-click on the name of the class and press Alt+Enter. The test will run and you ’ ll see the results in the JUnit Test Explorer pane.

Summing Up
In this post, you learned a bit about the various components that make up Selenium WebDriver. We also showed you how to install Intellij, gather up the respective WebDriver pieces necessary for Java tests in Intellij, and we show you an extremely simple exam on Windows.
Share this post
Automate This With SUSA
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.
Try SUSA FreeTest Your App Autonomously
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.
Try SUSA Free