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(),但是因为代码块的相似性导致测试用例失败,我猜。所以我用&#试过了34; elementToBeClickable "。但它也会导致同样的错误。
请帮忙
先谢谢
答案 0 :(得分:0)
根据您提到的reset_invalid_email()
方法提出的问题,您可以使用以下解决方案:
几句话:
elementToBeClickable()
方法。driver.manage().window().maximize();
driver.quit()
方法中调用tearDown(){}
以关闭&正常销毁 WebDriver 和 Web客户端实例。您的工作代码块:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class q50598754 {
WebDriver driver;
@BeforeTest
public void setup()
{
System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");
driver=new FirefoxDriver();
driver.get("https://test.admin.placer.life/login");
}
@Test(priority=10)
public void reset_invalid_email()
{
//LoginPage login=new LoginPage(driver);
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.linkText("I forgot my password"))).click();
new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='app']/div/div[2]/p[contains(text(),'Reset Password')]")));
//login.set_reset_email("a@gmail.com");
//skipped to reproduce the error message The email field is required
//login.click_reset_button();
driver.findElement(By.cssSelector("button.btn.btn-primary.btn-block.btn-flat")).click();;
Assert.assertEquals(driver.findElement(By.cssSelector("div.form-group.has-feedback.has-error span.help-block")).getText(),"The email field is required.");
}
@AfterTest
public void close()
{
driver.quit();
}
}
控制台输出:
PASSED: reset_invalid_email
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================