Selenium会删除cookie吗?

时间:2015-05-27 18:03:15

标签: python django selenium cookies

为了使功能测试更清晰,我使用预先认证的会话,以便我可以跳过每个需要它的用例的登录。 使用Selenium,我访问网站并设置cookie。

def create_pre_authenticated_session(self, email):
    user = User.objects.create_user(email=email, password="pass")

    session = SessionStore()
    session[SESSION_KEY] = user.pk
    session[BACKEND_SESSION_KEY] = settings.AUTHENTICATION_BACKENDS[1]
    session.save()

    ## to set a cookie we need to first visit the domain.
    ## 404 pages load the quickest!
    self.browser.get(self.live_server_url + "/404_no_such_url/")
    self.browser.add_cookie(dict(
        name=settings.SESSION_COOKIE_NAME,
        value=session.session_key,
        path='/',
))

问题在于,在运行上面显示的功能后(我确认cookie已在浏览器中设置),我访问了与测试相关的地址,但cookie已经消失。

如果我对django dev服务器手动执行此用例,则一切正常。我可以跳过登录并直接进入相关页面。 硒版本是2.45

关于这里发生了什么的任何想法?

0 个答案:

没有答案