我正在尝试将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在我的项目中导致了错误。
如何解决?
发布于 2011-07-18 23:25:01
我解决了这个问题。
出现这个错误是因为我的测试环境没有上下文,这就是selenium无法访问数据的原因。
谢谢大家。
https://stackoverflow.com/questions/6695719
复制相似问题