使用水豚进行黄瓜测试中的饼干 [英] Cookies within a cucumber test using capybara

查看:14
本文介绍了使用水豚进行黄瓜测试中的饼干的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为我对网站的集成测试的一部分,我使用 cucumber 和 capybara.似乎水豚无法模仿使用 cookie.

As part of my integration tests for a website I am using cucumber with capybara. It seems that capybara cannot emulate the use of cookies.

例如我在用户登录时设置cookie:

For example I set the cookie when the user signs in:

    def sign_in(user)
      cookies.permanent.signed[:remember_token] = [user.id, user.salt]
      current_user = user
    end

但是,当我稍后使用 cookies.inspect 获取 cookie 的值时,它会返回 {}这是水豚的已知限制吗?如果是这种情况,如何通过多个请求测试登录用户?

However when I later fetch the value of cookies using cookies.inspect it returns {} Is this a known limiting of capybara? How can I test a signed in user over multiple requests if this is the case?

我应该添加我的测试:

Scenario: User is signed in when they press Sign In
 Given I have an existing account with email "bob@jones.com" and password "123456"
 And I am on the signin page
 When I fill in "Email" with "bob@jones.com"
 And I fill in "Password" with "123456"
 And I press "Sign In"
 Then I should see "Welcome Bob Jones"

推荐答案

这是在运行功能时显示 cookie 内容的好方法

here's a nice way to show the content of the cookies while running your feature

https://gist.github.com/484787

这篇关于使用水豚进行黄瓜测试中的饼干的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆