Assignment 11 STQA 11
Assignment 11 STQA 11
Roll No: 11
Assignment - 11
Implement Data provider Annotation on a testing website for username and password.
Code:
DemoDataProvider.java
import org.testng.annotations.Test;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.DataProvider;
public class DemoDataProvider1 {
@Test(dataProvider = "dp")
public void f(String un, String ps) {
System.setProperty("webdriver.chrome.driver", "S:\\SEM 3\\STQA\\102\\
chromedriver.exe");
WebDriver wd = new ChromeDriver();
wd.get("http://www.saucedemo.com");
wd.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
wd.findElement(By.id("user-name")).sendKeys(un);
wd.findElement(By.id("password")).sendKeys(ps);
wd.findElement(By.className("btn_action")).click();
try {
wd.findElement(By.xpath("//*[@id=\"react-burger-menu-
btn\"]")).click();
wd.findElement(By.xpath("/html/body/div/div/div/div[1]/div[1]/div[1]/div/div[2]/
div[1]/nav/a[3]")).click();
System.out.println("Login Success");
}catch(Exception e) {
System.out.println("Login Fail");
}
}
@DataProvider
public Object[][] dp() {
return new Object[][] {
new Object[] { "standard_user", "secret_sauce" },
new Object[] { "problem_user", "secret_sauce" },
new Object[] { "locked_out_user", "secret_sauce" }
};
}
}
Output: