Using Selenium WebDriver With Java for Automated Testing: Part I

Using Selenium WebDriver With Java for Automated Testing: Part I

Installing Java, Maven, and IntelliJ

In this article I will simplify the process of setting up and using Selenium WebDriver with Java and running a first test. In later articles I will go into more detail about the tools and processes we're using and why, but this will be a quick tutorial to get you off to a running start. Let's get right into it. I'm going to show you how to setup your system for test automation using Selenium WebDriver and Java. I'm running Windows 10 on my laptop for this demonstration.

Installing Java JDK for Windows

Download the current version of Java JDK if you don't have it installed already. To check, pull up your command line and type javac -version to see if it is installed. If it is, a version will be returned to the screen. At the time of writing this I am running Java 17.0.2.

checking_java_version.png

If not, downloading Java and installation is necessary.

java_windows.png

Installing Maven for Windows

Next install Maven, which is a build management application for Java. This tool automates the entire software build lifecycle.

Visit the Maven site.

dl_maven_win1.png

Scroll down the page, select the Windows tab, download the Windows binary zip file, unzip the file and place the folder in C:\Program Files.

dl_maven_win_binary_zip.png

maven_unzipped.png

Installing IntelliJ IDEA Community Edition

Next we need to install an IDE to write and run our Java code. IntelliJ IDEA Community Edition is IntelliJ's free IDE version. Go to this site to download it and then install it.

download_intellij_free.png

Setting System Environment Variables

Next, we will set the environment variables for Java and Maven. This can be confusing but let's not let make it. Follow the steps closely as we set each application up with system environment variables.

Here's a useful resource for understanding what setting them does, which is to make sure things get installed in their proper place.

For IntelliJ IDEA this will be determined during installation when you select if you want to install it just for yourself or all users. It will set the environment variables at that time.

  1. Type "system environment" in your windows search field to pull up the app.
  2. Once the System Properties dialog box appears,
  3. Select the Advanced tab.
  4. Click on the Environment Variables button.
  5. The Environment Variables screen will appear.
  6. Click the New button from the System Variables portion of the screen located at the bottom
  7. The New System Variable screen will appear.
  8. Type %JAVA_HOME% in the Variable Name field.
  9. Click the Browse Directory button to locate the directory that you installed Java in and select it.
  10. The directory location should appear in the Variable Value field.
  11. Hit the OK button.
  12. Next scroll through System Variables to find Path. There will already be entries listed here.
  13. Select the Edit button.
  14. Once the dialog appears, select the New button.
  15. Enter %JAVA_HOME%\bin

java_new_sys_variable.png

Repeat the EXACT same steps for Maven except use %MAVEN_HOME% and %MAVEN_HOME%\bin

maven_sys_var_new.png

Java_Maven_path.png

java_maven_compiler.png

When everything is complete, you can open up CMD and check your versions and paths. Here is my CMD screen showing all the commands I used to show the information:

all_paths_versions.png

Next ---> Creating a Maven Project in IntelliJ IDEA.

Check out the next article Using Selenium WebDriver with Java for Automated Testing Part II: Create a Maven Project and Run Your First Test