01/10/2018, 08:14
Giúp mình fix lỗi DataProvider trong TestNG, không thể pass 3/4 testcase còn lại
import java.io.File;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class TestScript03 {
private static WebDriver driver;
@DataProvider(name = "Authentication")
public static Object[][] credentials() {
return new Object[][] { { "mngr59425", "zytYtan" }, { "invalid", "valid" }, { "valid", "invalid" },
{ "invalid", "invalid" } };
}
@BeforeTest
public void setUp() {
System.setProperty("webdriver.chrome.driver", "G:\TestNG\selenium\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(Util.WAIT_TIME, TimeUnit.SECONDS);
driver.get(Util.BASE_URL);
}
@Test(dataProvider = "Authentication")
public void TestScript03(String username, String password) throws Exception {
String alertText, actualTitle;
driver.findElement(By.name("uid")).clear();
driver.findElement(By.name("uid")).sendKeys(username);
driver.findElement(By.name("password")).clear();
driver.findElement(By.name("password")).sendKeys(password);
driver.findElement(By.name("btnLogin")).click();
try {
Alert alt = driver.switchTo().alert();
alertText = alt.getText(); // get content of the Alter Message
Assert.assertEquals(alertText, Util.EXPECT_ERROR);
} catch (NoAlertPresentException Ex) {
actualTitle = driver.getTitle();
// On Successful login compare Actual Page Title with Expected Title
Assert.assertEquals(actualTitle, Util.EXPECT_TITLE);
}
}
@AfterTest
public void terminal(){
driver.quit();
}
}
import java.io.File;
public class Util {
public static final int WAIT_TIME = 30; // Delay time to wait the website
// launch completely
public static final String BASE_URL = "http://www.demo.guru99.com/V4/";
// Expected output
public static final String EXPECT_TITLE = "Guru99 Bank Manager HomePage";
public static final String EXPECT_ERROR = "User or Password is not valid";
}
Bài liên quan