Created
June 3, 2020 00:32
-
-
Save twalpole/6a3b090ee1f71161fc0188f472898b02 to your computer and use it in GitHub Desktop.
Test for different types of multiline text input
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 'capybara' | |
gem 'puma' | |
gem 'selenium-webdriver' | |
gem 'webdrivers' | |
gem 'byebug' | |
end | |
require 'selenium-webdriver' | |
require "capybara/dsl" | |
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('/') | |
input = sess.find('input') | |
text_area = sess.find('textarea') | |
c_e = sess.find('div[contenteditable]') | |
input.set("this is multi\nline text") | |
text_area.set("this is multi\nline text") | |
c_e.set("this is multi\nline text") | |
sess.assert_selector(:field, with: 'this is multiline text') | |
sess.assert_selector(:field, with: "this is multi\nline text") | |
sess.assert_text(c_e, "this is multi\nline text") | |
end | |
__END__ | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>Hello!</title> | |
<meta charset="utf-8"> | |
</head> | |
<body> | |
<input type="text"/> | |
<textarea></textarea> | |
<div contenteditable="true" style="height: 100px"></div> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment