尝试在Play 2中测试时,Chrome WebDriver无法正常工作

时间:2014-05-13 15:02:20

标签: testing playframework-2.0 selenium-chromedriver fluentlenium

我正在尝试使用Fluentlenium测试Play 2应用。

这是其中一个测试用例的代码:

import org.junit.*;

import play.mvc.*;
import play.test.*;
import play.libs.F.*;

import static play.test.Helpers.*;
import static org.fest.assertions.Assertions.*;

import static org.fluentlenium.core.filter.FilterConstructor.*;
public class IntegrationTest {

/**
 * Verify if the Login Page is rendered correctly
 */
@Test
public void LoginPage() {
    running(testServer(3333, fakeApplication(inMemoryDatabase())), HTMLUNIT_, new Callback<TestBrowser>() {
        public void invoke(TestBrowser browser) {
            browser.goTo("http://localhost:3333");
            assertThat(browser.pageSource()).contains("Login");
        }
    });
}

当我使用HTMLUNIT执行此操作时,它工作正常,但有一些页面具有复杂的JavaScript,因此HTMLUNIT在某些测试用例上有所不同。

当我用FIREFOX替换HTMLUNIT时,它会启动Firefox,但在浏览器上没有做任何事情。

当我尝试使用CHROME时,它会给我一个&#34;找不到符号&#34;编译错误。我尝试下载ChromeWebDriver并将其复制到&#34; / usr / bin&#34;文件夹,但仍然无法正常工作。

我不知道问题出在哪里。

2 个答案:

答案 0 :(得分:-1)

您需要Chrome driver library,可能需要明确告诉您的应用在哪里找到它,例如这样:

System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "/extra/chromedriver")

答案 1 :(得分:-1)

我在Firefox启动时遇到了同样的问题,没有发生任何事情。 Play Framework中包含的最新Fluent版本与最新Firefox版本的更新不一致。

我要做的是升级Fluentlenium(目前版本为0.10.13)

// For Scala, add the latest fluentlenium dependency in build.sbt
libraryDependencies ++= Seq(
  <other dependencies of the project>
  "org.fluentlenium" % "fluentlenium-core" % "0.10.3" % "test"
)

同时降级Firefox(28.0似乎可以与Fluent集团0.10.3一起使用)

sudo apt-get purge firefox
sudo apt-get install firefox=28.0+build2-0ubuntu2