Created
July 29, 2019 20:39
-
-
Save twalpole/bb472b4032e3a0bd1d80786d60c77d7a to your computer and use it in GitHub Desktop.
Test using_driver
This file contains 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.27.0' | |
gem 'byebug' | |
gem 'puma' | |
end | |
require 'webdrivers' | |
require "capybara/dsl" | |
require 'byebug' | |
html = DATA.read | |
app = proc { |env| [200, { "Content-Type" => "text/html" }, [html] ] } | |
Capybara.register_driver :phonegap do |app| | |
browser_options = ::Selenium::WebDriver::Chrome::Options.new | |
# browser_options.args << '--headless' | |
# browser_options.args << '--disable-gpu' | |
# browser_options.args << "--window-size=#{SCREEN_WIDTH},#{SCREEN_HEIGHT}" | |
# browser_options.args << "--user-agent-=#{USER_AGENT}" | |
Capybara::Selenium::Driver.new app, | |
browser: :chrome, | |
# clear_local_storage: true, | |
# clear_session_storage: true, | |
options: browser_options | |
end | |
Capybara.app = app | |
Capybara.current_driver = :selenium_chrome | |
# Go to page for the first time | |
Capybara.page.visit("/") | |
Capybara.page.assert_selector(:css, '#local', exact_text: 'empty') | |
Capybara.using_driver(:phonegap) do | |
Capybara.page.visit("/") | |
Capybara.page.assert_selector(:css, '#local', exact_text: 'empty') | |
end | |
# Go again - local storage should be set this time | |
Capybara.page.visit("/") | |
Capybara.page.assert_selector(:css, '#local', exact_text: 'abcdefg') | |
Capybara.using_driver(:phonegap) do | |
Capybara.page.visit("/") | |
Capybara.page.assert_selector(:css, '#local', exact_text: 'abcdefg') | |
end | |
# Reset all Capybara managed sessions | |
Capybara.reset_sessions! | |
# Local storage should have been cleared | |
Capybara.page.visit("/") | |
Capybara.page.assert_selector(:css, '#local', exact_text: 'empty') | |
Capybara.using_driver(:phonegap) do | |
Capybara.page.visit("/") | |
Capybara.page.assert_selector(:css, '#local', exact_text: 'empty') | |
end | |
__END__ | |
<!doctype html> | |
<html> | |
<head> | |
<title>Some title</title> | |
<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script> | |
</head> | |
<body> | |
<script> | |
$('body').append('<div id="local">' + (window.localStorage.getItem('test') || 'empty') + '</div>'); | |
window.localStorage.setItem('test', 'abcdefg'); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment