Created
August 20, 2013 22:40
-
-
Save benalavi/6288265 to your computer and use it in GitHub Desktop.
Test showing poltergeist fails to properly click an element in an iframe with padding
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 "minitest/autorun" | |
require "capybara/poltergeist" | |
# Capybara.register_driver :poltergeist do |app| | |
# Capybara::Poltergeist::Driver.new(nil, { debug: true }) | |
# end | |
Capybara.javascript_driver = :poltergeist | |
Capybara.default_driver = Capybara.javascript_driver | |
Capybara.app = lambda do |env| | |
req = Rack::Request.new(env) | |
if env["PATH_INFO"] == "/frame1" | |
# src for frame1 (which contains the link we're trying to click) | |
body = <<-HTML | |
<!DOCTYPE html> | |
<html> | |
<head></head> | |
<body style="background-color:#afa"> | |
<p>Frame 1 Content</p> | |
<a href="/frame2">Frame 2</a> | |
</body> | |
</html> | |
HTML | |
elsif env["PATH_INFO"] == "/frame2" | |
# src for frame2 (which shows we clicked the link) | |
body = <<-HTML | |
<!DOCTYPE html> | |
<html> | |
<head></head> | |
<body style="background-color:#aaf"> | |
<p>Frame 2 Content</p> | |
</body> | |
</html> | |
HTML | |
elsif env["PATH_INFO"] == "/frame_with_padding" | |
# src for container which uses an iframe w/ padding | |
body = <<-HTML | |
<!DOCTYPE html> | |
<html> | |
<head></head> | |
<body style="background-color:#fff"> | |
<p style="height:200px;">Outer Content</p> | |
<iframe name="main" src="/frame1" style="height:300px;padding-top:100px;"></iframe> | |
</body> | |
</html> | |
HTML | |
elsif env["PATH_INFO"] == "/frame_without_padding" | |
# src for container which uses an iframe w/o padding | |
body = <<-HTML | |
<!DOCTYPE html> | |
<html> | |
<head></head> | |
<body style="background-color:#fff"> | |
<p style="height:200px;">Outer Content</p> | |
<iframe name="main" src="/frame1" style="height:300px;"></iframe> | |
</body> | |
</html> | |
HTML | |
end | |
Rack::Response.new body, 200, {} | |
end | |
class PoltergeistTest < MiniTest::Test | |
include Capybara::DSL | |
def test_click_element_inside_iframe_with_padding | |
visit "/frame_with_padding" | |
within_frame "main" do | |
assert has_content?("Frame 1 Content") | |
assert has_no_content?("Frame 2 Content") | |
click_link "Frame 2" | |
assert has_no_content?("Frame 1 Content") | |
assert has_content?("Frame 2 Content") | |
end | |
end | |
def test_click_element_inside_iframe_without_padding | |
visit "/frame_without_padding" | |
within_frame "main" do | |
assert has_content?("Frame 1 Content") | |
assert has_no_content?("Frame 2 Content") | |
click_link "Frame 2" | |
assert has_no_content?("Frame 1 Content") | |
assert has_content?("Frame 2 Content") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment