{"id":13804632,"url":"https://github.com/rubycdp/cuprite","last_synced_at":"2025-05-12T20:49:16.131Z","repository":{"id":39602174,"uuid":"141314250","full_name":"rubycdp/cuprite","owner":"rubycdp","description":"Headless Chrome/Chromium driver for Capybara","archived":false,"fork":false,"pushed_at":"2025-03-06T06:09:09.000Z","size":795,"stargazers_count":1297,"open_issues_count":67,"forks_count":98,"subscribers_count":21,"default_branch":"main","last_synced_at":"2025-05-08T18:32:29.112Z","etag":null,"topics":["capybara","chrome","chromium","driver","headless","headless-chrome","integration-testing","testing","testing-tools"],"latest_commit_sha":null,"homepage":"https://cuprite.rubycdp.com","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rubycdp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"rubycdp"}},"created_at":"2018-07-17T16:13:43.000Z","updated_at":"2025-05-06T19:24:41.000Z","dependencies_parsed_at":"2023-09-22T13:52:26.731Z","dependency_job_id":"79ab0dee-019f-46b6-a7fc-45637641e8a3","html_url":"https://github.com/rubycdp/cuprite","commit_stats":{"total_commits":404,"total_committers":36,"mean_commits":"11.222222222222221","dds":0.1534653465346535,"last_synced_commit":"0b8da9c31df1145c60eaae7b89b3a58ed4d8c0df"},"previous_names":["machinio/cuprite"],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubycdp%2Fcuprite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubycdp%2Fcuprite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubycdp%2Fcuprite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rubycdp%2Fcuprite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rubycdp","download_url":"https://codeload.github.com/rubycdp/cuprite/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253820241,"owners_count":21969490,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["capybara","chrome","chromium","driver","headless","headless-chrome","integration-testing","testing","testing-tools"],"created_at":"2024-08-04T01:00:51.557Z","updated_at":"2025-05-12T20:49:16.113Z","avatar_url":"https://github.com/rubycdp.png","language":"Ruby","readme":"# Cuprite - Headless Chrome driver for Capybara\n\nCuprite is a pure Ruby driver (read as _no_ Selenium/WebDriver/ChromeDriver\ndependency) for [Capybara](https://github.com/teamcapybara/capybara). It allows\nyou to run Capybara tests on a headless Chrome or Chromium. Under the hood it\nuses [Ferrum](https://github.com/rubycdp/ferrum#index) which is high-level API\nto the browser by CDP protocol.\n\n\n## Install\n\nAdd this to your `Gemfile` and run `bundle install`.\n\n``` ruby\ngroup :test do\n  gem \"cuprite\"\nend\n```\n\nIn your test setup add:\n\n``` ruby\nrequire \"capybara/cuprite\"\nCapybara.javascript_driver = :cuprite\nCapybara.register_driver(:cuprite) do |app|\n  Capybara::Cuprite::Driver.new(app, window_size: [1200, 800])\nend\n```\n\nif you use `Docker` don't forget to pass `no-sandbox` option:\n\n```ruby\nCapybara::Cuprite::Driver.new(app, browser_options: { 'no-sandbox': nil })\n```\n\nSince Cuprite uses [Ferrum](https://github.com/rubycdp/ferrum#examples) there\nare many useful methods you can call even using this driver:\n\n```ruby\nbrowser = page.driver.browser\nbrowser.mouse.move(x: 123, y: 456).down.up\n```\n\nFor Selenium you better check your code for `manage` calls because it works\ndifferently in Cuprite, see the documentation below.\n\n\n## Customization\n\nSee the full list of options for\n[Ferrum](https://github.com/rubycdp/ferrum#customization).\n\nYou can pass options with the following code in your test setup:\n\n``` ruby\nCapybara.register_driver(:cuprite) do |app|\n  Capybara::Cuprite::Driver.new(app, options)\nend\n```\n\n`Cuprite`-specific options are:\n\n* options `Hash`\n  * `:url_blacklist` (Array) - array of regexes to match against requested URLs\n  * `:url_whitelist` (Array) - array of regexes to match against requested URLs\n\n\n## Debugging\n\nYou can put `page.driver.debug` or `page.driver.debug(binding)` in your test to pause it.\nThis will launch the browser where you can inspect the content.\n\n```ruby\nit \"does something useful\" do\n  visit root_path\n\n  fill_in \"field\", with: \"value\"\n  page.driver.debug(binding)\n\n  expect(page).to have_content(\"value\")\nend\n```\n\nIn the middle of the execution Chrome will open a new tab where you can inspect\nthe content and also if you passed `binding` an `irb` or `pry` console will be\nopened where you can further experiment with the test.\n\n\n## Clicking/Scrolling\n\n* `page.driver.click(x, y)` Click a very specific area of the screen.\n* `page.driver.scroll_to(left, top)` Scroll to a given position.\n* `element.send_keys(*keys)` Send keys to a given node.\n\n\n## Request headers\n\nManipulate HTTP request headers like a boss:\n\n``` ruby\npage.driver.headers # =\u003e {}\npage.driver.headers = { \"User-Agent\" =\u003e \"Cuprite\" }\npage.driver.add_headers(\"Referer\" =\u003e \"https://example.com\")\npage.driver.headers # =\u003e { \"User-Agent\" =\u003e \"Cuprite\", \"Referer\" =\u003e \"https://example.com\" }\n```\n\nNotice that `headers=` will overwrite already set headers. You should use\n`add_headers` if you want to add a few more. These headers will apply to all\nsubsequent HTTP requests (including requests for assets, AJAX, etc). They will\nbe automatically cleared at the end of the test.\n\n\n## Network traffic\n\n* `page.driver.network_traffic` allows you to inspect network traffic (i.e., loaded resources) on the current page. It returns an array of `Ferrum::Network::Exchange` objects, each representing a network request/response exchange. You can query both the request and response details of each exchange.\n\n```ruby\n# Retrieve all network exchanges\nnetwork_traffic = page.driver.network_traffic\n\n# Access the first exchange\nfirst_exchange = network_traffic.first\n\n# Inspect the response of the first request\nresponse = first_exchange.response\n```\n\n* `page.driver.wait_for_network_idle` Natively waits for network idle and if\nthere are no active connections returns or raises `TimeoutError` error. Accepts\nthe same options as\n[`wait_for_idle`](https://github.com/rubycdp/ferrum#wait_for_idleoptions)\n\n```ruby\npage.driver.wait_for_network_idle\npage.driver.refresh\n```\n\nPlease note that network traffic is not cleared when you visit new page. You can\nmanually clear the network traffic by calling `page.driver.clear_network_traffic`\nor `page.driver.reset`\n\n* `page.driver.wait_for_reload` unlike `wait_for_network_idle` will wait until\nthe whole page is reloaded or raise a timeout error. It's useful when you know\nthat for example after clicking autocomplete suggestion you expect page to be\nreloaded, you have a few choices - put sleep or wait for network idle, but both\nare bad. Sleep makes you wait longer or less than needed, network idle can\nreturn earlier even before the whole page is started to reload. Here's the\nrescue.\n\n\n## Manipulating cookies\n\nThe following methods are used to inspect and manipulate cookies:\n\n* `page.driver.cookies` - a hash of cookies accessible to the current\n  page. The keys are cookie names. The values are `Cookie` objects, with\n  the following methods: `name`, `value`, `domain`, `path`, `size`, `secure?`,\n  `httponly?`, `session?`, `expires`.\n* `page.driver.set_cookie(name, value, options = {})` - set a cookie.\n  The options hash can take the following keys: `:domain`, `:path`,\n  `:secure`, `:httponly`, `:expires`. `:expires` should be a\n  `Time` object.\n* `page.driver.remove_cookie(name)` - remove a cookie\n* `page.driver.clear_cookies` - clear all cookies\n\n\n## Screenshot\n\nBesides capybara screenshot method you can get image as Base64:\n\n* `page.driver.render_base64(format, options)`\n\n\n## Authorization\n\n* `page.driver.basic_authorize(user, password)`\n\n## Proxy\n\n* `page.driver.set_proxy(ip, port, user, password)`\n\n\n## URL Blocklisting \u0026 Allowlisting\n\nCuprite supports URL blocklisting, which allows you to prevent scripts from\nrunning on designated domains:\n\n```ruby\npage.driver.browser.url_blocklist = %r{http://www.example.com}\n```\n\nand also URL allowlisting, which allows scripts to only run on designated\ndomains:\n\n```ruby\npage.driver.browser.url_allowlist = %r{http://www.example.com}\n```\n\nFor legacy support, `url_blacklist=` and `url_whitelist=` continue to work respectively.\n\nIf you are experiencing slower run times, consider creating a URL allowlist of\ndomains that are essential or a blocklist of domains that are not essential,\nsuch as ad networks or analytics, to your testing environment.\n\n## License\n\nThe gem is available as open source under the terms of the\n[MIT License](https://opensource.org/licenses/MIT).\n","funding_links":["https://github.com/sponsors/rubycdp"],"categories":["Chrome DevTools Protocol","Ruby"],"sub_categories":["Libraries for driving the protocol (or a layer above)"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubycdp%2Fcuprite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frubycdp%2Fcuprite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubycdp%2Fcuprite/lists"}