2011-02-18 22:53:06 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'capybara/driver/webkit'
|
|
|
|
|
|
|
|
describe Capybara::Driver::Webkit do
|
2011-03-11 11:19:59 -05:00
|
|
|
subject { Capybara::Driver::Webkit.new(@app, :browser => $webkit_browser) }
|
2011-02-25 17:53:36 -05:00
|
|
|
before { subject.visit("/hello/world?success=true") }
|
2011-02-18 22:53:06 -05:00
|
|
|
after { subject.reset! }
|
|
|
|
|
2011-04-19 03:16:25 -04:00
|
|
|
context "iframe app" do
|
|
|
|
before(:all) do
|
|
|
|
@app = lambda do |env|
|
|
|
|
params = ::Rack::Utils.parse_query(env['QUERY_STRING'])
|
2011-04-20 01:42:20 -04:00
|
|
|
if params["iframe"] == "true"
|
|
|
|
# We are in an iframe request.
|
2011-04-19 03:16:25 -04:00
|
|
|
p_id = "farewell"
|
|
|
|
msg = "goodbye"
|
2011-04-20 01:42:20 -04:00
|
|
|
iframe = nil
|
2011-04-19 03:16:25 -04:00
|
|
|
else
|
2011-04-20 01:42:20 -04:00
|
|
|
# We are not in an iframe request and need to make an iframe!
|
2011-04-19 03:16:25 -04:00
|
|
|
p_id = "greeting"
|
|
|
|
msg = "hello"
|
2011-04-20 01:42:20 -04:00
|
|
|
iframe = "<iframe id=\"f\" src=\"/?iframe=true\"></iframe>"
|
2011-07-12 15:31:10 -04:00
|
|
|
end
|
2011-04-19 03:16:25 -04:00
|
|
|
body = <<-HTML
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<style type="text/css">
|
|
|
|
#display_none { display: none }
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
2011-04-20 01:42:20 -04:00
|
|
|
#{iframe}
|
2011-04-19 03:16:25 -04:00
|
|
|
<script type="text/javascript">
|
|
|
|
document.write("<p id='#{p_id}'>#{msg}</p>");
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
HTML
|
|
|
|
[200,
|
|
|
|
{ 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
|
|
|
|
[body]]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-04-20 01:42:20 -04:00
|
|
|
it "finds frames by index" do
|
|
|
|
subject.within_frame(0) do
|
|
|
|
subject.find("//*[contains(., 'goodbye')]").should_not be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "finds frames by id" do
|
2011-04-19 03:16:25 -04:00
|
|
|
subject.within_frame("f") do
|
|
|
|
subject.find("//*[contains(., 'goodbye')]").should_not be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-04-20 01:42:20 -04:00
|
|
|
it "raises error for missing frame by index" do
|
|
|
|
expect { subject.within_frame(1) { } }.
|
2011-07-12 15:31:10 -04:00
|
|
|
to raise_error(Capybara::Driver::Webkit::WebkitInvalidResponseError)
|
2011-04-20 01:42:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "raise_error for missing frame by id" do
|
|
|
|
expect { subject.within_frame("foo") { } }.
|
2011-07-12 15:31:10 -04:00
|
|
|
to raise_error(Capybara::Driver::Webkit::WebkitInvalidResponseError)
|
2011-04-20 01:42:20 -04:00
|
|
|
end
|
|
|
|
|
2011-04-19 03:16:25 -04:00
|
|
|
it "returns an attribute's value" do
|
|
|
|
subject.within_frame("f") do
|
|
|
|
subject.find("//p").first["id"].should == "farewell"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a node's text" do
|
|
|
|
subject.within_frame("f") do
|
|
|
|
subject.find("//p").first.text.should == "goodbye"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the current URL" do
|
|
|
|
subject.within_frame("f") do
|
|
|
|
port = subject.instance_variable_get("@rack_server").port
|
2011-04-20 01:42:20 -04:00
|
|
|
subject.current_url.should == "http://127.0.0.1:#{port}/?iframe=true"
|
2011-04-19 03:16:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the source code for the page" do
|
|
|
|
subject.within_frame("f") do
|
|
|
|
subject.source.should =~ %r{<html>.*farewell.*}m
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "evaluates Javascript" do
|
|
|
|
subject.within_frame("f") do
|
|
|
|
result = subject.evaluate_script(%<document.getElementById('farewell').innerText>)
|
2011-04-20 01:42:20 -04:00
|
|
|
result.should == "goodbye"
|
2011-04-19 03:16:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "executes Javascript" do
|
|
|
|
subject.within_frame("f") do
|
|
|
|
subject.execute_script(%<document.getElementById('farewell').innerHTML = 'yo'>)
|
|
|
|
subject.find("//p[contains(., 'yo')]").should_not be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-09-09 15:52:34 -04:00
|
|
|
context "redirect app" do
|
|
|
|
before(:all) do
|
|
|
|
@app = lambda do |env|
|
|
|
|
if env['PATH_INFO'] == '/target'
|
|
|
|
content_type = "<p>#{env['CONTENT_TYPE']}</p>"
|
|
|
|
[200, {"Content-Type" => "text/html", "Content-Length" => content_type.length.to_s}, [content_type]]
|
|
|
|
elsif env['PATH_INFO'] == '/form'
|
|
|
|
body = <<-HTML
|
|
|
|
<html>
|
|
|
|
<body>
|
|
|
|
<form action="/redirect" method="POST" enctype="multipart/form-data">
|
|
|
|
<input name="submit" type="submit" />
|
|
|
|
</form>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
HTML
|
|
|
|
[200, {"Content-Type" => "text/html", "Content-Length" => body.length.to_s}, [body]]
|
|
|
|
else
|
|
|
|
[301, {"Location" => "/target"}, [""]]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should redirect without content type" do
|
|
|
|
subject.visit("/form")
|
|
|
|
subject.find("//input").first.click
|
|
|
|
subject.find("//p").first.text.should == ""
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-09-15 11:22:10 -04:00
|
|
|
context "css app" do
|
|
|
|
before(:all) do
|
|
|
|
body = "css"
|
|
|
|
@app = lambda do |env|
|
|
|
|
[200, {"Content-Type" => "text/css", "Content-Length" => body.length.to_s}, [body]]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-09-23 11:00:50 -04:00
|
|
|
it "renders unsupported content types gracefully" do
|
2011-09-15 11:22:10 -04:00
|
|
|
subject.visit("/")
|
|
|
|
subject.body.should =~ /css/
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
context "hello app" do
|
2011-03-11 11:19:59 -05:00
|
|
|
before(:all) do
|
|
|
|
@app = lambda do |env|
|
2011-02-26 16:35:21 -05:00
|
|
|
body = <<-HTML
|
2011-03-09 23:50:21 -05:00
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<style type="text/css">
|
|
|
|
#display_none { display: none }
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
2011-09-23 11:57:09 -04:00
|
|
|
<div class='normalize'>Spaces not normalized </div>
|
2011-03-09 23:50:21 -05:00
|
|
|
<div id="display_none">
|
|
|
|
<div id="invisible">Can't see me</div>
|
|
|
|
</div>
|
2011-05-23 09:01:12 -04:00
|
|
|
<input type="text" disabled="disabled"/>
|
2011-07-16 13:34:31 -04:00
|
|
|
<input id="checktest" type="checkbox" checked="checked"/>
|
2011-03-09 23:50:21 -05:00
|
|
|
<script type="text/javascript">
|
|
|
|
document.write("<p id='greeting'>he" + "llo</p>");
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|
2011-02-26 16:35:21 -05:00
|
|
|
HTML
|
|
|
|
[200,
|
|
|
|
{ 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
|
|
|
|
[body]]
|
|
|
|
end
|
|
|
|
end
|
2011-02-18 22:53:06 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "finds content after loading a URL" do
|
|
|
|
subject.find("//*[contains(., 'hello')]").should_not be_empty
|
|
|
|
end
|
2011-02-24 23:22:56 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "has an empty page after reseting" do
|
|
|
|
subject.reset!
|
|
|
|
subject.find("//*[contains(., 'hello')]").should be_empty
|
|
|
|
end
|
2011-02-25 00:15:08 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "raises an error for an invalid xpath query" do
|
|
|
|
expect { subject.find("totally invalid salad") }.
|
2011-07-12 15:31:10 -04:00
|
|
|
to raise_error(Capybara::Driver::Webkit::WebkitInvalidResponseError, /xpath/i)
|
2011-02-26 16:35:21 -05:00
|
|
|
end
|
2011-02-25 22:57:55 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "returns an attribute's value" do
|
|
|
|
subject.find("//p").first["id"].should == "greeting"
|
|
|
|
end
|
2011-02-25 23:39:29 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "parses xpath with quotes" do
|
|
|
|
subject.find('//*[contains(., "hello")]').should_not be_empty
|
|
|
|
end
|
2011-02-26 10:06:11 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "returns a node's text" do
|
|
|
|
subject.find("//p").first.text.should == "hello"
|
|
|
|
end
|
2011-02-25 18:04:23 -05:00
|
|
|
|
2011-09-23 11:57:09 -04:00
|
|
|
it "normalizes a node's text" do
|
|
|
|
subject.find("//div[contains(@class, 'normalize')]").first.text.should == "Spaces not normalized"
|
|
|
|
end
|
|
|
|
|
2011-02-26 16:35:21 -05: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-26 10:19:24 -05:00
|
|
|
|
2011-04-13 14:50:20 -04:00
|
|
|
it "escapes URLs" do
|
|
|
|
subject.visit("/hello there")
|
|
|
|
subject.current_url.should =~ /hello%20there/
|
|
|
|
end
|
|
|
|
|
2011-06-02 15:45:28 -04:00
|
|
|
it "visits a page with an anchor" do
|
|
|
|
subject.visit("/hello#display_none")
|
|
|
|
subject.current_url.should =~ /hello#display_none/
|
|
|
|
end
|
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "returns the source code for the page" do
|
|
|
|
subject.source.should =~ %r{<html>.*greeting.*}m
|
|
|
|
end
|
2011-02-26 13:02:43 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "evaluates Javascript and returns a string" do
|
|
|
|
result = subject.evaluate_script(%<document.getElementById('greeting').innerText>)
|
|
|
|
result.should == "hello"
|
|
|
|
end
|
2011-02-26 13:02:43 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "evaluates Javascript and returns an array" do
|
|
|
|
result = subject.evaluate_script(%<["hello", "world"]>)
|
|
|
|
result.should == %w(hello world)
|
|
|
|
end
|
2011-02-26 13:02:43 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "evaluates Javascript and returns an int" do
|
|
|
|
result = subject.evaluate_script(%<123>)
|
|
|
|
result.should == 123
|
|
|
|
end
|
2011-02-26 13:02:43 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "evaluates Javascript and returns a float" do
|
|
|
|
result = subject.evaluate_script(%<1.5>)
|
|
|
|
result.should == 1.5
|
|
|
|
end
|
2011-02-26 13:02:43 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "evaluates Javascript and returns null" do
|
|
|
|
result = subject.evaluate_script(%<(function () {})()>)
|
|
|
|
result.should == nil
|
|
|
|
end
|
2011-02-26 13:02:43 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "evaluates Javascript and returns an object" do
|
|
|
|
result = subject.evaluate_script(%<({ 'one' : 1 })>)
|
|
|
|
result.should == { 'one' => 1 }
|
|
|
|
end
|
2011-02-26 13:02:43 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "evaluates Javascript and returns true" do
|
|
|
|
result = subject.evaluate_script(%<true>)
|
|
|
|
result.should === true
|
|
|
|
end
|
2011-02-26 13:02:43 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "evaluates Javascript and returns false" do
|
|
|
|
result = subject.evaluate_script(%<false>)
|
|
|
|
result.should === false
|
|
|
|
end
|
2011-02-26 13:38:10 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "evaluates Javascript and returns an escaped string" do
|
|
|
|
result = subject.evaluate_script(%<'"'>)
|
|
|
|
result.should === "\""
|
|
|
|
end
|
2011-02-26 14:03:30 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "evaluates Javascript with multiple lines" do
|
|
|
|
result = subject.evaluate_script("[1,\n2]")
|
|
|
|
result.should == [1, 2]
|
|
|
|
end
|
2011-02-26 14:03:30 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "executes Javascript" do
|
|
|
|
subject.execute_script(%<document.getElementById('greeting').innerHTML = 'yo'>)
|
|
|
|
subject.find("//p[contains(., 'yo')]").should_not be_empty
|
|
|
|
end
|
2011-02-18 22:53:06 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "raises an error for failing Javascript" do
|
|
|
|
expect { subject.execute_script(%<invalid salad>) }.
|
2011-07-12 15:31:10 -04:00
|
|
|
to raise_error(Capybara::Driver::Webkit::WebkitInvalidResponseError)
|
2011-02-26 16:35:21 -05:00
|
|
|
end
|
2011-02-26 15:18:11 -05:00
|
|
|
|
2011-04-13 14:28:06 -04:00
|
|
|
it "doesn't raise an error for Javascript that doesn't return anything" do
|
|
|
|
lambda { subject.execute_script(%<(function () { "returns nothing" })()>) }.
|
|
|
|
should_not raise_error
|
|
|
|
end
|
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "returns a node's tag name" do
|
|
|
|
subject.find("//p").first.tag_name.should == "p"
|
|
|
|
end
|
2011-02-26 15:50:45 -05:00
|
|
|
|
2011-05-23 09:01:12 -04:00
|
|
|
it "reads disabled property" do
|
|
|
|
subject.find("//input").first.should be_disabled
|
|
|
|
end
|
|
|
|
|
2011-07-16 13:16:08 -04:00
|
|
|
it "reads checked property" do
|
2011-07-16 13:34:31 -04:00
|
|
|
subject.find("//input[@id='checktest']").first.should be_checked
|
2011-07-16 13:16:08 -04:00
|
|
|
end
|
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "finds visible elements" do
|
|
|
|
subject.find("//p").first.should be_visible
|
|
|
|
subject.find("//*[@id='invisible']").first.should_not be_visible
|
|
|
|
end
|
2011-02-26 15:50:45 -05:00
|
|
|
end
|
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
context "form app" do
|
2011-03-11 11:19:59 -05:00
|
|
|
before(:all) do
|
|
|
|
@app = lambda do |env|
|
2011-02-26 16:35:21 -05:00
|
|
|
body = <<-HTML
|
|
|
|
<html><body>
|
|
|
|
<form action="/" method="GET">
|
|
|
|
<input type="text" name="foo" value="bar"/>
|
2011-08-25 13:37:14 -04:00
|
|
|
<input type="text" name="maxlength_foo" value="bar" maxlength="10"/>
|
2011-05-23 09:01:12 -04:00
|
|
|
<input type="text" id="disabled_input" disabled="disabled"/>
|
2011-03-11 11:25:06 -05:00
|
|
|
<input type="checkbox" name="checkedbox" value="1" checked="checked"/>
|
|
|
|
<input type="checkbox" name="uncheckedbox" value="2"/>
|
2011-02-26 16:35:21 -05:00
|
|
|
<select name="animal">
|
2011-02-26 17:51:47 -05:00
|
|
|
<option id="select-option-monkey">Monkey</option>
|
|
|
|
<option id="select-option-capybara" selected="selected">Capybara</option>
|
|
|
|
</select>
|
|
|
|
<select name="toppings" multiple="multiple">
|
2011-02-26 17:52:28 -05:00
|
|
|
<optgroup label="Mediocre Toppings">
|
|
|
|
<option selected="selected" id="topping-apple">Apple</option>
|
|
|
|
<option selected="selected" id="topping-banana">Banana</option>
|
|
|
|
</optgroup>
|
|
|
|
<optgroup label="Best Toppings">
|
|
|
|
<option selected="selected" id="topping-cherry">Cherry</option>
|
|
|
|
</optgroup>
|
2011-02-26 16:35:21 -05:00
|
|
|
</select>
|
|
|
|
<textarea id="only-textarea">what a wonderful area for text</textarea>
|
2011-03-11 11:25:06 -05:00
|
|
|
<input type="radio" id="only-radio" value="1"/>
|
2011-02-26 16:35:21 -05:00
|
|
|
</form>
|
|
|
|
</body></html>
|
|
|
|
HTML
|
|
|
|
[200,
|
|
|
|
{ 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
|
|
|
|
[body]]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a textarea's value" do
|
|
|
|
subject.find("//textarea").first.value.should == "what a wonderful area for text"
|
|
|
|
end
|
2011-02-26 16:08:14 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "returns a text input's value" do
|
|
|
|
subject.find("//input").first.value.should == "bar"
|
|
|
|
end
|
2011-02-26 16:08:14 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "returns a select's value" do
|
|
|
|
subject.find("//select").first.value.should == "Capybara"
|
|
|
|
end
|
2011-02-26 16:08:14 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "sets an input's value" do
|
|
|
|
input = subject.find("//input").first
|
|
|
|
input.set("newvalue")
|
|
|
|
input.value.should == "newvalue"
|
|
|
|
end
|
2011-02-26 16:20:05 -05:00
|
|
|
|
2011-08-25 13:37:14 -04:00
|
|
|
it "sets an input's value greater than the max length" do
|
|
|
|
input = subject.find("//input[@name='maxlength_foo']").first
|
|
|
|
input.set("allegories (poems)")
|
|
|
|
input.value.should == "allegories"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "sets an input's value equal to the max length" do
|
|
|
|
input = subject.find("//input[@name='maxlength_foo']").first
|
|
|
|
input.set("allegories")
|
|
|
|
input.value.should == "allegories"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "sets an input's value less than the max length" do
|
|
|
|
input = subject.find("//input[@name='maxlength_foo']").first
|
|
|
|
input.set("poems")
|
|
|
|
input.value.should == "poems"
|
|
|
|
end
|
|
|
|
|
2011-06-25 16:35:18 -04:00
|
|
|
it "sets an input's nil value" do
|
|
|
|
input = subject.find("//input").first
|
|
|
|
input.set(nil)
|
|
|
|
input.value.should == ""
|
|
|
|
end
|
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "sets a select's value" do
|
|
|
|
select = subject.find("//select").first
|
|
|
|
select.set("Monkey")
|
|
|
|
select.value.should == "Monkey"
|
|
|
|
end
|
2011-02-26 15:48:44 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "sets a textarea's value" do
|
|
|
|
textarea = subject.find("//textarea").first
|
|
|
|
textarea.set("newvalue")
|
|
|
|
textarea.value.should == "newvalue"
|
|
|
|
end
|
2011-02-26 17:51:47 -05:00
|
|
|
|
|
|
|
let(:monkey_option) { subject.find("//option[@id='select-option-monkey']").first }
|
|
|
|
let(:capybara_option) { subject.find("//option[@id='select-option-capybara']").first }
|
|
|
|
let(:animal_select) { subject.find("//select[@name='animal']").first }
|
|
|
|
let(:apple_option) { subject.find("//option[@id='topping-apple']").first }
|
|
|
|
let(:banana_option) { subject.find("//option[@id='topping-banana']").first }
|
|
|
|
let(:cherry_option) { subject.find("//option[@id='topping-cherry']").first }
|
|
|
|
let(:toppings_select) { subject.find("//select[@name='toppings']").first }
|
|
|
|
|
|
|
|
it "selects an option" do
|
|
|
|
animal_select.value.should == "Capybara"
|
|
|
|
monkey_option.select_option
|
|
|
|
animal_select.value.should == "Monkey"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "unselects an option in a multi-select" do
|
|
|
|
toppings_select.value.should include("Apple", "Banana", "Cherry")
|
|
|
|
|
|
|
|
apple_option.unselect_option
|
|
|
|
toppings_select.value.should_not include("Apple")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "reselects an option in a multi-select" do
|
|
|
|
apple_option.unselect_option
|
|
|
|
banana_option.unselect_option
|
|
|
|
cherry_option.unselect_option
|
|
|
|
|
|
|
|
toppings_select.value.should == []
|
|
|
|
|
|
|
|
apple_option.select_option
|
|
|
|
banana_option.select_option
|
|
|
|
cherry_option.select_option
|
|
|
|
|
|
|
|
toppings_select.value.should include("Apple", "Banana", "Cherry")
|
|
|
|
end
|
2011-03-11 11:25:06 -05:00
|
|
|
|
|
|
|
let(:checked_box) { subject.find("//input[@name='checkedbox']").first }
|
|
|
|
let(:unchecked_box) { subject.find("//input[@name='uncheckedbox']").first }
|
|
|
|
|
|
|
|
it "knows a checked box is checked" do
|
|
|
|
checked_box['checked'].should be_true
|
|
|
|
end
|
|
|
|
|
2011-07-16 13:16:08 -04:00
|
|
|
it "knows a checked box is checked using checked?" do
|
2011-07-18 09:59:38 -04:00
|
|
|
checked_box.should be_checked
|
2011-07-16 13:16:08 -04:00
|
|
|
end
|
|
|
|
|
2011-03-11 11:25:06 -05:00
|
|
|
it "knows an unchecked box is unchecked" do
|
|
|
|
unchecked_box['checked'].should_not be_true
|
|
|
|
end
|
|
|
|
|
2011-07-16 13:16:08 -04:00
|
|
|
it "knows an unchecked box is unchecked using checked?" do
|
2011-07-18 09:59:38 -04:00
|
|
|
unchecked_box.should_not be_checked
|
2011-07-16 13:16:08 -04:00
|
|
|
end
|
|
|
|
|
2011-03-11 11:25:06 -05:00
|
|
|
it "checks an unchecked box" do
|
|
|
|
unchecked_box.set(true)
|
2011-07-18 09:59:38 -04:00
|
|
|
unchecked_box.should be_checked
|
2011-03-11 11:25:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "unchecks a checked box" do
|
|
|
|
checked_box.set(false)
|
2011-07-18 09:59:38 -04:00
|
|
|
checked_box.should_not be_checked
|
2011-03-11 11:25:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "leaves a checked box checked" do
|
|
|
|
checked_box.set(true)
|
2011-07-18 09:59:38 -04:00
|
|
|
checked_box.should be_checked
|
2011-03-11 11:25:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "leaves an unchecked box unchecked" do
|
|
|
|
unchecked_box.set(false)
|
2011-07-18 09:59:38 -04:00
|
|
|
unchecked_box.should_not be_checked
|
2011-03-11 11:25:06 -05:00
|
|
|
end
|
2011-05-23 09:01:12 -04:00
|
|
|
|
|
|
|
let(:enabled_input) { subject.find("//input[@name='foo']").first }
|
|
|
|
let(:disabled_input) { subject.find("//input[@id='disabled_input']").first }
|
|
|
|
|
|
|
|
it "knows a disabled input is disabled" do
|
|
|
|
disabled_input['disabled'].should be_true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "knows a not disabled input is not disabled" do
|
|
|
|
enabled_input['disabled'].should_not be_true
|
|
|
|
end
|
2011-03-11 11:25:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "form events app" do
|
|
|
|
before(:all) do
|
|
|
|
@app = lambda do |env|
|
|
|
|
body = <<-HTML
|
|
|
|
<html><body>
|
|
|
|
<form action="/" method="GET">
|
|
|
|
<input class="watch" type="text"/>
|
|
|
|
<input class="watch" type="password"/>
|
|
|
|
<textarea class="watch"></textarea>
|
|
|
|
<input class="watch" type="checkbox"/>
|
|
|
|
<input class="watch" type="radio"/>
|
|
|
|
</form>
|
|
|
|
<ul id="events"></ul>
|
|
|
|
<script type="text/javascript">
|
|
|
|
var events = document.getElementById("events");
|
|
|
|
var recordEvent = function (event) {
|
|
|
|
var element = document.createElement("li");
|
|
|
|
element.innerHTML = event.type;
|
|
|
|
events.appendChild(element);
|
|
|
|
};
|
|
|
|
|
|
|
|
var elements = document.getElementsByClassName("watch");
|
|
|
|
for (var i = 0; i < elements.length; i++) {
|
|
|
|
var element = elements[i];
|
|
|
|
element.addEventListener("focus", recordEvent);
|
|
|
|
element.addEventListener("keydown", recordEvent);
|
2011-05-04 04:45:57 -04:00
|
|
|
element.addEventListener("keypress", recordEvent);
|
2011-03-11 11:25:06 -05:00
|
|
|
element.addEventListener("keyup", recordEvent);
|
|
|
|
element.addEventListener("change", recordEvent);
|
|
|
|
element.addEventListener("blur", recordEvent);
|
|
|
|
element.addEventListener("click", recordEvent);
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</body></html>
|
|
|
|
HTML
|
|
|
|
[200,
|
|
|
|
{ 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
|
|
|
|
[body]]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-04 04:45:57 -04:00
|
|
|
let(:newtext) { 'newvalue' }
|
|
|
|
|
|
|
|
let(:keyevents) do
|
|
|
|
(%w{focus} +
|
|
|
|
newtext.length.times.collect { %w{keydown keypress keyup} } +
|
|
|
|
%w{change blur}).flatten
|
|
|
|
end
|
|
|
|
|
2011-03-11 11:25:06 -05:00
|
|
|
it "triggers text input events" do
|
2011-05-04 04:45:57 -04:00
|
|
|
subject.find("//input[@type='text']").first.set(newtext)
|
|
|
|
subject.find("//li").map(&:text).should == keyevents
|
2011-03-11 11:25:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "triggers textarea input events" do
|
2011-05-04 04:45:57 -04:00
|
|
|
subject.find("//textarea").first.set(newtext)
|
|
|
|
subject.find("//li").map(&:text).should == keyevents
|
2011-03-11 11:25:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "triggers password input events" do
|
2011-05-04 04:45:57 -04:00
|
|
|
subject.find("//input[@type='password']").first.set(newtext)
|
|
|
|
subject.find("//li").map(&:text).should == keyevents
|
2011-03-11 11:25:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "triggers radio input events" do
|
|
|
|
subject.find("//input[@type='radio']").first.set(true)
|
2011-05-27 13:32:12 -04:00
|
|
|
subject.find("//li").map(&:text).should == %w(click change)
|
2011-03-11 11:25:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "triggers checkbox events" do
|
|
|
|
subject.find("//input[@type='checkbox']").first.set(true)
|
2011-05-27 13:32:12 -04:00
|
|
|
subject.find("//li").map(&:text).should == %w(click change)
|
2011-03-11 11:25:06 -05:00
|
|
|
end
|
2011-02-26 15:48:44 -05:00
|
|
|
end
|
2011-02-26 16:16:30 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
context "mouse app" do
|
2011-03-11 11:19:59 -05:00
|
|
|
before(:all) do
|
|
|
|
@app =lambda do |env|
|
2011-02-26 16:35:21 -05:00
|
|
|
body = <<-HTML
|
|
|
|
<html><body>
|
|
|
|
<div id="change">Change me</div>
|
|
|
|
<div id="mouseup">Push me</div>
|
|
|
|
<div id="mousedown">Release me</div>
|
2011-04-20 23:01:57 -04:00
|
|
|
<form action="/" method="GET">
|
|
|
|
<select id="change_select" name="change_select">
|
|
|
|
<option value="1" id="option-1" selected="selected">one</option>
|
|
|
|
<option value="2" id="option-2">two</option>
|
|
|
|
</select>
|
|
|
|
</form>
|
2011-02-26 16:35:21 -05:00
|
|
|
<script type="text/javascript">
|
2011-04-20 23:01:57 -04:00
|
|
|
document.getElementById("change_select").
|
|
|
|
addEventListener("change", function () {
|
|
|
|
this.className = "triggered";
|
|
|
|
});
|
2011-02-26 16:35:21 -05:00
|
|
|
document.getElementById("change").
|
|
|
|
addEventListener("change", function () {
|
|
|
|
this.className = "triggered";
|
|
|
|
});
|
|
|
|
document.getElementById("mouseup").
|
|
|
|
addEventListener("mouseup", function () {
|
|
|
|
this.className = "triggered";
|
|
|
|
});
|
|
|
|
document.getElementById("mousedown").
|
|
|
|
addEventListener("mousedown", function () {
|
|
|
|
this.className = "triggered";
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
<a href="/next">Next</a>
|
|
|
|
</body></html>
|
|
|
|
HTML
|
|
|
|
[200,
|
|
|
|
{ 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
|
|
|
|
[body]]
|
|
|
|
end
|
|
|
|
end
|
2011-02-26 16:16:30 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "clicks an element" do
|
|
|
|
subject.find("//a").first.click
|
|
|
|
subject.current_url =~ %r{/next$}
|
|
|
|
end
|
2011-02-26 16:26:22 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "fires a mouse event" do
|
|
|
|
subject.find("//*[@id='mouseup']").first.trigger("mouseup")
|
|
|
|
subject.find("//*[@class='triggered']").should_not be_empty
|
|
|
|
end
|
2011-02-26 16:26:22 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "fires a non-mouse event" do
|
|
|
|
subject.find("//*[@id='change']").first.trigger("change")
|
|
|
|
subject.find("//*[@class='triggered']").should_not be_empty
|
|
|
|
end
|
|
|
|
|
2011-04-20 23:01:57 -04:00
|
|
|
it "fires a change on select" do
|
|
|
|
select = subject.find("//select").first
|
|
|
|
select.value.should == "1"
|
|
|
|
option = subject.find("//option[@id='option-2']").first
|
|
|
|
option.select_option
|
|
|
|
select.value.should == "2"
|
|
|
|
subject.find("//select[@class='triggered']").should_not be_empty
|
|
|
|
end
|
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
it "fires drag events" do
|
|
|
|
draggable = subject.find("//*[@id='mousedown']").first
|
|
|
|
container = subject.find("//*[@id='mouseup']").first
|
2011-02-26 16:26:22 -05:00
|
|
|
|
2011-02-26 16:35:21 -05:00
|
|
|
draggable.drag_to(container)
|
|
|
|
|
2011-04-23 07:22:16 -04:00
|
|
|
subject.find("//*[@class='triggered']").size.should == 1
|
2011-02-26 16:35:21 -05:00
|
|
|
end
|
2011-02-26 16:26:22 -05:00
|
|
|
end
|
2011-02-26 16:46:59 -05:00
|
|
|
|
|
|
|
context "nesting app" do
|
2011-03-11 11:19:59 -05:00
|
|
|
before(:all) do
|
|
|
|
@app = lambda do |env|
|
2011-02-26 16:46:59 -05:00
|
|
|
body = <<-HTML
|
|
|
|
<html><body>
|
|
|
|
<div id="parent">
|
|
|
|
<div class="find">Expected</div>
|
|
|
|
</div>
|
|
|
|
<div class="find">Unexpected</div>
|
|
|
|
</body></html>
|
|
|
|
HTML
|
|
|
|
[200,
|
|
|
|
{ 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
|
|
|
|
[body]]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "evaluates nested xpath expressions" do
|
|
|
|
parent = subject.find("//*[@id='parent']").first
|
|
|
|
parent.find("./*[@class='find']").map(&:text).should == %w(Expected)
|
|
|
|
end
|
|
|
|
end
|
2011-03-09 00:08:30 -05:00
|
|
|
|
|
|
|
context "slow app" do
|
2011-03-11 11:19:59 -05:00
|
|
|
before(:all) do
|
|
|
|
@app = lambda do |env|
|
2011-03-09 00:08:30 -05:00
|
|
|
body = <<-HTML
|
|
|
|
<html><body>
|
|
|
|
<form action="/next"><input type="submit"/></form>
|
|
|
|
<p>#{env['PATH_INFO']}</p>
|
|
|
|
</body></html>
|
|
|
|
HTML
|
|
|
|
sleep(0.5)
|
|
|
|
[200,
|
|
|
|
{ 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
|
|
|
|
[body]]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "waits for a request to load" do
|
|
|
|
subject.find("//input").first.click
|
|
|
|
subject.find("//p").first.text.should == "/next"
|
|
|
|
end
|
|
|
|
end
|
2011-03-11 12:07:30 -05:00
|
|
|
|
2011-05-05 10:30:43 -04:00
|
|
|
context "error app" do
|
|
|
|
before(:all) do
|
|
|
|
@app = lambda do |env|
|
|
|
|
if env['PATH_INFO'] == "/error"
|
|
|
|
[404, {}, []]
|
|
|
|
else
|
|
|
|
body = <<-HTML
|
|
|
|
<html><body>
|
|
|
|
<form action="/error"><input type="submit"/></form>
|
|
|
|
</body></html>
|
|
|
|
HTML
|
|
|
|
[200,
|
|
|
|
{ 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
|
|
|
|
[body]]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "raises a webkit error for the requested url" do
|
|
|
|
expect {
|
|
|
|
subject.find("//input").first.click
|
2011-05-05 18:27:04 -04:00
|
|
|
wait_for_error_to_complete
|
|
|
|
subject.find("//body")
|
2011-05-05 10:30:43 -04:00
|
|
|
}.
|
2011-07-12 15:31:10 -04:00
|
|
|
to raise_error(Capybara::Driver::Webkit::WebkitInvalidResponseError, %r{/error})
|
2011-05-05 10:30:43 -04:00
|
|
|
end
|
2011-05-05 18:27:04 -04:00
|
|
|
|
|
|
|
def wait_for_error_to_complete
|
|
|
|
sleep(0.5)
|
|
|
|
end
|
2011-05-05 10:30:43 -04:00
|
|
|
end
|
|
|
|
|
2011-05-05 09:19:46 -04:00
|
|
|
context "slow error app" do
|
|
|
|
before(:all) do
|
|
|
|
@app = lambda do |env|
|
|
|
|
if env['PATH_INFO'] == "/error"
|
|
|
|
body = "error"
|
|
|
|
sleep(1)
|
|
|
|
[304, {}, []]
|
|
|
|
else
|
|
|
|
body = <<-HTML
|
|
|
|
<html><body>
|
|
|
|
<form action="/error"><input type="submit"/></form>
|
|
|
|
<p>hello</p>
|
|
|
|
</body></html>
|
|
|
|
HTML
|
|
|
|
[200,
|
|
|
|
{ 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
|
|
|
|
[body]]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "raises a webkit error and then continues" do
|
|
|
|
subject.find("//input").first.click
|
2011-07-12 15:31:10 -04:00
|
|
|
expect { subject.find("//p") }.to raise_error(Capybara::Driver::Webkit::WebkitInvalidResponseError)
|
2011-05-05 09:19:46 -04:00
|
|
|
subject.visit("/")
|
|
|
|
subject.find("//p").first.text.should == "hello"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-03-11 12:07:30 -05:00
|
|
|
context "popup app" do
|
|
|
|
before(:all) do
|
|
|
|
@app = lambda do |env|
|
|
|
|
body = <<-HTML
|
|
|
|
<html><body>
|
|
|
|
<script type="text/javascript">
|
|
|
|
alert("alert");
|
|
|
|
confirm("confirm");
|
|
|
|
prompt("prompt");
|
|
|
|
</script>
|
|
|
|
<p>success</p>
|
|
|
|
</body></html>
|
|
|
|
HTML
|
|
|
|
sleep(0.5)
|
|
|
|
[200,
|
|
|
|
{ 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
|
|
|
|
[body]]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't crash from alerts" do
|
|
|
|
subject.find("//p").first.text.should == "success"
|
|
|
|
end
|
|
|
|
end
|
2011-06-25 07:31:19 -04:00
|
|
|
|
|
|
|
context "custom header" do
|
|
|
|
before(:all) do
|
|
|
|
@app = lambda do |env|
|
|
|
|
body = <<-HTML
|
|
|
|
<html><body>
|
|
|
|
<p id="user-agent">#{env['HTTP_USER_AGENT']}</p>
|
|
|
|
<p id="x-capybara-webkit-header">#{env['HTTP_X_CAPYBARA_WEBKIT_HEADER']}</p>
|
|
|
|
<p id="accept">#{env['HTTP_ACCEPT']}</p>
|
|
|
|
<a href="/">/</a>
|
|
|
|
</body></html>
|
|
|
|
HTML
|
|
|
|
[200,
|
|
|
|
{ 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
|
|
|
|
[body]]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
subject.header('user-agent', 'capybara-webkit/custom-user-agent')
|
|
|
|
subject.header('x-capybara-webkit-header', 'x-capybara-webkit-header')
|
|
|
|
subject.header('accept', 'text/html')
|
|
|
|
subject.visit('/')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "can set user_agent" do
|
|
|
|
subject.find('id("user-agent")').first.text.should == 'capybara-webkit/custom-user-agent'
|
|
|
|
subject.evaluate_script('navigator.userAgent').should == 'capybara-webkit/custom-user-agent'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "keep user_agent in next page" do
|
|
|
|
subject.find("//a").first.click
|
|
|
|
subject.find('id("user-agent")').first.text.should == 'capybara-webkit/custom-user-agent'
|
|
|
|
subject.evaluate_script('navigator.userAgent').should == 'capybara-webkit/custom-user-agent'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "can set custom header" do
|
|
|
|
subject.find('id("x-capybara-webkit-header")').first.text.should == 'x-capybara-webkit-header'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "can set Accept header" do
|
|
|
|
subject.find('id("accept")').first.text.should == 'text/html'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "can reset all custom header" do
|
|
|
|
subject.reset!
|
|
|
|
subject.visit('/')
|
|
|
|
subject.find('id("user-agent")').first.text.should_not == 'capybara-webkit/custom-user-agent'
|
|
|
|
subject.evaluate_script('navigator.userAgent').should_not == 'capybara-webkit/custom-user-agent'
|
|
|
|
subject.find('id("x-capybara-webkit-header")').first.text.should be_empty
|
|
|
|
subject.find('id("accept")').first.text.should_not == 'text/html'
|
|
|
|
end
|
|
|
|
end
|
2011-07-12 15:31:10 -04:00
|
|
|
|
|
|
|
context "no response app" do
|
|
|
|
before(:all) do
|
|
|
|
@app = lambda do |env|
|
|
|
|
body = <<-HTML
|
|
|
|
<html><body>
|
|
|
|
<form action="/error"><input type="submit"/></form>
|
|
|
|
</body></html>
|
|
|
|
HTML
|
|
|
|
[200,
|
|
|
|
{ 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
|
|
|
|
[body]]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "raises a webkit error for the requested url" do
|
2011-07-13 11:35:23 -04:00
|
|
|
make_the_server_go_away
|
2011-07-12 15:31:10 -04:00
|
|
|
expect {
|
|
|
|
subject.find("//body")
|
|
|
|
}.
|
|
|
|
to raise_error(Capybara::Driver::Webkit::WebkitNoResponseError, %r{response})
|
|
|
|
make_the_server_come_back
|
|
|
|
end
|
|
|
|
|
|
|
|
def make_the_server_come_back
|
|
|
|
subject.browser.instance_variable_get(:@socket).unstub!(:gets)
|
2011-07-13 11:35:23 -04:00
|
|
|
subject.browser.instance_variable_get(:@socket).unstub!(:puts)
|
|
|
|
subject.browser.instance_variable_get(:@socket).unstub!(:print)
|
2011-07-12 15:31:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def make_the_server_go_away
|
|
|
|
subject.browser.instance_variable_get(:@socket).stub!(:gets).and_return(nil)
|
2011-07-13 11:35:23 -04:00
|
|
|
subject.browser.instance_variable_get(:@socket).stub!(:puts)
|
|
|
|
subject.browser.instance_variable_get(:@socket).stub!(:print)
|
2011-07-12 15:31:10 -04:00
|
|
|
end
|
|
|
|
end
|
2011-07-22 14:21:15 -04:00
|
|
|
|
2011-08-12 15:26:26 -04:00
|
|
|
context "custom font app" do
|
|
|
|
before(:all) do
|
|
|
|
@app = lambda do |env|
|
|
|
|
body = <<-HTML
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<style type="text/css">
|
|
|
|
p { font-family: "Verdana"; }
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<p id="text">Hello</p>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
HTML
|
|
|
|
[200,
|
|
|
|
{ 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
|
|
|
|
[body]]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "ignores custom fonts" do
|
|
|
|
font_family = subject.evaluate_script(<<-SCRIPT)
|
|
|
|
var element = document.getElementById("text");
|
|
|
|
element.ownerDocument.defaultView.getComputedStyle(element, null).getPropertyValue("font-family");
|
|
|
|
SCRIPT
|
|
|
|
font_family.should == "Arial"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-09-24 17:25:15 -04:00
|
|
|
context "cookie-based app" do
|
|
|
|
before(:all) do
|
|
|
|
@cookie = 'cookie=abc; domain=127.0.0.1; path=/'
|
|
|
|
@app = lambda do |env|
|
|
|
|
request = ::Rack::Request.new(env)
|
|
|
|
|
|
|
|
body = <<-HTML
|
|
|
|
<html><body>
|
|
|
|
<p id="cookie">#{request.cookies["cookie"] || ""}</p>
|
|
|
|
</body></html>
|
|
|
|
HTML
|
|
|
|
[200,
|
|
|
|
{ 'Content-Type' => 'text/html; charset=UTF-8',
|
|
|
|
'Content-Length' => body.length.to_s,
|
|
|
|
'Set-Cookie' => @cookie,
|
|
|
|
},
|
|
|
|
[body]]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def echoed_cookie
|
|
|
|
subject.find('id("cookie")').first.text
|
|
|
|
end
|
|
|
|
|
|
|
|
it "remembers the cookie on second visit" do
|
|
|
|
echoed_cookie.should == ""
|
|
|
|
subject.visit "/"
|
|
|
|
echoed_cookie.should == "abc"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "uses a custom cookie" do
|
|
|
|
subject.browser.set_cookie @cookie
|
|
|
|
subject.visit "/"
|
|
|
|
echoed_cookie.should == "abc"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "clears cookies" do
|
|
|
|
subject.browser.clear_cookies
|
|
|
|
subject.visit "/"
|
|
|
|
echoed_cookie.should == ""
|
|
|
|
end
|
|
|
|
|
|
|
|
it "allows enumeration of cookies" do
|
|
|
|
cookies = subject.browser.get_cookies
|
|
|
|
|
|
|
|
cookies.size.should == 1
|
|
|
|
|
2011-09-30 11:41:59 -04:00
|
|
|
cookie = Hash[cookies[0].split(/\s*;\s*/).map { |x| x.split("=", 2) }]
|
2011-09-24 17:25:15 -04:00
|
|
|
cookie["cookie"].should == "abc"
|
|
|
|
cookie["domain"].should include "127.0.0.1"
|
|
|
|
cookie["path"].should == "/"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-07-22 14:21:15 -04:00
|
|
|
context "with socket debugger" do
|
|
|
|
let(:socket_debugger_class){ Capybara::Driver::Webkit::SocketDebugger }
|
|
|
|
let(:browser_with_debugger){
|
|
|
|
Capybara::Driver::Webkit::Browser.new(:socket_class => socket_debugger_class)
|
|
|
|
}
|
|
|
|
let(:driver_with_debugger){ Capybara::Driver::Webkit.new(@app, :browser => browser_with_debugger) }
|
|
|
|
|
|
|
|
before(:all) do
|
|
|
|
@app = lambda do |env|
|
|
|
|
body = <<-HTML
|
|
|
|
<html><body>
|
|
|
|
<div id="parent">
|
|
|
|
<div class="find">Expected</div>
|
|
|
|
</div>
|
|
|
|
<div class="find">Unexpected</div>
|
|
|
|
</body></html>
|
|
|
|
HTML
|
|
|
|
[200,
|
|
|
|
{ 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
|
|
|
|
[body]]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "prints out sent content" do
|
|
|
|
socket_debugger_class.any_instance.stub(:received){|content| content }
|
|
|
|
sent_content = ['Find', 1, 17, "//*[@id='parent']"]
|
|
|
|
socket_debugger_class.any_instance.should_receive(:sent).exactly(sent_content.size).times
|
|
|
|
driver_with_debugger.find("//*[@id='parent']")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "prints out received content" do
|
|
|
|
socket_debugger_class.any_instance.stub(:sent)
|
|
|
|
socket_debugger_class.any_instance.should_receive(:received).at_least(:once).and_return("ok")
|
|
|
|
driver_with_debugger.find("//*[@id='parent']")
|
|
|
|
end
|
|
|
|
end
|
2011-02-26 14:55:40 -05:00
|
|
|
end
|