Selenium WebDriver with TestNG Sample Script

Selenium WebDriver with TestNG in Java – in this example, we will test the Google Calculator feature using Selenium for UI automation and TestNG as testing framework. You can download this java file here

public class calculatorTest {
	//Tests google calculator
	public void googleCalculator(){
		//Create firfox driver's instance
		WebDriver driver = new FirefoxDriver();
		//Set implicit wait of 10 seconds
		driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
		//Launch google
		//Write 2+2 in google textbox
		WebElement googleTextBox = driver.findElement("gbqfq"));
		//Click on searchButton
		WebElement searchButton = driver.findElement("gbqfb"));;
		//Get result from calculator
		WebElement calculatorTextBox = driver.findElement("cwos"));
		String result = calculatorTextBox.getText();
		//Verify that result of 2+2 is 4
		Assert.assertEquals(result, "4");

Leave a Comment

Pin It on Pinterest