Selenium 的功能测试在 Grails 上失败
我正在尝试将 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 在我的项目中导致错误。
如何解决呢?
I'am trying to integrate selenium tests with a grails project and some problems are appearing.
I am using the selenium-rc plugin
grails install-plugin selenium-rc
Here are the errors in the tests:
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)
This is just a test that log in my application.
Here is the test code:
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")
}
}
I don't know what is happening, I thought that can be the configuration, here is the code:
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
}
I am using chrome as the browser because firefox was causing errors in my project.
How to resolve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我解决了这个问题。
发生错误是因为我的测试环境没有上下文,这就是为什么 selenium 无法访问数据。
谢谢大家。
I resolved the issue.
The error occurred because my test environment was without context, thats why selenium can`t access the data.
thanks all.