Automation Testing Using Selenium Java

Share

Automation Testing Using Selenium Java

Automation testing using Selenium with Java is a powerful combination to efficiently and effectively test web applications. Selenium is a popular open-source automation testing framework, and Java is a widely-used programming language for test automation. Below, I’ll guide you through the steps to set up a basic Selenium Java project and create a simple test script.

Step 1: Set up the project

  1. Install Java Development Kit (JDK): Download and install the latest JDK from the Oracle website or adopt OpenJDK.

  2. Install an Integrated Development Environment (IDE): Popular choices include Eclipse, IntelliJ IDEA, or NetBeans. Choose one and set it up.

  3. Download Selenium WebDriver: Visit the Selenium website and download the WebDriver for Java.

  4. Set up a Java Project: Open your IDE and create a new Java project. Add the Selenium WebDriver jar files to the project’s build path.

Step 2: Create a simple test script

Now, let’s create a basic test script to open a web page and perform some interactions.

  1. In your Java project, create a new class for your test script. For example, name it “SampleTest”.

  2. Import the necessary libraries:

java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
  1. Write the main test method:
java

public class SampleTest {
public static void main(String[] args) {
// Set the system property to the location of your ChromeDriver executable
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");

// Create an instance of ChromeDriver
WebDriver driver = new ChromeDriver();

// Maximize the browser window (optional)
driver.manage().window().maximize();

// Navigate to the desired URL
driver.get(“https://www.example.com”);

// Perform some interactions – e.g., click a link, fill a form, etc.
// For demonstration purposes, let’s print the page title
System.out.println(“Page Title: “ + driver.getTitle());

 

// Close the browser
driver.quit();
}
}

Step 3: Download and set up the WebDriver

To run tests with Selenium, you need the WebDriver for the respective browser (Chrome, Firefox, etc.). In this example, we’re using Chrome, so you need to download the ChromeDriver executable and specify its location in your code (as shown in Step 2, point 3).

  1. Download ChromeDriver: Go to the official ChromeDriver download page, and download the version compatible with your installed Chrome browser.

  2. Extract the ChromeDriver executable: After downloading, extract the executable file and remember its location.

Step 4: Run the test

Now, you can run the test script by executing the main method of your “SampleTest” class. The test should launch the Chrome browser, open the specified URL, print the page title, and then close the browser.

Remember to replace “path/to/chromedriver” with the actual path to your ChromeDriver executable.

Demo Day 1 Video:

 
You can find more information about Selenium in this Selenium Link

 

Conclusion:

Unogeeks is the No.1 IT Training Institute for Selenium Training. Anyone Disagree? Please drop in a comment

You can check out our other latest blogs on  Selenium here – Selenium Blogs

You can check out our Best In Class Selenium Training Details here – Selenium Training

💬 Follow & Connect with us:

———————————-

For Training inquiries:

Call/Whatsapp: +91 73960 33555

Mail us at: info@unogeeks.com

Our Website ➜ https://unogeeks.com

Follow us:

Instagram: https://www.instagram.com/unogeeks

Facebook:https://www.facebook.com/UnogeeksSoftwareTrainingInstitute

Twitter: https://twitter.com/unogeeks


Share

Leave a Reply

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