1
如果在执行打印操作后屏幕上出现错误,我需要测试失败。硒测试。简单的例外,如果在屏幕上出现错误
目前,该代码工作:
[TestMethod]
[Description("Should Print")]
public void PrintDetails()
{
mainPage.PrintDetails(driver);
Thread.Sleep(300);
Wait.WaitForNoErrorMsg(driver);
}
-
public static void WaitForNoErrorMsg(IWebDriver driver)
{
string errorMsg = "//div[@class='errorMessage']";
try
{
WaitForElementNotVisible(driver, errorMsg, 3);
}
catch (Exception)
{
throw;
}
}
-
public static void WaitForElementNotVisible(IWebDriver driver, string locator, int seconds)
{
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(seconds));
wait.Until(ExpectedConditions.InvisibilityOfElementLocated(By.XPath(locator)));
}
我觉得这不是一个最佳的方式,它可以用做更好的ExpectedException。我对吗? 你能举个例子吗?
非常感谢!该解决方案正在工作。纠正我,如果我错了,但我想,“errorMessagePresent”应重新命名为“errorMessageAbsent”,因为我们等待(验证),将不会有错误。最后一行代码应该像Assert.IsTrue(errorMessageAbsent); –
@NikolayM好吧,这取决于你是否想测试以检查错误是否存在或它是否存在。我会做两个测试。在第一个馈送正常输入中,验证是否缺少错误消息,并在第二个馈送错误输入中验证是否存在错误消息。 – Gilles