### Install Cuprite Gem Source: https://github.com/rubycdp/cuprite/blob/main/README.md Add the Cuprite gem to your Gemfile for testing purposes and run bundle install. ```ruby group :test do gem "cuprite" end ``` -------------------------------- ### Configure Cuprite Driver with No Sandbox Option Source: https://github.com/rubycdp/cuprite/blob/main/README.md When using Docker, pass the 'no-sandbox' option to the Cuprite driver. ```ruby Capybara::Cuprite::Driver.new(app, browser_options: { 'no-sandbox': nil }) ``` -------------------------------- ### Proxy Configuration Source: https://github.com/rubycdp/cuprite/blob/main/README.md Configures the proxy settings for the browser. ```APIDOC ## Proxy ### `page.driver.set_proxy(ip, port, user, password)` #### Description Sets the proxy server to be used by the browser. Requires IP address, port, and optional user credentials. ``` -------------------------------- ### Configure Capybara with Cuprite Driver Source: https://github.com/rubycdp/cuprite/blob/main/README.md Set Cuprite as the default JavaScript driver and register it with Capybara, specifying window size. ```ruby require "capybara/cuprite" Capybara.javascript_driver = :cuprite Capybara.register_driver(:cuprite) do |app| Capybara::Cuprite::Driver.new(app, window_size: [1200, 800]) end ``` -------------------------------- ### Authorization Source: https://github.com/rubycdp/cuprite/blob/main/README.md Handles basic HTTP authentication. ```APIDOC ## Authorization ### `page.driver.basic_authorize(user, password)` #### Description Performs basic HTTP authentication using the provided username and password. ``` -------------------------------- ### URL Blocklisting & Allowlisting Source: https://github.com/rubycdp/cuprite/blob/main/README.md Configures URL blocklisting and allowlisting to control script execution on specific domains. ```APIDOC ## URL Blocklisting & Allowlisting ### `page.driver.browser.url_blocklist = %r{pattern}` #### Description Prevents scripts from running on domains matching the provided regular expression pattern. ### `page.driver.browser.url_allowlist = %r{pattern}` #### Description Allows scripts to run only on domains matching the provided regular expression pattern. *Note: `url_blacklist=` and `url_whitelist=` are supported for legacy compatibility.* ``` -------------------------------- ### Set URL Allowlist in Cuprite Source: https://github.com/rubycdp/cuprite/blob/main/README.md Use URL allowlisting to restrict script execution to only designated domains. This ensures scripts only run on essential domains. ```ruby page.driver.browser.url_allowlist = %r{http://www.example.com} ``` -------------------------------- ### Screenshot Source: https://github.com/rubycdp/cuprite/blob/main/README.md Captures a screenshot of the page as a Base64 encoded string. ```APIDOC ## Screenshot ### `page.driver.render_base64(format, options)` #### Description Returns the screenshot of the current page as a Base64 encoded string. Accepts a format and optional options. ``` -------------------------------- ### Set URL Blocklist in Cuprite Source: https://github.com/rubycdp/cuprite/blob/main/README.md Use URL blocklisting to prevent scripts from running on specified domains. This is useful for improving test performance by excluding ad networks or analytics. ```ruby page.driver.browser.url_blocklist = %r{http://www.example.com} ``` -------------------------------- ### Register Cuprite Driver with Custom Options Source: https://github.com/rubycdp/cuprite/blob/main/README.md Register the Cuprite driver with Capybara, passing custom options for configuration. ```ruby Capybara.register_driver(:cuprite) do |app| Capybara::Cuprite::Driver.new(app, options) end ``` -------------------------------- ### Wait for Page Reload Source: https://github.com/rubycdp/cuprite/blob/main/README.md Use `page.driver.wait_for_reload` to specifically wait for a page reload to complete, which is more reliable than waiting for network idle in certain scenarios. ```ruby page.driver.wait_for_reload ``` -------------------------------- ### Wait for Network Idle and Refresh Page Source: https://github.com/rubycdp/cuprite/blob/main/README.md Use `page.driver.wait_for_network_idle` to wait for network activity to cease before proceeding. `page.driver.refresh` reloads the current page. ```ruby page.driver.wait_for_network_idle page.driver.refresh ``` -------------------------------- ### Inspect Network Traffic with Cuprite Source: https://github.com/rubycdp/cuprite/blob/main/README.md Retrieve and inspect network traffic data, including request and response details, using `page.driver.network_traffic`. ```ruby # Retrieve all network exchanges network_traffic = page.driver.network_traffic # Access the first exchange first_exchange = network_traffic.first # Inspect the response of the first request response = first_exchange.response ``` -------------------------------- ### Debug Test Execution with Cuprite Source: https://github.com/rubycdp/cuprite/blob/main/README.md Pause test execution using `page.driver.debug` to inspect the browser state and use `binding` for interactive debugging with pry or irb. ```ruby it "does something useful" do visit root_path fill_in "field", with: "value" page.driver.debug(binding) expect(page).to have_content("value") end ``` -------------------------------- ### Set Request Headers with Cuprite Source: https://github.com/rubycdp/cuprite/blob/main/README.md Manipulate HTTP request headers. Use `headers=` to overwrite all headers or `add_headers` to append new ones. Headers are cleared at the end of the test. ```ruby page.driver.headers # => {} page.driver.headers = { "User-Agent" => "Cuprite" } page.driver.add_headers("Referer" => "https://example.com") page.driver.headers # => { "User-Agent" => "Cuprite", "Referer" => "https://example.com" } ``` -------------------------------- ### Access Ferrum Browser API Source: https://github.com/rubycdp/cuprite/blob/main/README.md Access the underlying Ferrum browser object from the Capybara driver to use advanced features like mouse interactions. ```ruby browser = page.driver.browser browser.mouse.move(x: 123, y: 456).down.up ``` -------------------------------- ### Cookie Manipulation Source: https://github.com/rubycdp/cuprite/blob/main/README.md Methods for inspecting and manipulating cookies on the current page. ```APIDOC ## Cookie Manipulation ### `page.driver.cookies` #### Description Returns a hash of cookies accessible to the current page. The keys are cookie names and the values are `Cookie` objects. ### `page.driver.set_cookie(name, value, options = {})` #### Description Sets a cookie with the given name and value. Options can include `:domain`, `:path`, `:secure`, `:httponly`, and `:expires` (a `Time` object). ### `page.driver.remove_cookie(name)` #### Description Removes the cookie with the specified name. ### `page.driver.clear_cookies` #### Description Clears all cookies for the current page. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.