Skip to content

Instantly share code, notes, and snippets.

@twalpole
Created May 28, 2021 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twalpole/df24f13b5416971142d7b2ffd32891cc to your computer and use it in GitHub Desktop.
Save twalpole/df24f13b5416971142d7b2ffd32891cc to your computer and use it in GitHub Desktop.
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'capybara'
# gem 'capybara', path: "/Users/twalpole/projects/Capybara"
gem 'puma'
gem 'selenium-webdriver'
gem 'webdrivers'
gem 'byebug'
gem 'rexml'
end
require 'selenium-webdriver'
require "capybara/dsl"
Capybara.default_max_wait_time = 5
html = DATA.read
app = proc { |env| [200, { "Content-Type" => "text/html" }, [html] ] }
%i[selenium_chrome selenium_chrome_headless].each do |driver|
puts "Using #{driver}"
sess = Capybara::Session.new(driver, app)
sess.visit('/')
sess.assert_selector(:field, 'sometextareaid', with: /\s*initial value\s/)
sess.fill_in('sometextareaid', with: 'other value', fill_options: { clear: :backspace })
sess.assert_selector(:field, 'sometextareaid', with: 'other value')
end
__END__
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hello!</title>
</head>
<body>
<textarea id="sometextareaid">
initial value
</textarea>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment