
๐How to Set Up IntelliJ IDEA with Selenium WebDriver
How to Set Up IntelliJ IDEA with Selenium: IntelliJ IDEA is one of the most powerful Java IDEs developed by JetBrains. It supports a variety of languages and tools and is ideal for Selenium-based test automation using Java.
This guide will help you install IntelliJ, configure Selenium libraries, and run your first Selenium test using IntelliJ.
๐ Table of Contents
- What is IntelliJ IDEA?
- Pre-requisites for Selenium Setup in IntelliJ
- How to Download and Install IntelliJ
- Configure IntelliJ for Selenium WebDriver
- Create a Selenium Example Project in IntelliJ
- Advantages of Using IntelliJ
- Summary
What is IntelliJ IDEA?
How to Set Up IntelliJ IDEA with Selenium: IntelliJ IDEA is a full-featured Java IDE used for developing software applications. Developed by JetBrains, it offers both a free Community Edition and a paid Ultimate Edition. IntelliJ stands out due to:
- Intelligent code completion
- Code navigation
- Powerful refactoring tools
- Built-in support for Gradle, Maven, Git, and more
Pre-requisites for Selenium Setup in IntelliJ
How to Set Up IntelliJ IDEA with Selenium: Before starting, ensure the following are available:
- โ
IntelliJ IDEA (Community or Ultimate)
- โ
Java Development Kit (JDK) installed
- โ
Web browser (Firefox recommended for this example)
- โ
Selenium Java .jar files
Download from: https://www.selenium.dev/downloads/
Extract .jar files from the ZIP to a local directory.
How to Download and Install IntelliJ
Step 1:
Visit the
Select Community Edition (Free) or Ultimate Edition
Step 2:
Download the setup file and run the installer.
Step 3 to 8:
Follow the wizard steps:
- Choose install location
- Select 32-bit launcher (optional)
- Select UI language
- Click Install and then Finish
Step 9-10:
- Choose whether to import settings from a previous version.
- Accept the JetBrains Privacy Policy.
Step 11-13:
- Set up initial plugins (optional).
- Choose Create New Project on the welcome screen.
- Create a project with name, e.g., Selenium_Guru99.
Configure IntelliJ for Selenium WebDriver
Step 1:
Go to File โ New โ Project. Select Java and click Next.
Step 2:
Name the project (e.g., Selenium_Guru99) โ Click Finish.
Step 3: Add Selenium .jar Files
Go to File โ Project Structure โ Modules โ Dependencies
Click the โ button โ JARs or Directories โ Select all .jar files from the Selenium folder and /lib subfolder.
Step 4:
Right-click the /src directory โ New โ Java Class
Create your test class (e.g., LoginTest)
Create a Selenium Example Project in IntelliJ
Test Scenario:
How to Set Up IntelliJ IDEA with Selenium: We will automate the following:
- Launch a browser
- Navigate to URL
- Enter an invalid email
- Click submit
- Validate error message
Example Java Code:
java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.By;
public class LoginTest {
public static void main(String[] args) {
System.setProperty(“webdriver.gecko.driver”, “path_to_geckodriver”);
WebDriver driver = new FirefoxDriver();
driver.get(“https://example.com/login”);
driver.findElement(By.id(“email”)).sendKeys(“abc.gmail.com”);
driver.findElement(By.id(“submit”)).click();
String errorMsg = driver.findElement(By.id(“error”)).getText();
System.out.println(“Error Message: ” + errorMsg);
driver.quit();
}
}
Output:
- Firefox browser opens
- Invalid email is entered
- Error message displays: “Email ID is not valid.”
๐ Advantages of Using IntelliJ for Selenium
- How to Set Up IntelliJ IDEA with Selenium: Auto-generates getter/setter methods
- Wraps code in try-catch or if-else blocks with simple shortcuts
- Built-in support for Gradle, Maven, Grunt, SBT
- Access databases like MySQL, Oracle, PostgreSQL from the IDE
- Supports multiple languages: Java, JavaScript, Clojure, Kotlin
- Compatible with Windows, macOS, Linux
๐ Summary
- How to Set Up IntelliJ IDEA with Selenium: IntelliJ IDEA is a powerful and user-friendly IDE for Java development.
- Easily integrates with Selenium WebDriver for automation testing.
- Offers smart features like code refactoring, navigation, plugin support, and cross-platform compatibility.
- With proper configuration and Selenium libraries, you can run and manage robust automation test scripts efficiently.