A Gentle, Newbie-Friendly Guide to Installing Selenium WebDriver – Part 2: Get Intellij!

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.

idea
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:

Intellij1

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:

Intellij2

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:

Intellij3

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.

Intellij4

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!

  • Pingback: A Gentle, Newbie-Friendly Guide to Installing Selenium WebDriver – Part 3: Get Testing! | James Willett - Technical Testing()

  • Pingback: Getting up and Running with Rest-Assured | James Willett - Technical Testing()

  • Ken

    Hello James,
    This is hands down one of the most simplified and ‘Actually’ newbie-friendly tutorials. Other tutorials I tried, did not explain explicitly that the dependencies in pom.xml help to download selenium webDriver and JUnit. I was under the impression I have to download selenium standalone jar or something, which was not explained anywhere, most tutorials had created the pom and asked to “add these lines to your pom.xml”

    Appreciate your work!
    Greetings!

  • James Willett

    Hi Ken,

    I am glad the tutorial has been helpful for you. When I started out with this stuff, I had very similar experiences to you, in that a lot of knowledge about certain aspects it is assumed you already know, or they are so obvious that the tutorial doesn’t mention it! Hopefully this is more “newbie friendly” 🙂

    Thanks for the feedback.

    James

  • Mike

    Agreed, this is easily understood even for a novice like myself.

    One thing James, you say “… you should see a popup in the top-right corner of the page – “Maven projects need to be imported”. ” I don’t see that anywhere.

    Does this mean they’re imported already?

    Thanks

    • James Willett

      Possibly, although you will soon find out when you try to build a project, as you will get an error then.

  • Gaze

    Thank you so so so much. This tutorial helped me a lot. I was tired of eclipse and as a regular user of pycharm I develop an attachment to jetbrains products. Thanks a lot again!

    • http://james-willett.com James Willett

      Thanks Gaze, I am pleased that it helped you!

  • Richa

    Hey James,

    Really appreciate your work!
    Thanks a lot…

    I am seeing cannot resolve error for “FirefoxDriver” though i have imported both –
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;

    Will you please help here!

    Richa

  • Stephanie

    This was an amazing tutorial! It also took me ‘an embarrassingly long amount of time’ figure out how to install Selenium webdriver within Intellij. So many other instructions that I found online are very piecemeal. Thank you for laying out the instructions (and the reasoning behind them) very simply! 🙂

  • Marit

    Excellent tutorials; very easy to get started. Thanks so much!
    Unfortunately I did have trouble with Selenium 3.0.1 and FireFox 49.0.2.
    Solution I found was to use geckodriver instead.
    See: http://stackoverflow.com/questions/37785686/how-to-use-the-gecko-executable-with-selenium
    tldr: In the sample code for first test, replace:

    FirefoxDriver driver = new FirefoxDriver();

    with:

    System.setProperty(“webdriver.gecko.driver”,”F:\\geckodriver.exe”);
    WebDriver driver = new FirefoxDriver();

    (With actual location of geckodriver)

    Also, add relevant import:
    import org.openqa.selenium.WebDriver;

    Download “geckodriver.exe” from https://github.com/mozilla/geckodriver/releases

    Information on how to add to maven (haven’t done this yet):
    https://github.com/bonigarcia/webdrivermanager

    • http://james-willett.com James Willett

      Thanks for the information Marit . I know that Firefox has recently switched over to the Gecko driver and it has caused lots of capability versions with Selenium. I appreciate you sharing your approach here.

      James