2) If your project
is set up and you have selected the Test Case folder before creating TestNG
class then the source folder and the package name will be prepopulated on the
form. Set class name as ‘TestNG‘.
Under Annotations,
check “@BeforeMethod”, “@AfterMethod” and click Finish.
Now it is the time to write the first TestNG
test case.
5) Let’s take an
example of First Test Case and divide the test case in to three parts
@BeforeMethod: Launch Firefox
and direct it to the Base URL
@Test: Enter Username
& Password to Login, Print console message and Log out
@AfterMethod: Close Firefox
browser
package automationFramework;
import
java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import
org.openqa.selenium.WebDriver;
import
org.openqa.selenium.firefox.FirefoxDriver;
import
org.testng.annotations.Test;
import
org.testng.annotations.BeforeMethod;
import
org.testng.annotations.AfterMethod;
public class TestNG {
public WebDriver driver;
@BeforeMethod
public void
beforeMethod() {
// Create a new
instance of the Firefox driver
driver = new FirefoxDriver();
driver.get("http://www.Gmail.com");
}
@Test
public void main() {
// Find the element that's ID
attribute is 'account' And enter send keys
driver.findElement(By.id("Email")).sendKeys("malli.arjun440@gmail.com");
//
Click on Next Button
driver.findelement(by.id("next")).click();
// Find the element that's ID
attribute is 'pwd' (Password)
// Enter Password on the element found
by the above desc.
driver.findElement(By.id("Passwd")).sendKeys("Test@123");
// Now Sign In. WebDriver will find
the form for us from the element
driver.findElement(By.id("signIn")).click();
// Print a Log In message to the
screen
System.out.println("
Login Successfully, now it is the time to Log Off buddy.");
// Find the element that's ID
attribute is 'account_logout' (Log Out)
driver.findElement(By.id("account_logout"));
}
@AfterMethod
public void
afterMethod() {
// Close the driver
driver.quit();
} }
Results of running the Testng:
It displayed ‘passed : 1′. This means test is
successful and Passed.
As you see, there is information of which
test cases are executed and their duration. Take look to other tabs. Better
than Junit right?
Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.
ReplyDeletejava training in chennai
I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details.
ReplyDeletejava training in bangalore