Menu

HardAssertionExample

By testautomation | Selenium Code

Aug 27
package selenium;

import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;

public class HardAssertionExample {
	WebDriver driver;

	@Test
	public void testHardAssertion() {

		driver.get("https://www.google.com");
		String titleOfGoogleHomePage = driver.getTitle();
        String expectedTitleOfGoogleHomePate = "Google";
        String searchTerm = null;
        //searchTerm = "TestAutomation.co";
        Assert.assertEquals(titleOfGoogleHomePage, expectedTitleOfGoogleHomePate);	
        
		WebElement searchBox = driver.findElement(By.xpath("//input[@title='Search' and @type='text']"));
		Assert.assertNotNull(searchTerm);
		searchBox.sendKeys(searchTerm);
		WebElement submitSearchBtn = driver.findElement(By.name("btnK"));
		submitSearchBtn.submit();

	}

	@BeforeMethod
	public void beforeMethod() {
		System.setProperty("webdriver.chrome.driver", "C:\\chrome\\chromedriver_win32\\chromedriver.exe");
		driver = new ChromeDriver();

	}

	@AfterMethod
	public void afterMethod() {
		// driver.quit();
	}

}

About the Author

Leave a Comment:

Leave a Comment: