Skip to content

Instantly share code, notes, and snippets.

@zhangyuan
Created May 2, 2017 06:41
Show Gist options
  • Select an option

  • Save zhangyuan/81b67183b0884d4a6d54b6eff305bf62 to your computer and use it in GitHub Desktop.

Select an option

Save zhangyuan/81b67183b0884d4a6d54b6eff305bf62 to your computer and use it in GitHub Desktop.
Load local cookies.txt to browser in Cucumber and Capybara
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