selenium - 断言确认的 webdriver 等效项是什么?

标签 selenium junit webdriver junit4

assertconfirmation 的 Webdriver 等效项是什么? 我有以下 selenium IDE 代码,当导出到 JUnit 4 (Webdriver) 时会返回错误:

IDE代码:

<tr>
    <td>click</td>
    <td>link=Logout</td>
    <td></td>
</tr>
<tr>
    <td>assertConfirmation</td>
    <td>Are you sure you want to logout?</td>
    <td></td>
</tr>

导出的 Webdriver 代码与上面对应:

@Test
    public void testUntitled2() throws Exception {
        driver.findElement(By.linkText("Logout")).click();
        // ERROR: Caught exception [ERROR: Unsupported command [getConfirmation]]
    }

我过去能够成功地使用 RC 来使用以下内容,但使用 webdriver 时它不再起作用 - (请注意我正在尝试将我的脚本迁移到 webdriver)

assertTrue(selenium.getConfirmation().matches("^Are you sure you want to logout[\\s\\S]$"));

干杯

最佳答案

应该是这个!

final String text = "Are you sure you want to logout?";
assertTrue(driver.switchTo().alert().getText().equals(text));

...或者可能是您那里的“matches()”版本。

switchTo()

alert()

getText()

关于selenium - 断言确认的 webdriver 等效项是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10178584/

相关文章:

java - 如何在 selenium 中自动执行 cmd 提示符和 vb 实用程序文件中的命令?

java - Hibernate 语句挂起

javascript - 如何通过 Jasmine JS 在 Webdriver 中操作 "text"的验证?

selenium - 如何在 Selenium 中按 shift + ctrl + s

selenium - WebDriver - 向浏览器发送 key 在 Firefox 中不起作用?

java - eclipse 错误 : 'Selection does not contain a main type/an applet'

java - 测试环境中可以使用HSQLDB替代MSSQL吗

java - Junit expectMessage 断言错误

python - python中用于测试自动化的随机数据

java - 如何使用 WebDriver 和 Java 制作 "background-image"CSS 列表