IntelliJ is a Java Integrated Development Environment used for software development which helps you to write better and faster code.

What is IntelliJ?

IntelliJ is an IDE developed and maintained by JetBrains. This IDE was particularly created for developing, importing, modelling, and for deploying computer software.

It is available in two versions, namely:

  • Community Version (Free and Open-Source)
  • Commercial Version (Licensed Version)

It provides services like advanced code refactoring capabilities and code navigation.

Advantages of IntelliJ

  1. It supports multiple languages like Javascript, Java, etc
  2. It supports multiple Operating Systems like Linux, Windows, etc. which can be downloaded from JetBrains website.
  3. For object attributes it generates setter and getter methods.
  4. It generates inbuilt packaging tools like Grunt, SBT, gradle, bower, etc.
  5. Databases like ORACLE, SQL, Microsoft SQL Server, PostgreSQL can be accessed directly from IDE.

Pre-requisites required for IntelliJ with Selenium Webdriver

We need following Pre-requisites for IntelliJ with Selenium Webdriver

  • IntelliJ
  • Any browser
  • JDK (Java Development Kit)
  • Selenium jar files

Download & Install IntelliJ

Step1: Go to the official website https://www.jetbrains.com/idea/download/#section=windows. And select the desired version of your choice. Here we are selecting “Community” version which is a Free and Open-Source. You can download “Ultimate” version for Web, mobile and enterprise development.

Step2: You can see a message like below while downloading.

Step3: Click on the Downloaded folder as shown below

Step4: Click on the ‘Next’ button in the setup wizard.

Step5: Click on ‘Next’ button and Browse your destination folder.

Step6: In this step

  1. Check the checkbox – 64-bit launcher
  2. Check the checkbox for language as per your requirement
  3. Click on ‘Next’ button

Step7: Click on ‘Install’ button

You can see the progress as IntelliJ installing.

Step8: In this step,

  1. To run IntelliJ, check the checkbox ‘Run IntelliJ IDEA Community Edition and
  2. Click the ‘Finish’ button

Step9: Click the checkbox ‘I confirm that I have read and accept the terms of this User Agreement’ and click ‘Continue’ button.

Step 10: Click on Skip Remaining and Set Defaults to set plugin setting.

Step 11: In this step, select the option like create a new project, import project, open, etc. as per your choice.

Configure IntelliJ to Support Selenium

Follow the below steps to configure IntelliJ IDE

Step 1: Launch IntelliJ IDE. Select File -> New -> Project and click on New to make a new Project.

Step2: A new screen will open when we click on Next button and give the project name and Click on Finish button. Your project has been created in IntelliJ.

Enter the Project Name as and click Finish button

Step3: Now add the Selenium’s .jar files into intelliJ as external libraries. Click on File-> Project Structure.

Go to Modules and click on Dependencies.

Click on ‘+’ Sign -> Select for JARs or directories in a project setting tab.

Step 4: Select all the selenium .jar files from the directory and subdirectory /lib.

Now, you can see that you have successfully added the .jar files into intelliJ and if you see your project structure, you will notice that you project’s /src directory is empty.

Step 5: Expand the Project and Right Click on /src directory -> Click on New -> Java Class and your project structure will look as below.

Example

We will use the site http://www.facebook.com/.

In this test scenario

  • We will launch the URL
  • Enter Invalid Email ID
  • Enter Password
  • Click the Log In button
  • The output will be as shown below- ‘Email id is not valid’

Program

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class SeleniumTest {

        public static void main(String[] args) {
            System.setProperty("webdriver.chrome.driver", "F:\\drivers\\chromedriver.exe");
            //create chrome instance
            driver = new ChromeDriver();
            driver.get("http://www.facebook.com/");
            WebElement element = driver.findElement(By.xpath("//input[@name='email']"));
            element.sendKeys("[email protected]");
            WebElement element = driver.findElement(By.xpath("//input[@name='pass']"));
            element.sendKeys("abbaas");
            WebElement button = driver.findElement(By.xpath("//input[@name='login']"));
            button.click();
        }
    }

Conclusion

  • IntelliJ is a Java Integrated Development Environment used for software development 
  • It has facilities like advanced code navigation and code refactoring capabilities.
  • IntelliJ comes with inbuilt plugins and packaging tools
  • The advantage of using intelliJ is
  1. It supports multiple languages like Javascript, Java, etc
  2. It supports multiple Operating Systems like Linux, Windows, etc. which can be downloaded from JetBrains website.
  3. For object attributes it generates setter and getter methods.
  4. It generates inbuilt packaging tools like Grunt, SBT, gradle, bower, etc.
  5. Databases like ORACLE, SQL, Microsoft SQL Server, PostgreSQL can be accessed directly from IDE.
  • To work with Selenium, you need to configure IntelliJ.