2

与 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]$"));

干杯

4

1 回答 1

4

应该是这个!

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

...或者也许是你得到的“matches()”版本。

切换到()

警报()

获取文本()

于 2012-04-16T18:03:01.563 回答