2011-02-19 03:53:06 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'capybara/driver/webkit'
|
|
|
|
|
|
|
|
describe Capybara::Driver::Webkit do
|
|
|
|
let(:hello_app) do
|
|
|
|
lambda do |env|
|
|
|
|
body = <<-HTML
|
|
|
|
<html><body>
|
|
|
|
<script type="text/javascript">
|
2011-02-25 05:15:08 +00:00
|
|
|
document.write("<p id='greeting'>he" + "llo</p>");
|
2011-02-19 03:53:06 +00:00
|
|
|
</script>
|
|
|
|
</body></html>
|
|
|
|
HTML
|
|
|
|
[200,
|
|
|
|
{ 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
|
|
|
|
[body]]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-02-26 04:47:55 +00:00
|
|
|
before(:all) { @@browser = Capybara::Driver::Webkit::Browser.new }
|
|
|
|
subject { Capybara::Driver::Webkit.new(hello_app, :browser => @@browser) }
|
2011-02-25 22:53:36 +00:00
|
|
|
before { subject.visit("/hello/world?success=true") }
|
2011-02-19 03:53:06 +00:00
|
|
|
after { subject.reset! }
|
|
|
|
|
|
|
|
it "finds content after loading a URL" do
|
|
|
|
subject.find("//*[contains(., 'hello')]").should_not be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has an empty page after reseting" do
|
|
|
|
subject.reset!
|
|
|
|
subject.find("//*[contains(., 'hello')]").should be_empty
|
|
|
|
end
|
2011-02-25 04:22:56 +00:00
|
|
|
|
|
|
|
it "raises an error for an invalid xpath query" do
|
|
|
|
expect { subject.find("totally invalid salad") }.
|
|
|
|
to raise_error(Capybara::Driver::Webkit::WebkitError, /xpath/i)
|
|
|
|
end
|
2011-02-25 05:15:08 +00:00
|
|
|
|
|
|
|
it "returns an attribute's value" do
|
|
|
|
subject.find("//p").first["id"].should == "greeting"
|
|
|
|
end
|
2011-02-26 03:57:55 +00:00
|
|
|
|
|
|
|
it "parses xpath with quotes" do
|
|
|
|
subject.find('//*[contains(., "hello")]').should_not be_empty
|
|
|
|
end
|
2011-02-26 04:39:29 +00:00
|
|
|
|
|
|
|
it "returns a node's text" do
|
|
|
|
subject.find("//p").first.text.should == "hello"
|
|
|
|
end
|
2011-02-26 15:06:11 +00:00
|
|
|
|
2011-02-25 22:53:36 +00:00
|
|
|
it "returns the current URL" do
|
|
|
|
port = subject.instance_variable_get("@rack_server").port
|
|
|
|
subject.current_url.should == "http://127.0.0.1:#{port}/hello/world?success=true"
|
|
|
|
end
|
2011-02-25 23:04:23 +00:00
|
|
|
|
|
|
|
it "returns the source code for the page" do
|
|
|
|
subject.source.should == %{<html><head></head><body>
|
|
|
|
<script type="text/javascript">
|
|
|
|
document.write("<p id='greeting'>he" + "llo</p>");
|
|
|
|
</script><p id="greeting">hello</p>
|
|
|
|
|
|
|
|
</body></html>}
|
|
|
|
end
|
2011-02-19 03:53:06 +00:00
|
|
|
end
|
|
|
|
|