If you followed the 5-minute “Getting Started with Maven” guide from the previous post (link here incase you missed it), then you should now have Maven installed on your machine. From installing Maven, you should inturn also have installed the JDK on your machine. If not, go and check the Maven guide and come back here once you have the JDK and Maven installed.
We are now ready for the next step in getting Selenium WebDriver up and running, installing an IDE. You can use any Java IDE that you want, alot of people use Eclipse and its a great choice, but I am going to recommend Jetbrains Intellij.
I feel that this IDE is a little bit more friendly / forgiving to newer users and offers a lot of useful help/tips when there are errors in your code. Intellij has a free, open-source ‘Community Edition’ that is perfect for Selenium testing. You can download it from here – https://www.jetbrains.com/idea/download/
Once you have downloaded Intellij install it as normal by following the on-screen instructions. After the install has completed, launch Intellij and you should arrive at a landing page that looks something like below:
Intellij conveniently ties in with Maven, and we are going to use that functionality to get setup quickly. Go ahead and click “Create New Project” in Intellij. The “New Project” window opens, with several options. Simply select “Maven” from the left hand menu, and click next:
Next we need to enter a GroupId and ArtifactId for our project. You may have learnt a little about these from the Maven documentation in the previous post, but they are basically just names for our project. For the GroupId enter something like “com.mycompanyname.mytestapp” and for the ArtifactId enter “MyTestApp”. Click next.
Finally we need to enter a project name, and choose the location to save all the files. For the project name enter something like “MyFirstAutomationProject”, and choose a location that you will remember. Click “Finish” and the project will be created:
Once the project has been created Intellij should automatically open up the “pom.xml” file. This might look a little confussing but don’t worry, in just a few small lines of code we are going to install WebDriver and Junit directly from this file.
TIP: for Maven to work well with Intellij, it is important to turn on Auto-Import. When you open Intellij, you should see a popup in the top-right corner of the page – “Maven projects need to be imported”. Go ahead and click “Enable Auto-Import”. Now whenever we add a new dependency to the POM, Intellij will automatically import it through Maven.
Confussed? Don’t worry, it will all become clear soon! We are going to go ahead and install both Selenium and Junit in one swoop. Add the following code so that your POM.xml file looks like this:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mycompanyname.mytestapp</groupId> <artifactId>MyTestApp</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>2.43.0</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> </dependency> </dependencies> </project>
As soon as you type in this code, Intellij will automatically get to work installing Selenium and Junit for you.
Congratulations, you are now in a position to begin writing automated tests! When I first started out with this stuff, it took me an embarrassingly long time to get to this point, so I hope that I made it a little less painful for you.
In the next post we will check that the installation of Selenium was indeed successful, and we will write our first Selenium test!