Skip to content

Instantly share code, notes, and snippets.

@jnicklas
Created May 9, 2016 14:19
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 jnicklas/a2ada84190f2cc9fdb95acec6a235dde to your computer and use it in GitHub Desktop.
Save jnicklas/a2ada84190f2cc9fdb95acec6a235dde to your computer and use it in GitHub Desktop.
require "capybara"
html = DATA.read
app = proc { |env| [200, { "Content-Type" => "text/html" }, [html] ] }
sess = Capybara::Session.new(:selenium, app)
sess.visit("/")
sess.click_link("Click me")
sess.reset!
__END__
<!doctype html>
<html>
<body>
<a href="/foo">Click me</a>
<script>
window.addEventListener("beforeunload", function(event) {
if(!confirm("are you sure?")) {
event.preventDefault();
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment