【发布时间】:2018-04-14 14:33:59
【问题描述】:
我对 Selenium HTMLUnit 还很陌生,所以我正在寻找一些帮助来为我的 Spring Boot 应用程序中的导航按钮创建基本测试。
我正在尝试进行一些基本测试,以确保我的 web 应用程序中的导航按钮按预期工作。我的方法是通过 Id 找到所需的导航按钮,单击它,然后检查当前 URL 是否是我期望的新页面。
...
private HtmlUnitDriver driver = new HtmlUnitDriver(true);
...
@Test
public void navigationTest() {
driver.get(BASE_URL);
WebElement button = driver.findElement(By.id("navigation_button_id"));
button.click();
String currentUrl = driver.getCurrentUrl();
Assert.assertThat(currentUrl, is(BASE_URL + "some_other_page"));
driver.close();
}
我尝试使用 .click() 方法(如上所示),我也尝试使用 Actions 对象而不是更简单的 .click() 方法(见下文)来执行导航,但这仍然没用。
Actions actions = new Actions(driver);
actions.click(button).build().perform();
目前的行为是 URL 没有从 BASE_URL 更改(例如http://localhost:8080),我已经验证它可以手动工作(亲自点击)但我无法通过测试点击按钮并告诉我 URL 已更改(表明用户已被带到新页面,例如 http://localhost:8080/some_other_page)。
任何人都可以提供一些建议以使其正常工作吗?我只需要测试基本导航的最简单方法就是在 HTMLUnit 中工作。
【问题讨论】:
标签: java selenium htmlunit ui-testing