硒的功能测试在Grails上失败

时间:2011-07-14 15:23:41

标签: testing grails selenium functional-testing

我正在尝试将selenium测试与grails项目集成,并且出现了一些问题。

我正在使用selenium-rc插件

grails install-plugin selenium-rc

以下是测试中的错误:

ERROR: Element username not found

com.thoughtworks.selenium.SeleniumException: ERROR: Element username not found
    at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:97)
    at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:91)
    at com.thoughtworks.selenium.DefaultSelenium.type(DefaultSelenium.java:291)
    at com.thoughtworks.selenium.Selenium$type$0.call(Unknown Source)
    at grails.plugins.selenium.SeleniumWrapper.type(SeleniumWrapper.groovy)
    at com.thoughtworks.selenium.Selenium$type.call(Unknown Source)
    at com.example.DashboardTests.testTeste(DashboardTests.groovy:25)

这只是一个登录我的应用程序的测试。

这是测试代码:

import static org.hamcrest.Matchers.*
import static org.junit.Assert.*
import com.thoughtworks.selenium.*
import grails.plugins.selenium.*

import org.junit.*


@Mixin(SeleniumAware)
class DashboardTests extends GroovySeleneseTestCase{

    void testTeste() throws Exception {
        selenium.open("http://localhost:8080/login/auth")
        selenium.type("username", "user")
        selenium.type("password", "12345")
        selenium.clickAndWait("button")
    }
}

我不知道发生了什么,我以为可以配置,这里是代码:

selenium {

    slow = false                                    // true to run tests in slow resources mode
    singleWindow = true                             // true for single window mode, false for multi-window mode
    browser = "*googlechrome"                       // can include full path to executable, default value is *firefox or *iexplore on Windows
    url = "http://localhost:8080/"                      // the base URL for tests, defaults to Grails server url
    defaultTimeout = 60000                          // the timeout after which selenium commands will fail
    windowMaximize = false                          // true to maximize browser on startup
    screenshot {
        dir = "./target/test-reports/screenshots"   // directory where screenshots are placed relative to project root
        onFail = false                              // true to capture screenshots on test failures
    }
    server {
        host = "localhost"                          // the host the selenium server will run on
        port = 4444                                 // the port the selenium server will run on
    }
    userExtensions = ""                             // path to user extensions javascript file

}

我使用chrome作为浏览器,因为firefox在我的项目中导致错误。

如何解决?

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。

发生错误是因为我的测试环境没有上下文,这就是为什么selenium无法访问数据。

谢谢大家。