Test NG
Test NG
Test NG
Benefits of TestNG
annotations.
Annotations are strongly typed, so the
Steps to follow:
Press Ctrl+N , select TestNG Class
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;
@Test
public void main() {
// Find the element that's ID attribute is 'account'(My
Account)
driver.findElement(By.id("account")).click();
// Find the element that's ID attribute is 'log'
(Username)
// Enter Username on the element found by above
desc.
driver.findElement(By.id("log")).sendKeys("testuser_1")
;
// Find the element that's ID attribute is 'pwd' (Password)
// Enter Password on the element found by the above
desc.
driver.findElement(By.id("pwd")).sendKeys("Test@123");
// Now submit the form. WebDriver will find the form for
(Log Out)
driver.findElement(By.id("account_logout"));
}
@BeforeMethod
public void beforeMethod() {
// Create a new instance of the Firefox driver
driver = new FirefoxDriver();
//Put a Implicit wait, this means that any search
TimeUnit.SECONDS);
//Launch the Online Store Website
driver.get("http://www.onlinestore.toolsqa.com");
}
@AfterMethod
public void afterMethod() {
// Close the driver
driver.quit();
}
}
Run the test by right click on the test case
script and select Run As > TestNG Test.