JUnit - SPLessons

JUnit Selenium Test

Chapter 18

SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

JUnit Selenium Test

JUnit Selenium Test

shape Introduction

This chapter demonstrate the JUnit Selenium Test. Selenium Test automates the we browser and generate the search process like a normal user and known as automated tool for JUnit. Following are the concepts covered.

  • Selenium

Selenium

shape Description

JUnit Selenium Test can be created using JUnit which can automate a web browser to create test and operate at the same level as a real user. Selenium Test is a useful source tool for automating web browsers. The below demonstrate the JUnit Selenium Test.

shape Step 1

Visit the official page in  order to download Selenium Selenium.

shape Step 2

Now a page appears in a browser providing some options click on download link to get the JUnit Selenium Test as shown in below image.

shape Step 3

Now the page redirects and appear by providing some options like versions and more information select the appropriate one and download, as shown in below image.

shape Step 4

User need to add the JAR file to the Eclipse which can be done by the procedure mentioned below.

Right click on Project – > select Build Path – > click Configure Build Path

as shown in below image.

shape Step 5

Now a window get appears known as Properties for created project, click on Add External JARs button and add Selenium JAR file from local drive, proceed by clicking OK button as shown in below image.

shape Examples

The code below demonstrate searching the given web site in a given web browser by using the JUnit Selenium automated tool.

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class SeleniumTest {

	@Test
	public void CanOpenGoogle() {
		WebDriver driver = new FirefoxDriver();
		driver.get("http://google.com");
		WebElement searchBox = driver.findElement(By.name("q"));
		searchBox.sendKeys("splessons");
		searchBox.submit();
		
	}
	
}

The output for above code get generated in a given web browser as shown in below image.

Summary

shape Key Points

  • Selenium is automated web browser tool for JUnit.
  • In order to use selenium, user need to download and add to Eclipse environment.
  • User must give the search engine name while developing code.