Verify browser title using TestNG

package usinghtmlunit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.testng.annotations.Test;

public class verifybrowsertitleusingtestng {

@Test
public void FacebookTitle()
{
WebDriver driver = new HtmlUnitDriver();

driver.get(“http://facebook.com”);

System.out.println(driver.getTitle());
}

}

Verify browser title using TestNG and Assert

package usinghtmlunit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.testng.Assert;
import org.testng.annotations.Test;

public class verifybrowsertitleusingtestngandassert {

@Test
public void FacebookTitle()
{
WebDriver driver = new HtmlUnitDriver();

driver.get(“http://facebook.com”);

String fbTitle = driver.getTitle();

Assert.assertTrue(fbTitle.contains(“Facebook”));

System.out.println(fbTitle);
}

@Test
public void FacebookTitlenew()
{
WebDriver driver = new HtmlUnitDriver();

driver.get(“http://facebook.com”);

String fbTitle = driver.getTitle();

Assert.assertTrue(fbTitle.contains(“Selenium”));

System.out.println(fbTitle);
}

}

Run Selenium Tests in Firefox Browser using TestNG

package usingtestng;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;

public class ffbrowser {

public static WebDriver driver;

@Test
public void f() throws InterruptedException {

driver.get(“http://www.google.com”);

Thread.sleep(5000);

System.out.println(“Test case executed successfully… “);
}
@BeforeClass
public void beforeClass() {

driver = new FirefoxDriver();

driver.manage().window().maximize();

driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}

@AfterClass
public void afterClass() {

driver.quit();
}

}

1 5 6 7