Created
May 2, 2017 06:41
-
-
Save zhangyuan/81b67183b0884d4a6d54b6eff305bf62 to your computer and use it in GitHub Desktop.
Load local cookies.txt to browser in Cucumber and Capybara
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "http-cookie" # gem 'http-cookies' | |
| When /^Login domain.local$/ do | |
| visit "https://domain.local/not_found" | |
| cookie_jar = HTTP::CookieJar.new | |
| cookie_jar.load("/path/to/cookies.txt", :cookiestxt) | |
| cookie_jar.each do |cookie| | |
| next unless cookie.domain["domain.local"] | |
| hash = { | |
| name: cookie.name, | |
| domain: cookie.domain, | |
| value: cookie.value, | |
| path: cookie.path, | |
| expires: cookie.expires | |
| } | |
| page.driver.browser.manage().add_cookie(hash) | |
| end | |
| visit "https://domain.local/" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment