Created
July 12, 2019 15:40
-
-
Save twalpole/2f69984a5c6063aab04ea25c0aa3d2ca to your computer and use it in GitHub Desktop.
Test FF UA profile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'selenium-webdriver', '3.142.3' | |
gem 'webdrivers' | |
gem 'capybara', '3.18.0' | |
gem 'byebug' | |
gem 'puma' | |
end | |
require 'webdrivers' | |
require "capybara/dsl" | |
html = DATA.read | |
app = proc { |env| [200, { "Content-Type" => "text/html" }, [html] ] } | |
Capybara.register_driver :ff do |app| | |
profile = Selenium::WebDriver::Firefox::Profile.new | |
profile['general.useragent.override'] = 'Random User Agent' | |
opts = Selenium::WebDriver::Firefox::Options.new(profile: profile) | |
Capybara::Selenium::Driver.new(app, browser: :firefox, options: opts) | |
end | |
sess = Capybara::Session.new(:ff, app) | |
sess.visit('/') | |
sess.find('#user_agent').assert_text('Random User Agent', exact: true) | |
__END__ | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>UA</title> | |
</head> | |
<body> | |
<p id="user_agent"></p> | |
<script> | |
document.getElementById('user_agent').innerHTML = navigator.userAgent; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment