0

我目前正在学习使用Wisdom 框架作为后端的角度教程。因此,正如智慧框架文档所述,我使用Fluentlenium运行端到端测试。

我对第 3 步的测试虽然非常简单,但没有通过。

完整的测试可以在 github 上找到:Step03IsImplementedIT

然而,这是有问题的摘录(大约第 30 行)

@Test
public void canTestPageCorrectly() {
    if (getDriver() instanceof HtmlUnitDriver) {
        HtmlUnitDriver driver = (HtmlUnitDriver) getDriver();
        if(!driver.isJavascriptEnabled()) {
            driver.setJavascriptEnabled(true);
        }
        Assert.assertTrue("Javascript should be enabled for Angular to work !", driver.isJavascriptEnabled());
    }
    goTo(GoogleShopController.LIST);
    // Et on charge la liste des téléphones
    FluentWebElement phones = findFirst(".phones");
    assertThat(phones).isDisplayed();

    FluentList<FluentWebElement> items = find(".phone");
    assertThat(items).hasSize(3); // <-- this is the assert that fails
}

失败信息:

canTestPageCorrectly(org.ndx.wisdom.tutorial.angular.Step03IsImplementedIT)  Time elapsed: 2.924 sec  <<< FAILURE!
java.lang.AssertionError: Expected size: 3. Actual size: 1.
    at org.fluentlenium.assertj.custom.FluentListAssert.hasSize(FluentListAssert.java:60)
    at org.ndx.wisdom.tutorial.angular.Step03IsImplementedIT.canTestPageCorrectly(Step03IsImplementedIT.java:33)

从那次失败中,我猜角度控制器没有加载。

我怎样才能确保它们是?我怎样才能进行工作测试?

4

1 回答 1

0

原来错误不是预期的错误......嗯,它是,但以一种隐藏的方式。

HtmlUnitDriver众所周知,它是浏览器的纯 Java 实现,因此有一些限制。

它的限制之一是 Javascript 解释,它似乎与 angular 一起变得非常糟糕......

长话短说,解决这个问题的最简单方法是用 Firefox 替换默认驱动程序,这意味着

  • 设置fluentlenium.browserfirefox
  • 通过在测试开始时添加一个小断言来确保驱动程序正确加载(因为firefox.exe在尝试使用其驱动程序时应该在路径上)

然后是最终测试

    assertThat(getDriver()).isInstanceOf(FirefoxDriver.class);
    goTo(GoogleShopController.LIST);
    FluentList<FluentWebElement> items = find("li");
    FluentLeniumAssertions.assertThat(items).hasSize(3);
    fill("input").with("nexus");
    await();
    items = find(".phone");
    FluentLeniumAssertions.assertThat(items).hasSize(1);
    fill("input").with("motorola");
    await();
    items = find(".phone");
    FluentLeniumAssertions.assertThat(items).hasSize(2);
于 2014-07-09T12:08:32.373 回答