Created
February 16, 2018 17:52
-
-
Save twalpole/ae7b39c7ad75687d49aba0e6f06248b0 to your computer and use it in GitHub Desktop.
test assert_text/assert_no_text
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 'capybara/dsl' | |
require 'selenium-webdriver' | |
require 'capybara' | |
require 'byebug' | |
html = DATA.read | |
app = proc { |env| [200, { "Content-Type" => "text/html" }, [html] ] } | |
session1 = Capybara::Session.new(:selenium, app) | |
session2 = Capybara::Session.new(:rack_test, app) | |
[session1, session2].each do |session| | |
session.visit('/') | |
div1 = session.find('#div1') | |
div2 = session.find('#div2') | |
div1.assert_text('Some text') | |
div2.assert_text('Other text') | |
div1.assert_no_text('Other text') | |
div2.assert_no_text('Some text') | |
session.within(div1) do | |
session.assert_text('Some text') | |
session.assert_no_text('Other text') | |
end | |
end | |
__END__ | |
<!doctype html> | |
<html> | |
<head> | |
</head> | |
<body> | |
<div id="div1"> | |
Some text | |
</div> | |
<div id="div2"> | |
Other text | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment