All Projects → sandro → capybara-chrome

sandro / capybara-chrome

Licence: MIT license
Chrome driver for Capybara using Chrome's remote debugging protocol

Programming Languages

ruby
36898 projects - #4 most used programming language
javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to capybara-chrome

Gowitness
🔍 gowitness - a golang, web screenshot utility using Chrome Headless
Stars: ✭ 996 (+3588.89%)
Mutual labels:  headless, headless-chrome
Chrome Devtools Protocol
Chrome Devtools Protocol client for PHP
Stars: ✭ 112 (+314.81%)
Mutual labels:  headless, headless-chrome
Ferrum
Headless Chrome Ruby API
Stars: ✭ 1,009 (+3637.04%)
Mutual labels:  headless, headless-chrome
Cuprite
Headless Chrome/Chromium driver for Capybara
Stars: ✭ 743 (+2651.85%)
Mutual labels:  headless, headless-chrome
Taiko
A node.js library for testing modern web applications
Stars: ✭ 2,964 (+10877.78%)
Mutual labels:  headless, headless-chrome
Url To Pdf Api
Web page PDF/PNG rendering done right. Self-hosted service for rendering receipts, invoices, or any content.
Stars: ✭ 6,544 (+24137.04%)
Mutual labels:  headless, headless-chrome
Mocha Chrome
☕️ Run Mocha tests using headless Google Chrome
Stars: ✭ 66 (+144.44%)
Mutual labels:  headless, headless-chrome
rubium
Rubium is a lightweight alternative to Selenium/Capybara/Watir if you need to perform some operations (like web scraping) using Headless Chromium and Ruby
Stars: ✭ 65 (+140.74%)
Mutual labels:  headless, capybara
Pdf Bot
🤖 A Node queue API for generating PDFs using headless Chrome. Comes with a CLI, S3 storage and webhooks for notifying subscribers about generated PDFs
Stars: ✭ 2,551 (+9348.15%)
Mutual labels:  headless, headless-chrome
Chromeless
🖥 Chrome automation made simple. Runs locally or headless on AWS Lambda.
Stars: ✭ 13,254 (+48988.89%)
Mutual labels:  headless, headless-chrome
Html Pdf Chrome
HTML to PDF converter via Chrome/Chromium
Stars: ✭ 629 (+2229.63%)
Mutual labels:  headless, headless-chrome
mache
A library for writing cleaner and more expressive acceptance tests using page objects.
Stars: ✭ 40 (+48.15%)
Mutual labels:  rspec, capybara
Pychrome
A Python Package for the Google Chrome Dev Protocol [threading base]
Stars: ✭ 469 (+1637.04%)
Mutual labels:  headless, headless-chrome
Navalia
A bullet-proof, fast, and reliable headless browser API
Stars: ✭ 950 (+3418.52%)
Mutual labels:  headless, headless-chrome
Playwright Go
Playwright for Go a browser automation library to control Chromium, Firefox and WebKit with a single API.
Stars: ✭ 272 (+907.41%)
Mutual labels:  headless, headless-chrome
Crawlergo
A powerful dynamic crawler for web vulnerability scanners
Stars: ✭ 1,088 (+3929.63%)
Mutual labels:  headless, headless-chrome
headless-chrome-alpine
A Docker container running headless Chrome
Stars: ✭ 26 (-3.7%)
Mutual labels:  headless, headless-chrome
node-headless-chrome
⚠️ 🚧 Install precompiled versions of the Chromium/Chrome headless shell using npm or yarn
Stars: ✭ 20 (-25.93%)
Mutual labels:  headless, headless-chrome
Phpchrometopdf
A slim PHP wrapper around google-chrome to convert url to pdf or to take screenshots , easy to use and clean OOP interface
Stars: ✭ 127 (+370.37%)
Mutual labels:  headless, headless-chrome
capybara-chromedriver-logger
Enables console.log/error/info output from Javascript feature specs running with Chromedriver
Stars: ✭ 54 (+100%)
Mutual labels:  rspec, capybara

Capybara::Chrome

Use Capybara to drive Chrome in headless mode via the debugging protocol.

Installation

Add this line to your application's Gemfile:

gem 'capybara-chrome'

And then execute:

$ bundle

Or install it yourself as:

$ gem install capybara-chrome

Using Docker

Add this line to your Dockerfile to install Chrome:

  RUN curl -sL -o chrome-stable.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb ; dpkg -i chrome-stable.deb ; apt-get install -fy; rm -rf /var/lib/apt/lists/*

In my experience, headless Chrome cannot be run as root, so you need to run rspec as an unprivileged user and use this flag with docker run

docker run --security-opt seccomp=unconfined

Usage

Capybara.javascript_driver = :chrome
Capybara::Chrome.configuration.chrome_port = 9222 # optional

The standard port for the debugging protocol is 9222. Visit localhost:9222 in a Chrome tab to watch the tests execute. Note, the port will be random by default.

Using thin

I like using thin instead of WEBrick as my Capybara server. It's a little faster, gives me greater control of logging, shows errors, and allows me to disable signal handlers. Below are my settings:

Capybara.register_server :thin do |app, port, host|
  require "rack/handler/thin"
  Thin::Logging.silent = false
  # Thin::Logging.debug = true # uncomment to see request and response codes
  # Thin::Logging.trace = true # uncomment to see full requests/responses
  Rack::Handler::Thin.run(app, Host: host, Port: port, signals: false)
end
Capybara.server = :thin

Debugging

Use byebug instead of binding.pry when debugging a test. The Pry debugger tends to hang when visit is called.

Using the repl

You can use the capybara-chrome browser without providing a rack app. This can be helpful in debugging.

[2] pry(main)> driver = Capybara::Chrome::Driver.new(nil, port:9222); driver.start; browser = driver.browser
[3] pry(main)> browser.visit "http://google.com"
=> true
[4] pry(main)> browser.current_url
=> "https://www.google.com/?gws_rd=ssl"
[5] pry(main)>

Further, you can run a local netcat server and point the capybara-chrome browser to it to see the entire request that's being sent.

Terminal one contains the browser:

[1] pry(main)> driver = Capybara::Chrome::Driver.new(nil, port:9222); driver.start; browser = driver.browser
[2] pry(main)> browser.header "x-foo", "bar"
[3] pry(main)> browser.visit "http://localhost:8000"

Terminal two prints the request

$ while true; do { echo -e "HTTP/1.1 200 OK \r\n"; echo "hi"; } | nc -l 8000; done
GET / HTTP/1.1
Host: localhost:8000
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/68.0.3440.106 Safari/537.36
x-foo: bar
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding: gzip, deflate

Videos

A video showing capybara-chrome running in a browser tab

Preview of visualizing capybara-chrome

A video demonstrating debugging an rspec test with byebug

Preview of debugging capybara-chrome

A video showing capybara-chrome running against a netcat backend

Preview of debugging capybara-chrome with netcat

Contributing

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

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].