How to run an Effective Suite of Java Selenium Tests - Part1: in IDE
Running your Selenium JUnit tests in your IDE - the basics
Automated End-to-End testing is all about enabling frequent, reliable regression testing. The purpose behind automating End-to-End tests is to run them as frequent regression tests.
In this article, I will show you the basics of how to run Selenium Java tests with JUnit directly from your IDE (Integrated Development Environment).
Choosing an IDE
Many Java users I know use the IntelliJ IDE. IntelliJ has two versions, a paid version and a free Community edition. The Community edition is perfectly fine for developing automated E2E tests, and I recommend it.
Setting up Java Dependencies
Java projects require dependencies (e.g. Java ARchive, JAR, files) that your project and IDE need to know about to run tests.
Some IDEs (like IntelliJ) can connect to online repositories and download required JARs for you. There are also dedicated tools to manage dependencies (e.g. POM). However, you can always do it the old-school way and download the JARs manually.
I did the latter way, just to keep it super simple for this example project. WebDriver is an established protocol, which is stable and don’t need frequent updates.
Note: I did not add these static libraries into the project Git repository. Instead, symbolic linked the central Java Library folder.
Running Tests
First you will need to have a suite of Selenium JUnit tests to run.
I created 20 user-story-level Selenium tests for the WhenWise app. I developed all using IntelliJ, and here is the result of running them via the IDE:
In IntelliJ, it’s very easy to execute tests, as they are just JUnit tests. Simply right-click and run.
IDEs offer a lot of flexibility in running tests, you can run them at various levels:
Individual Test Cases
This is good for debugging and developing tests.Test Classes
Running related tests together.Multiple classes
Checking for interdependency between other tests.Package level
Running grouped tests.Whole project
Run everything.
Using an IDE for running tests
IDEs are great for developing and debugging tests, however, they are not the best choice for running frequently. Out of the box, IDEs don’t store test execution history or generate shareable reports.
Another drawback is that test execution can tie up your IDE. In headed mode, browser windows popping up; and making updates might shift line numbers, making debugging tricker. IDEs can also have settings that are specific to a machine or environment, that might not be used/set up by others; so it’s hard to share.
In Part 2, I’ll explore how running JUnit tests via the command line can mitigate some of these issues.
Related reading: