0

I'm using capybara with capybara-webkit for testing, but I need to set some specific cookies.

I'm so confused by it's document, and the source code.

I did find a method here https://github.com/thoughtbot/capybara-webkit/blob/e6e2351a15cabf620152eb938e5cacb514fe1529/lib/capybara/webkit/browser.rb#L177

But I really don't know what format should I use for the 'cookie' param in this method.

If I have a cookie in json like this:

[
    {
        "domain": ".github.com",
        "expirationDate": 1453495731,
        "hostOnly": false,
        "httpOnly": false,
        "name": "__utma",
        "path": "/",
        "secure": false,
        "session": false,
        "storeId": "0",
        "value": "58162108.1841781874.1390418256.1390423639.1390423639.1",
        "id": 1
    },
    {
        "domain": ".github.com",
        "expirationDate": 1406191731,
        "hostOnly": false,
        "httpOnly": false,
        "name": "__utmz",
        "path": "/",
        "secure": false,
        "session": false,
        "storeId": "0",
        "value": "58162108.1390423639.1.1.utmcsr=developer.github.com|utmccn=(referral)|utmcmd=referral|utmcct=/",
        "id": 3
    },
    ... ...
]

How to modify the above into the correct acceptable string format for capybara-webkit? Can anyone give me an example?

Steven Yue
  • 966
  • 1
  • 8
  • 16

1 Answers1

3

The set_cookie method expects a valid value for the Cookie header as specified by RFC 2109.

The simplest value would be cookie_name=cookie_value. You can add other properties with a string like cookie_name=value; domain=example.com; path=/.

Joe Ferris
  • 2,712
  • 19
  • 18
  • Thanks for your answer! But the standard says you can set a list of cookies, followed by a comma. Seems like you can only do one at a time using `set_cookie`, correct? – Steven Yue May 07 '14 at 17:12
  • You should actually be able to set more than one. Under the hood, this uses [`QNetworkCookie::parseCookies`](http://qt-project.org/doc/qt-5/qnetworkcookie.html#parseCookies). – Joe Ferris May 07 '14 at 18:03