简体   繁体   English

使用selenium hd在play框架测试中设置会话cookie

[英]Set session cookies in play framework testing using selenium hd

I am trying to do some unit testing using selenium hd. 我正在尝试使用selenium hd进行一些单元测试。 I currently have the following code: 我目前有以下代码:

    browser.goTo("http://localhost:3333/")
    browser.$("#email").text("michele@sample.com")
    browser.$("#password").text("secret")
    browser.$("#loginbutton").click()
    browser.goTo("http://localhost:3333/michele")

But I would like to be to be able to set a session cookie instead of having to do this for every test. 但我希望能够设置会话cookie,而不是每次测试都必须这样做。

I tried to do something like this 我试着这样做

    browser.webDriver.manage().addCookie( new Cookie("PLAY_SESSION",
      "1dd6811c9df64e03a892f55f57dd0f1190656d88-email%3Amichele%40sample.com") )

but doesnt work out, as I get a null pointer exception when I try to retrieve the cookie using browser.getCookie("PLAY_SESSION").getValue() must contain ("michele@sample.com") 因为当我尝试使用browser.getCookie("PLAY_SESSION").getValue()检索cookie时,我得到一个空指针异常,但是没有browser.getCookie("PLAY_SESSION").getValue()必须包含("michele@sample.com")

Any help is greatly appreciated!! 任何帮助是极大的赞赏!!

由于michele@sample.com被转换为michele%40sample.com,因此请尝试使用michele%40sample.com而不是michele@sample.com

browser.getCookie("PLAY_SESSION").getValue() must contain("michele%40sample.com")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM