public class TestingLogin {
WebDriver driver;
@BeforeTest
public void setup()
{
System.setProperty("webdriver.gecko.driver", "\\GeckoDriver\\geckodriver.exe");
driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://test.admin.placer.life/login");
}
@Test(priority=9)
public void reset_null_email()
{
LoginPage login=new LoginPage(driver);
driver.findElement(By.xpath("//*[@id='app']/div/div[2]/a")).click();
WebDriverWait wait = new WebDriverWait(driver, 60);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='app']/div/div[2]/p[contains(text(),'Reset Password')]")));
login.set_reset_email("");
login.click_reset_button();
WebDriverWait wait_reset_psw = new WebDriverWait(driver, 10);
wait_reset_psw.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='app']/div/div[2]/form/div[2]/span[2]")));
Assert.assertEquals(driver.findElement(By.xpath("//*[@id='app']/div/div[2]/form/div[2]/span[2]")).getText(),"The email field is required.");
driver.navigate().refresh();
}
@Test(priority=10)
public void reset_invalid_email()
{
LoginPage login=new LoginPage(driver);
driver.findElement(By.xpath("//*[@id='app']/div/div[2]/a")).click();
WebDriverWait wait = new WebDriverWait(driver, 120);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='app']/div/div[2]/p[contains(text(),'Reset Password')]")));
login.set_reset_email("a@gmail.com");
login.click_reset_button();
WebDriverWait wait_reset_psw = new WebDriverWait(driver, 10);
wait_reset_psw.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='app']/div/div[2]/form/div[2]/span[2]")));
Assert.assertEquals(driver.findElement(By.xpath("//*[@id='app']/div/div[2]/form/div[2]/span[2]")).getText(),"The email field is required.");
driver.navigate().refresh();
}
@AfterTest
public void close()
{
driver.close();
}
}
大家好,我已经尝试过使用“ visibilityOfElementLocated ”的reset_invalid_email() ,但由于代码块的相似性,我猜这是导致测试用例失败的原因。所以我用“ elementToBeClickable ”进行了尝试。但它也导致了同样的结果错误。
请帮忙
提前致谢