我想写一个selenium测试,它将检查当我登录我的应用程序,然后重新打开浏览器时,我会使用保存的cookie自动登录。
我认为在两个#{selenium}块之间调用clearSession()是可能的,但这似乎也清除了cookie。我已经测试过这个功能是否可以手动运行。
我是如何测试这个的。
供参考:这是我尝试过的。
#{fixture delete:'all', load:'../conf/User.yml' /}
#{selenium}
deleteAllVisibleCookies()
// Open the home page, and check that no error occurred
open('/')
waitForPageToLoad(1000)
assertNotTitle('Application error')
open('/login')
type('usernameOrEmail', 'marchaos')
type('password', 'password')
clickAndWait('css=input[type=submit]')
assertTextPresent('Welcome marchaos')
clearSession()
#{/selenium}
#{selenium}
// Open the home page, and check that no error occurred
open('/')
waitForPageToLoad(1000)
assertTextPresent('Welcome marchaos')
#{/selenium}
它在最后一个assertTextPresent()
失败了答案 0 :(得分:0)
我不知道Selenium,但你可以在功能测试中做到这一点。
我这样做:
Response loginResponse = FunctionalTest.GET("/user/login?login=test&password=test");
Map<String, Cookie> loginResponseCookies = loginResponse.cookies;
....
Request request = FunctionalTest.newRequest();
request.cookies = loginResponseCookies;
request.url = url;
return FunctionalTest.GET(request, url);