【问题标题】:Selenium test to test cookieSelenium 测试来测试 cookie
【发布时间】:2012-02-01 01:04:42
【问题描述】:

我想编写一个 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() 失败

【问题讨论】:

标签: cookies selenium playframework


【解决方案1】:

我不了解 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);

【讨论】:

    猜你喜欢
    • 2013-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-02
    • 1970-01-01
    • 1970-01-01
    • 2016-10-15
    相关资源
    最近更新 更多