Write a TestNG test method and use Data Provider annotation to provide multiple sets of data to the login form.
Create a method testlogin() to test the login feature with annotation @Test and data provider attribute to accept the multiple set of credentials for the login form.
Create another method which is a data provider method annotated with @DataProvider supplying the data sets to the above method.
package practice;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class Exercise3 {
@Test(dataProvider = "credentials")
public void testlogin(String email, String password) {
WebDriver driver = new ChromeDriver();
driver.get("https://proleed.academy/exercises/selenium/selenium-element-id-locators-practice-form.php");
driver.findElement(By.id("email")).sendKeys(email);
driver.findElement(By.id("password")).sendKeys(password);
driver.findElement(By.id("login")).click();
}
@DataProvider
public Object[][] credentials() {
return new Object[][] {
{"abc@gmail.com", "pass1"},
{"xyz@gmail.com", "pass2"},
{"abc@yahoo.com", "pass3"}
};
}
}
Copyright © 2023 - Proleed Academy | All Rights Reserved.