0% found this document useful (0 votes)
6 views1 page

Assignment

The document is a Java class for a JUnit test that automates a Google search using Selenium WebDriver. It sets up a ChromeDriver, performs a search for 'Junit', and asserts that the search results contain the term 'Junit'. The test includes setup and teardown methods for managing the WebDriver lifecycle.

Uploaded by

pdatte1999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Assignment

The document is a Java class for a JUnit test that automates a Google search using Selenium WebDriver. It sets up a ChromeDriver, performs a search for 'Junit', and asserts that the search results contain the term 'Junit'. The test includes setup and teardown methods for managing the WebDriver lifecycle.

Uploaded by

pdatte1999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import org.junit.jupiter.api.

AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

import static org.junit.jupiter.api.Assertions.assertTrue;

public class GoogleSearchTest {


private WebDriver driver;

@BeforeEach
public void setUp() {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\pdatt\\
Downloads\\chromedriver-win64\\chromedriver-win64/chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();

@Test
public void testGoogleSearch() {
driver.get("https://www.google.com");
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("Junit");
searchBox.submit();

String pageSource = driver.getPageSource();


assertTrue(pageSource.contains("Junit"), "Kết quả không chứa từ
'Selenium'");
}

@AfterEach
public void tearDown() {

You might also like