Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Getting Started
3.
Writing First Automated Test
4.
Frequently Asked Questions
5.
Conclusion
Last Updated: Mar 27, 2024
Easy

Webdriver Installation and setup for first test case

Author Aman Thakur
0 upvote

Introduction

The installation and setup of Selenium WebDriver is divided into five steps:
1. Java 11 or above must be downloaded and installed.
2. Install and setup IntelliJ idea or any other Java IDE you choose.
3. Download Selenium WebDriver Java Client 
4. Configure Selenium WebDriver.
5. Writing our first test case.

Let's get started with the setup and writing our first test case in the world of automation testing.

Getting Started

Here are few steps which are need to be followed to install the the software onto your system successfully

1. The article assumes that you've previously installed Java 11 or higher on your PC and set up the environment variables you'll need to execute and build Java programmes. With the respective os of your choice.
After you've downloaded and installed the most recent version of Java, you'll need to define your path or adjust your system's environment variables. To learn how to set path and setup environment variables in Java, click the link below:
Setting up the Environment

2. Assuming that you have previously installed intellij, if not, you can follow the respective instructions accordingly, which are mentioned in intellij website on how to install the software on respective os from the official website.
Download IntelliJ IDE

3. After that if you have covered the above two steps it is time to install the web drivers for the system you can choose the chrome web driver for chrome or gecko web driver for firefox. This article is specific about installation of chrome web driver however you are independent of having your hands dirty by trying different web drivers of your choice.

3.1 Check the version of chrome that you are using before installing the web driver. Go to the chrome setting and click on the about chrome icon given below:

3.2 After that check the version of the chrome. And install the web driver accordingly.


Download Chromium Driver

4. After that install the Java client from the link given below :
Download Selenium JDK

4.1 Now download the Selenium server(GRID) stable version: 4.1.3 as showman in figure if it changes in the future download accordingly.

5. Now create a simple java project in intellij and add the external jar file which you have downloaded in step 4.1 to the current project.

File > Project Structure > Modules > Dependencies

Click on + button on to link the downloaded jar file to this project and then click on apply and then ok.

Writing First Automated Test

This section discuss the code to write the automated test for the project,

// FirstTest.java 
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;


public class FirstTest {
   public static void main(String[] args) {
       System.setProperty("webdriver.chrome.driver", "../Dependencies/chromedriver");
       WebDriver webdriver = new ChromeDriver();


       webdriver.get("https://codingninjas.com");
   }
}

Lets hit the run button and see it in action the automates test window will look like this as given below:

Frequently Asked Questions

1. What is the WebDriver interface Selenium?

Ans: WebDriver is a remote control interface that enables introspection and control of user agents (browsers). It helps in automating the test by running it in an actual web environment to mimic users.

2. How do you automate test cases?
Ans: Test Automation Best Practices
1. Determine which test cases should be automated.
2. Choose the Most Appropriate Automated Testing Tool.
3. Distribute your Automated Testing Workload.
4. Produce high-quality test data.
5. Develop automated tests that can withstand UI changes.

3. What is the difference between WebElement and WebDriver?
Ans: WebElement represents an HTML element. Selenium WebDriver encapsulates a simple form element as an object of the WebElement. It basically represents a DOM element and all the HTML documents are made up of these HTML elements.

Conclusion

If you have reached still here, you have enjoyed reading the blog and shall be heading towards the journey of automation testing. The article focuses on setting up the test for the selenium web drivers and writing the first test case in java.

You can also checkout our practice platform Coding Ninjas Studio to practise top problems, attempt mock tests, read interview experiences, and much more. Please upvote our blog to assist other ninjas in their development.

Happy Learning!

Live masterclass