用于验证 Web 应用程序中 "cancel" 按钮是否正常工作的方法

Methods used to verify a "cancel" button in web application works

我正在为 Web 应用程序编写测试用例。当前的工作需要我确认一下,当你按下注销按钮时,会出现提示,你可以点击提示上的取消按钮,提示就会关闭。

我想知道我可以用来确认此功能是否有效的验证和断言方法。取消按钮除了关闭弹出提示外什么都不做。你们会用什么?

这是一些代码:

Actions actions = new Actions(driver);
WebElement logout = driver.findElement(By.xpath(".//*[@id='flow']/div[1]/div/div[7]/div/div[3]/div[4]/div/div/div/div/div/div/div/div[1]/div/img"));
actions.moveToElement(logout).build().perform();
WebElement logoutHover = driver.findElement(By.xpath(".//*[@id='flow']/div[1]/div/div[7]/div/div[3]/div[4]/div/div/div/div/div/div/div/div[3]/div/img"));
logoutHover.click();
WebElement logoutPushed = driver.findElement(By.xpath(".//*[@id='flow']/div[1]/div/div[7]/div/div[3]/div[4]/div/div/div/div/div/div/div/div[4]/div/img"));
logoutPushed.click();
WebElement cancel = driver.findElement(By.xpath("html/body/div[3]/div[4]/div/div/div[6]/div[2]/div/div[2]/div/div[3]/div/div/div/div[5]/div"));
actions.moveToElement(cancel).build().perform();
WebElement cancel2 = driver.findElement(By.xpath("html/body/div[3]/div[4]/div/div/div[6]/div[2]/div/div[2]/div/div[3]/div/div/div/div[5]/div"));
cancel2.click();

WebElement pageText = driver.findElement(By.xpath("html/body/div[3]/div[1]/div/div[3]/div/div/div/div/div/div/div/div/div[2]/div[2]/div/div/div/div/div[2]/div"));
Assert.assertTrue("Text not found!", pageText.contains("PRODUCT LIST"));

这个断言方法不起作用。我最初的想法是,如果您点击取消按钮,我可以断言用户仍在同一页面上(我的代码不起作用)。断言提示不再存在是否是更明智的选择?如果是这样,我该怎么做?

我认为正确的做法是确认注销提示不再出现并且您仍处于登录状态。我不知道您的网站是什么样子,但对于注销提示,请找到该弹出窗口独有的元素(可能是确定或取消按钮,最好是带有 ID 的东西)。检测到它不再可见,然后通过某种方式确认您仍处于登录状态...查找用户名或 ???

// click the logout button

// click the cancel button

List<WebElement> button = driver.findElements(By.id("sampleId")); // a button on the confirm popup
if (button.isEmpty())
{
    // the logout confirmation popup is not visible

    // verify that you are still logged in... maybe look for a user name or ???
}
else
{
    // log a failure here because you couldn't cancel the logout popup
}