To get started with WebDriver for Java in Eclipse you will need the following components.
- JUnit Test Framework
- Binding library for WebDriver’s Java
The idea here is to keep things simple by using a statically linked library. However, there are different ways that can be used to setup Java in Eclipse.
Eclipse is an open source platform with various tools, add-ons, and customization option. However, it is widely used as an editor for Java. In order to install Eclipse on your OSx, you need to get the latest version from http://www.eclipse.org/downloads/eclipse-packages/. Then, execute the installer saved on your desktop. There are various themes and editors that can be used to customize the Eclipse as required.
You can either create a new workspace or use the existing one to manage your projects. Folders and spaces within the workspace are handled differently by different teams.
- Right-click on the workspace explorer and select New->Java Project
- On the New Java Project dialog, provide the basic information and click ‘Finish’ to proceed.
WebDriver has a number of different components, including the browser driver that manipulates browser directly through the automation interface of the browser. Browser driver proxies are implemented by browser vendors differently. You can use language binding option (client drivers) to write WebDriver script in your desired language. It helps in running the tests on the local system. However, you need a server component to run tests on multiple machines. Selenium Server manages the WebDriver instances on remote machines.
Adding WebDriver to Eclipse
You can use any build management system to include WebDriver in your eclipse project. However, you can include a simple static library. In order to load libraries into eclipse, download Java WebDriver bindings and Selenium Standalone Server, including FirefoxDriver.
- Right-click on the project and select Build Path->Configure Build Path.
- Select Java Build Path from the Project Properties dialog. In the Libraries tab, click ‘Add External Jars…”. Then browse to the folder where Selenium Java language bindings are present. Select the file and save your changes.
- Add Firefox driver proxy by dropping the file in ‘utils’ folder on the host system.
Writing and Executing Tests
- You can make use of a testing framework to execute your tests. Using JUnit you can add a test case to your Eclipse by New->JUnit Test Case.
- Name the project and click ‘Finish’.
- Once you have created the test cases, you can run it as a JUnit test by right-clicking the test body.
You may also like: How to use IntelliJ While Working with WebDriver in Java?