项目作者: kyamaguchi

项目描述 :
Sign In Amazon using Capybara and Selenium
高级语言: Ruby
项目地址: git://github.com/kyamaguchi/amazon_auth.git
创建时间: 2017-03-08T07:40:58Z
项目社区:https://github.com/kyamaguchi/amazon_auth

开源协议:MIT License

下载


AmazonAuth

Gem Version
CircleCI

Sign In Amazon using Capybara and Selenium

amazon_auth_login

Recorded with Recordit

Installation

Add this line to your application’s Gemfile:

  1. gem 'amazon_auth'

And then execute:

  1. $ bundle

Or install it yourself as:

  1. $ gem install amazon_auth

Requirements

  • chromedriver

Before running, you need to download chromedriver.
And you may need to update chromedriver regularly.
Please download latest chromedriver_xxx.zip from https://chromedriver.storage.googleapis.com/index.html and place it somewhere on your PATH.

  1. mv ~/Downloads/chromedriver /usr/local/bin/

Usage

Set Amazon credentials on your local machine

[Quick] You can set login and password in console.

[Recommended] Or you can convert them to protect them against shoulder surfing.
Run amazon_auth and paste the output to .env.
(AMAZON_USERNAME_CODE , AMAZON_PASSWORD_CODE and AMAZON_CODE_SALT)

amazon_auth_setup

envchain for security

You can store environment variables in macOS Keychain instead of dotenv.
Check out envchain

  1. brew install envchain
  2. envchain --set amazon AMAZON_DOMAIN AMAZON_USERNAME_CODE AMAZON_PASSWORD_CODE AMAZON_CODE_SALT
  3. # Run console with envchain
  4. envchain amazon bin/console
  5. envchain amazon bundle exec irb
  6. envchain amazon rails console

Run

In console, you can move around pages using Capybara DSL

  1. # Without credentials in .env
  2. client = AmazonAuth::Client.new(login: 'your_amazon_email', password: 'your_amazon_password')
  3. # With credentials in .env
  4. client = AmazonAuth::Client.new
  5. # Sign in
  6. client.sign_in
  7. # Continue to the page for Kindle
  8. link = client.links_for('#navFooter a').find{|link| link =~ %r{/gp/digital/fiona/manage/} }
  9. client.session.visit link

Use amazon site in different domain

Set AMAZON_DOMAIN in .env.

e.g. AMAZON_DOMAIN=amazon.co.jp for Japanese site

Keep cookies

Using capybara-sessionkeeper gem

  1. client = AmazonAuth::Client.new(keep_cookie: true, debug: true)

You can change Capyabra.save_path when it isn’t set

  1. client = AmazonAuth::Client.new(keep_cookie: true, save_path: 'tmp/cookies', debug: true)

Logging

Normal logging

  1. client = AmazonAuth::Client.new(verbose: true)

More logging (This includes session.current_url)

  1. client = AmazonAuth::Client.new(debug: true)

Use Firefox

In console,

  1. client = AmazonAuth::Client.new(driver: :firefox)

Development

Use .env.development instead of .env in development.

  1. git clone https://github.com/kyamaguchi/amazon_auth.git
  2. cd amazon_auth
  3. bundle
  4. ./exe/amazon_auth
  5. vi .env.development
  6. rspec
  7. ./bin/console

Contributing

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

License

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