Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

capybara-sessionkeeper

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

capybara-sessionkeeper

  • 0.2.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Capybara::Sessionkeeper

Gem Version Build Status

Save and restore cookies of capybara session

Installation

Add this line to your application's Gemfile:

gem 'capybara-sessionkeeper'

And then execute:

$ bundle

Or install it yourself as:

$ gem install capybara-sessionkeeper

Usage

Require with capybara

require "capybara"
require "capybara/sessionkeeper"

Supported drivers

[Recommended] Chrome driver is supported.
Install chromedriver

Capybara.register_driver :chrome do |app|
  Capybara::Selenium::Driver.new(app, browser: :chrome)
end

Firefox(:selenium option) may not work.
Install geckodriver

session = Capybara::Session.new(:selenium)

session will be equivalent to page in the system test.

It follows Capybara.save_path.

Save cookies

session = Capybara::Session.new(:chrome)
session.visit 'https://github.com/'
path = session.save_cookies

Save cookie file with specified file name.

session.save_cookies('user1.cookies.txt')

Restore cookies

You have to visit the site which you are trying to restore cookie beforehand.
Otherwise, you will get error.

session = Capybara::Session.new(:chrome)
session.visit 'https://github.com/'
cookies = session.restore_cookies

Restore cookie file with specified file name.

session.restore_cookies(File.join(Capybara.save_path, 'user1.cookies.txt'))

Save and restore cookies from YAML

Save cookie to yaml string (serialization to yaml).

yaml_str = session.cookies_to_yaml

Restore cookie from yaml string (deserialization from yaml).

session.restore_cookies_from_data(yaml_str, format: 'yaml')

Read cookies of current session

session.driver.browser.manage.all_cookies

On restoring cookies, this gem ignores Selenium::WebDriver::Error::InvalidCookieDomainError.
If you repeat save_cookies and restore_cookies in a single file, you could lose some cookies of domains you haven't visited.

This behavior can be changed in the future.

Some use cases are,
Save/Restore cookies by users/use cases/sites.
You can switch signed-in users easily.
You don't need to sign in every time.
You just need to sign in once(or occasionally) and save/restore cookies.

Development

Testing with :selenium(Firefox) driver

SELENIUM=true rspec

Test app

Some spec uses test app https://github.com/kyamaguchi/testapp-capybara-sessionkeeper

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/kyamaguchi/capybara-sessionkeeper.

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 03 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc