• Selenium Video Tutorials

IntelliJ for Selenium



We would need to configure Selenium with an editor to execute the automated tests. There are several editors available for example: Eclipse, IntelliJ, Atom, Sublime, and so on. Using these editors, we can begin working on a Java project to start test automation.

Prerequisites to set up IntelliJ for Selenium

Download and install Java (version above 17) with the below link, and validate if it is available with the following command −

java –version

https://www.oracle.com/java/technologies/downloads/.

To get more about Java configuration, please refer to the below link −

https://www.youtube.com/watch?v=bxIZ1GVWYkQ.

Download and install maven with the below link, and validate if it is available with the following command −

mvn -version

https://maven.apache.org/download.cgi.

To get more about Maven configuration, refer to the link Maven Environment Setup

Sets up IntelliJ for Selenium

Step 1 − Navigate to the official website of IntelliJ (which is a product of Jetbrains) using the below link and then click on Download −

https://www.jetbrains.com/idea/.

Selenium IntelliJ 1

Step 2 − Once we navigate to the next page, we will get the option to download IntelliJ in various operating systems, like Windows, macOS, and Linux. Click on the tab based on the current operating system.

IntelliJ comes in two versions, Paid and Community(which is free).

Selenium IntelliJ 2

Step 3 − We would download the Community version. For that we would move down to the IntelliJ IDEA Community Edition section and then click on Download.

Selenium IntelliJ 3

Step 4 − IntelliJ logo should display for a few seconds, and next the JETBRAINS COMMUNITY EDITION TERMS should appear. Click the checkbox to accept the terms and conditions, then click on Continue.

Step 5 − Welcome to IntelliJ IDEA should appear. Click on the New Project button.

Step 6 − Enter a name under Name: field. Select Language as Java, Build System as Maven, and a JDK version, then click on Create.

Step 7 − Enter an ArtifactId and then click on Create.

Step 8 − IntelliJ editor setup should be completed successfully.

Step 9 − Add the Selenium Maven dependencies to the pom.xml file from the link Selenium Java

Selenium IntelliJ 4

Step 10 − Selected and clicked on a version link under the Central tab. We navigated to the Selenium Java >> <version> page. Copied the dependency under Maven tab.

Selenium IntelliJ 5

Dependency example −

<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
   <groupId>org.seleniumhq.selenium</groupId>
   <artifactId>selenium-java</artifactId>
   <version>4.11.0</version>
</dependency>

Step 11 − Pasted the dependency copied in the Step 9 in the pom.xml file (available under the Maven Project created in the IntelliJ workspace).

Step 12 − Added the below code in the Main.java file.

Code Implementation

package org.example;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Main {
   public static void main(String[] args) throws InterruptedException {
      WebDriver driver = new ChromeDriver();
      driver.get("https://www.google.com");
      System.out.println("Browser title: " + driver.getTitle());
   }
}

Dependencies added in pom.xml file −

<?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>org.example</groupId>
   <artifactId>SeleniumJava</artifactId>
   <version>1.0-SNAPSHOT</version>
   
   <properties>
      <maven.compiler.source>16</maven.compiler.source>
      <maven.compiler.target>16</maven.compiler.target>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>

   <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
   <dependencies>
      <dependency>
         <groupId>org.seleniumhq.selenium</groupId>
         <artifactId>selenium-java</artifactId>
         <version>4.11.0</version>
      </dependency>
   </dependencies>
</project>

Step 13 − Right click and select Run ‘Main.main()’ option. Wait till the run has completed.

Step 14 − Chrome browser got launched, and we had got the output in the console- Browser Title: Google with the message Process finished with exit code 0, signifying successful execution of the code.

Along with that Chrome browser got launched with the message Chrome is being controlled by automated test software.

Conclusion

This concludes our comprehensive take on the tutorial on Intellij Selenium. We’ve started with describing prerequisites to set up IntelliJ for Selenium, and walked through steps to set up IntelliJ along with Selenium. This equips you with in-depth knowledge of the Intellij Selenium. It is wise to keep practicing what you’ve learned and exploring others relevant to Selenium to deepen your understanding and expand your horizons.

Advertisements