i create a function test false login test but i want to assert with those loop test
here is my sample data
@DataProvider(name = "Lgindataprovides")
public Object[][] getData(){
Object[][] data= {
{"[email protected]","12345666"}#email and password wrong (asset text = enter email is not available please register)
{"[email protected]","12345666"},#email correct password wrong (assert text = password is wrong)
return data;
}
here is my test
@Test(dataProvider = "Lgindataprovides", dependsOnMethods = "boofoo")
public void logintest(String email, String passowrd) {
driver.get("https://dummyurl/login");
driver.findElement(By.id("email")).sendKeys(email);
driver.findElement(By.id("password")).sendKeys(passowrd);
driver.findElement(By.cssSelector("button[type='submit']"));
Assert.assertEquals(get1stdatatest, "enter email is not available please register")
Assert.assertEquals(get2nderrordatatest, "password is wrong")
}
buts it fails this test case how can I handle this? what I want is
when this data"[email protected]","12345666"
is passed to the login test its should assert with this "enter email is not available please register"
when this data[email protected]","12345666
is passed to the login test its should assert with this "enter email is not available please register"
I see, you wand to check a unique error message per test data pair.
@DataProvider(name = "Lgindataprovides")
public Object[][] getData(){
Object[][] data= {
{"[email protected]","12345666", "error-message-1"},
{"[email protected]","12345666", "error-message-2"}
}
return data;
}
@Test(dataProvider = "Lgindataprovides", dependsOnMethods = "boofoo")
public void logintest(String email, String passowrd, String expectedError) {
driver.get("https://dummyurl/login");
driver.findElement(By.id("email")).sendKeys(email);
driver.findElement(By.id("password")).sendKeys(passowrd);
driver.findElement(By.cssSelector("button[type='submit']"));
Assert.assertEquals(getActualErrorMessage(driver), expectedError)
}
//*[contains(@class, 'some-error-class']
. So, you'll get any error message text on the form and it should work.private String getActualErrorMessage(WebDriver driver) {
driver.findElement(By.xpath("...")).getText();
}
You might also do it inline without creating a new method. Also add some waits/timeouts if you need.