Skip to content

Instantly share code, notes, and snippets.

@jdelStrother
Created July 11, 2011 12:45
Show Gist options
  • Save jdelStrother/1075763 to your computer and use it in GitHub Desktop.
Save jdelStrother/1075763 to your computer and use it in GitHub Desktop.
require 'capybara'
require 'rack'
class IframeServer
def call(env)
r = Rack::Request.new(env)
content = case r.path
when '/container.html'
pages[0]
when '/iframe1.html'
pages[1]
when '/iframe2.html'
pages[2]
when '/final.html'
pages[3]
end
[200, {'Content-Type'=>'text/html'}, [content]]
end
def pages
@pages ||= DATA.read.split("===")
end
end
app = IframeServer.new
session = Capybara::Session.new(:selenium, app)
session.visit('/container.html')
session.within_frame('ThreeD') do
session.find('input', :value=>"Continue").click
end
raise "unexpected final content" unless session.has_content?('all done')
puts 'yay, it worked'
__END__
<html>
<head>
<style> iframe { border:2px solid red; } </style>
</head>
<body>
<h1> iframe :</h1>
<iframe id='ThreeD' src='/iframe1.html'>iframe content goes here </iframe>
</body>
</html>
===
<html>
<body>
<form action="/iframe2.html">
<input type="submit" value="Continue"/>
</form>
</body>
</html>
===
<html>
<body>
<script>
window.parent.location = '/final.html'
</script>
</body>
</html>
===
<html>
<body>
Yay, all done!!
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment