在黄瓜测试使用水豚的曲奇饼 [英] Cookies within a cucumber test using capybara

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

问题描述

作为网站的集成测试的一部分,我使用黄瓜与水豚。似乎水豚不能效仿饼干的使用。



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

  def sign_in(user)
cookies.permanent.signed [:remember_token] = [user.id,user.salt]
current_user = user $ b $然而,当我稍后使用cookies.inspect获取cookie的值,它返回{} $ b(b)



$ b这是已知的限制水豚吗?如何在多个请求之间测试已登录的用户?



我应该添加我的测试:

 场景:用户登录时,他们按登录
由于我有一个现有的帐户,电子邮件bob@jones.com和密码123456
我在登录页面
当我用bob@jones.com填写电子邮件
我填写密码与123456
我按登录
然后我应该看到欢迎鲍勃琼斯


解决方案<



https://gist.github.com/484787


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.

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

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?

I should add my test:

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"

解决方案

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

https://gist.github.com/484787

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

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