Setup selenium in Java using Gradle

Prerequisite:

  1. Need to setup java properly in pc
  2. Need to setup Gradle
  3. Configure selenium

Let’s check if java is installed in our pc.

Go to cmd and hit following command:

> java -version

If Java is installed, then you will see the java version.

If Java is not installed before, then follow this tutorial to install java.

Now install Gradle. Download Gradle from here.

  1. Now extract the file and keep it in C:\Program Files\Java location
  2. Now go to environment variables and set GRADLE_HOME

3. Now set the Gradle path in variable value.

Now click on Ok button and go to cmd. Hit following command:

> gradle -version

If Gradle installed successfully, then you will see following output:

Configure selenium

  1. Now start IntelIJ and go to File>New>Project
  2. Select Gradle

3. Click on Next button and set project name and location

4. Click on Finish button

5. Apply automatic configuration.

6. Now go to build.gradle file and add following lines:

    // https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
    compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.141.59'
    // https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-remote-driver
    compile group: 'org.seleniumhq.selenium', name: 'selenium-remote-driver', version: '3.141.59'
    // https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-firefox-driver
    compile group: 'org.seleniumhq.selenium', name: 'selenium-firefox-driver', version: '3.141.59'
    // https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver
    compile group: 'org.seleniumhq.selenium', name: 'selenium-chrome-driver', version: '3.141.59'

These lines are actually Gradle command that will fetch all selenium driver and browser dependencies. So you don’t have to install selenium jar files manually. Gradle is a dependency manager that will fetch all plugins for the required version.

Now click on Gradle tab and click on import icon.

Now all dependencies has been imported. It’s ready to start writing code.

We will write our first selenium script in next tutorial.

about author

admin

salmansrabon@gmail.com

If you like my post or If you have any queries, do not hesitate to leave a comment.

One Comment on "Setup selenium in Java using Gradle"

Leave a Reply

Your email address will not be published. Required fields are marked *