Skip to content
Related Articles

Related Articles

How to Create a Selenium Maven Project with Eclipse to Open Chrome Browser?

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 20 Apr, 2022

Maven is a Yiddish word meaning accumulator of knowledge, Maven is a build automation tool. It is a software project management and comprehension tool that can manage the project’s build, reporting, and documentation. Selenium is an open-source popular web-based automation tool. The major advantage of using selenium is that it supports all browsers like Google Chrome, Microsoft Edge, and Safari, works on all major OS and its scripts are written in various languages i.e Java, Python, JavaScript, etc. 

Eclipse IDE: We consider using the Eclipse IDE to work with the Selenium Maven project because Eclipse is open-source software and runs across different operating systems, Eclipse is an integrated development environment (IDE) for developing applications in Java and other languages such as C, C++, Python, etc. 

We will be discussing how to create a Maven project with Selenium to open the chrome browser, let’s consider a test case in which we will try to automate the following scenarios in the Google Chrome browser.

  • Launch Chrome browser.
  • Maximize the browser. 
  • Open URL: https://www.geeksforgeeks.org/

Installation:

  1. Java: To work with selenium Java is required, so download and install the Java JDK in your system, one must be aware of how to Download and Install Java for the 64-bit machine? 
  2. Eclipse IDE: Install the Eclipse IDE by referring to this article Eclipse IDE for Java Developers
  3. Chrome Driver: Download the Google Chrome browser.

Step By Step Implementation:

Step 1: Create a New Maven Project

1.1: From the File menu, choose New, and then choose Project.

 

1.2: In the New Project window, choose Maven Project and click next

 

 

1.3: Select the archetype to “org.apache.axis2.archetype” quickstart by entering “apache” in Filter box and click next.
 

 

1.4: Enter the Group Id and Artifact Id and click on Finish.

 

Step 2: Adding Dependency into the “pom.xml” file:

2.1: Go to Maven repository https://mvnrepository.com/

2.2: Search for selenium in the repository and select the Selenium java

 

2.3: Select the latest version and copy the dependency

 

2.4: Paste the dependency into “pom.xml” under the dependencies file and save.

 

Step 3: Create Java Class File in the src folder

Step 4: Set a system property “webdriver.chrome.driver” to the path of your ChromeDriver.exe file and instantiate a ChromeDriver class:

System.setProperty("webdriver.chrome.driver","C:\\Users\\ADMIN\\Documents\\chromedriver.exe");
ChromeDriver driver = new ChromeDriver();

Step 5: Write the code for opening the Google chrome and navigate to “geeksforgeeks.org”

Example:

Java




// Java Program to Illustrate Selenium Maven Project
// to Open Chrome Browser In Eclipse
  
package GFG_Maven.GFG_MAven;
  
// Importing required classes
import org.openqa.selenium.chrome.ChromeDriver;
  
// Class
public class Geeks {
  
    // Main driver method
    public static void main(String args[])
    {
        System.setProperty(
            "webdriver.chrome.driver",
            "C:\\Users\\ADMIN\\Documents\\chromedriver.exe");
  
        ChromeDriver driver = new ChromeDriver();
  
        // Maximize the browser
        // using maximize() method
        driver.manage().window().maximize();
  
        // Launching website
        driver.get("https://www.geeksforgeeks.org/");
    }
}

Step 6: Now click on Run In eclipse IDE to execute the code 

Output:

 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!