Getting started with Selenium 4.0 and adding dependencies

Welcome to Selenium 4 series!

What you will Learn:

  • Create Maven project in eclipse
  • Add Selenium 4 maven dependencies in pom.xml
  • Download browser drivers
  • Create simple Selenium 4 test
  • Code snippet

Create Maven project in eclipse

Open eclipse IDE > File > New > Other > Type ‘Maven Project’ > Select ‘Maven Project’
Selenium 4.0

Click Next > Select checkbox ‘Create a simple project’

Selenium 4.0

Click Next > Add any desired ‘Group Id’ and ‘Artifact Id’ as shown below

Selenium 4.0

Click Finish to create the Maven project

Selenium 4.0

Right click the maven project and click ‘Refresh’. You should then see the folder structure as shown below

Selenium 4.0

Also Check: Selenium Online Training

Add Selenium 4 maven dependencies in pom.xml

Click pom.xml that you see in above snapshot and add ‘dependencies’ tag (after typing <dep, you can press Ctrl+Spacebar to auto-populate the tag name as shown below)  

Selenium 4.0

So this is how we have to add the ‘dependencies’ section

Also Check: Selenium Python Training

Selenium 4.0

Next, go to https://mvnrepository.com/ and search for ‘selenium java’

Selenium 4.0

Click ‘Selenium Java’. 

You can see latest version 4.0.0 

Selenium 4.0

Click latest version 4.0.0 link, gets redirected to below 

Selenium 4.0

Click this section to copy it

Paste it in dependencies section of pom.xml file

Selenium 4.0

Ctrl+Shift+F to format the file

Save the pom.xml file to automatically download all the dependencies of selenium 4

Once the save process completes, you will see ‘Maven Dependencies’ folder getting created 

Selenium 4.0

If you expand this folder, you will see all the Selenium 4 related dependencies

Selenium 4.0

If you see below error, just edit the pom.xml file and save it again. For example, you can edit <dependency> to <dependency and change it back to <dependency>

If you save it now, the error should disappear

Add webdriver manager dependency to manage browsers

We will next add webdriver manager dependency to pom.xml file so that we can execute test(s) on different browser types (like chrome, firefox etc.)

Selenium 4.0

Selenium 4.0

Selenium 4.0

Save the file, you will than see the webdrivermanager jar

The advantage of webdrivermanager is that, we don’t have to manually download the executables of different browsers (chrome, firefox etc.)

Create simple Selenium 4 test 

Create a simple java class and write the selenium code as shown below

Selenium 4.0

Run as Java application, notice that the browser is launched and gets navigated to desired website

Selenium 4.0

Below is the snapshot of console

Selenium 4.0

Code snippet

package sel4scripts;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import io.github.bonigarcia.wdm.WebDriverManager;

public class FirstSelTest {

public static void main(String[] args) {

WebDriverManager.chromedriver().setup();

WebDriver driver = new ChromeDriver();

driver.get(“https://www.bing.com/”);

}

}

We are now set to learn the new features in selenium 4. 

Thank you for reading!

Also Check: API Testing Training

Share On

Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp
Share on tumblr
Share on email

Leave a Comment

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

Scroll to Top

Lifetime Membership Club

LIFETIME MEMBERSHIP BIG SALE - ALL LIVE COURES JUST - 10000 RS/149 USD
Attend All Live courses in just 10000 rs / $149 - offer ends 25th April 2024