capybara 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +4 -4
- data/README.rdoc +9 -2
- data/lib/capybara.rb +12 -6
- data/lib/capybara/driver/base.rb +17 -0
- data/lib/capybara/driver/culerity_driver.rb +22 -10
- data/lib/capybara/driver/rack_test_driver.rb +41 -36
- data/lib/capybara/driver/selenium_driver.rb +12 -5
- data/lib/capybara/dsl.rb +6 -6
- data/lib/capybara/node.rb +9 -5
- data/lib/capybara/rails.rb +0 -4
- data/lib/capybara/server.rb +3 -0
- data/lib/capybara/session.rb +69 -81
- data/lib/capybara/xpath.rb +124 -0
- data/spec/driver/selenium_driver_spec.rb +1 -1
- data/spec/drivers_spec.rb +20 -3
- data/spec/dsl_spec.rb +4 -3
- data/spec/public/jquery-ui.js +35 -0
- data/spec/session/culerity_session_spec.rb +4 -3
- data/spec/session/rack_test_session_spec.rb +4 -3
- data/spec/session/selenium_session_spec.rb +5 -4
- data/spec/session_spec.rb +248 -49
- data/spec/test_app.rb +1 -1
- data/spec/views/form.erb +26 -3
- data/spec/views/with_js.erb +25 -0
- data/spec/xpath_spec.rb +195 -0
- metadata +6 -6
- data/lib/capybara/driver/firewatir_driver.rb +0 -66
- data/lib/capybara/driver/safariwatir_driver.rb +0 -67
- data/spec/driver/firewatir_driver_spec.rb +0 -10
- data/spec/driver/safariwarit_driver_spec.rb +0 -10
data/spec/test_app.rb
CHANGED
data/spec/views/form.erb
CHANGED
@@ -2,8 +2,10 @@
|
|
2
2
|
|
3
3
|
<form action="/form" method="post">
|
4
4
|
<p>
|
5
|
-
<label for="form_first_name">
|
6
|
-
|
5
|
+
<label for="form_first_name">
|
6
|
+
First Name
|
7
|
+
<input type="text" name="form[first_name]" value="John" id="form_first_name"/>
|
8
|
+
</label>
|
7
9
|
</p>
|
8
10
|
|
9
11
|
<p>
|
@@ -11,11 +13,27 @@
|
|
11
13
|
<input type="text" name="form[last_name]" value="Smith" id="form_last_name"/>
|
12
14
|
</p>
|
13
15
|
|
16
|
+
<p>
|
17
|
+
<label for="form_name">Name</label>
|
18
|
+
<input type="text" name="form[name]" value="John Smith" id="form_name"/>
|
19
|
+
</p>
|
20
|
+
|
21
|
+
<p>
|
22
|
+
<label for="form_phone">Phone</label>
|
23
|
+
<input type="text" name="form[phone]" value="+1 555 7021" id="form_phone"/>
|
24
|
+
</p>
|
25
|
+
|
14
26
|
<p>
|
15
27
|
<label for="form_password">Password</label>
|
16
28
|
<input type="password" name="form[password]" value="seeekrit" id="form_password"/>
|
17
29
|
</p>
|
18
|
-
|
30
|
+
|
31
|
+
<p>
|
32
|
+
<label for="form_terms_of_use">Terms of Use</label>
|
33
|
+
<input type="hidden" name="form[terms_of_use]" value="0" id="form_terms_of_use_default">
|
34
|
+
<input type="checkbox" name="form[terms_of_use]" value="1" id="form_terms_of_use">
|
35
|
+
</p>
|
36
|
+
|
19
37
|
<p>
|
20
38
|
<label for="form_image">Image</label>
|
21
39
|
<input type="file" name="form[image]" id="form_image"/>
|
@@ -101,6 +119,11 @@
|
|
101
119
|
</form>
|
102
120
|
|
103
121
|
<form action="/upload" method="post" enctype="multipart/form-data">
|
122
|
+
<p>
|
123
|
+
<label for="form_file_name">File Name</label>
|
124
|
+
<input type="file" name="form[file_name]" id="form_file_name"/>
|
125
|
+
</p>
|
126
|
+
|
104
127
|
<p>
|
105
128
|
<label for="form_document">Document</label>
|
106
129
|
<input type="file" name="form[document]" id="form_document"/>
|
data/spec/views/with_js.erb
CHANGED
@@ -3,10 +3,27 @@
|
|
3
3
|
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
|
4
4
|
<title>with_js</title>
|
5
5
|
<script src="/jquery.js" type="text/javascript" charset="utf-8"></script>
|
6
|
+
<script src="/jquery-ui.js" type="text/javascript" charset="utf-8"></script>
|
6
7
|
<script type="text/javascript" charset="utf-8">
|
7
8
|
//<![CDATA[
|
8
9
|
$(function() {
|
9
10
|
$('#change').text('I changed it');
|
11
|
+
$('#drag').draggable();
|
12
|
+
$('#drop').droppable({
|
13
|
+
drop: function(event, ui) {
|
14
|
+
ui.draggable.remove();
|
15
|
+
$(this).html('Dropped!');
|
16
|
+
}
|
17
|
+
});
|
18
|
+
$('#clickable').click(function() {
|
19
|
+
var link = $(this);
|
20
|
+
setTimeout(function() {
|
21
|
+
$(link).after('<a href="#">Has been clicked</a>');
|
22
|
+
$(link).after('<input type="submit" value="New Here">');
|
23
|
+
$(link).after('<input type="text" id="new_field">');
|
24
|
+
}, 500);
|
25
|
+
return false;
|
26
|
+
});
|
10
27
|
});
|
11
28
|
//]]>
|
12
29
|
</script>
|
@@ -16,5 +33,13 @@
|
|
16
33
|
<h1>FooBar</h1>
|
17
34
|
|
18
35
|
<p id="change">This is text</p>
|
36
|
+
<div id="drag">
|
37
|
+
<p>This is a draggable element.</p>
|
38
|
+
</div>
|
39
|
+
<div id="drop">
|
40
|
+
<p>It should be dropped here.</p>
|
41
|
+
</div>
|
42
|
+
|
43
|
+
<p><a href="#" id="clickable">Click me</a></p>
|
19
44
|
</body>
|
20
45
|
</html>
|
data/spec/xpath_spec.rb
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe Capybara::XPath do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@driver = Capybara::Driver::RackTest.new(TestApp)
|
7
|
+
@driver.visit('/form')
|
8
|
+
@xpath = Capybara::XPath.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should proxy any class method calls to a new instance" do
|
12
|
+
@query = Capybara::XPath.fillable_field('First Name').to_s
|
13
|
+
@driver.find(@query).first.value.should == 'John'
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should respond to instance methods at the class level" do
|
17
|
+
Capybara::XPath.should respond_to(:fillable_field)
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '.wrap' do
|
21
|
+
it "should return an XPath unmodified" do
|
22
|
+
Capybara::XPath.wrap(@xpath).should == @xpath
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should wrap a string in an xpath object" do
|
26
|
+
@xpath = Capybara::XPath.wrap('//foo/bar')
|
27
|
+
@xpath.should be_an_instance_of(Capybara::XPath)
|
28
|
+
@xpath.paths.should == ['//foo/bar']
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#scope' do
|
33
|
+
it "should prepend the given scope to all paths" do
|
34
|
+
@xpath = Capybara::XPath.new('//foo/bar', '//test[@blah=foo]').scope('//quox')
|
35
|
+
@xpath.paths.should include('//quox//foo/bar', '//quox//test[@blah=foo]')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#field' do
|
40
|
+
it "should find any field by id or label" do
|
41
|
+
@query = @xpath.field('First Name').to_s
|
42
|
+
@driver.find(@query).first.value.should == 'John'
|
43
|
+
@query = @xpath.field('Password').to_s
|
44
|
+
@driver.find(@query).first.value.should == 'seeekrit'
|
45
|
+
@query = @xpath.field('Description').to_s
|
46
|
+
@driver.find(@query).first.text.should == 'Descriptive text goes here'
|
47
|
+
@query = @xpath.field('Document').to_s
|
48
|
+
@driver.find(@query).first[:name].should == 'form[document]'
|
49
|
+
@query = @xpath.field('Cat').to_s
|
50
|
+
@driver.find(@query).first.value.should == 'cat'
|
51
|
+
@query = @xpath.field('Male').to_s
|
52
|
+
@driver.find(@query).first.value.should == 'male'
|
53
|
+
@query = @xpath.field('Region').to_s
|
54
|
+
@driver.find(@query).first[:name].should == 'form[region]'
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should be chainable" do
|
58
|
+
@query = @xpath.field('First Name').password_field('First Name').to_s
|
59
|
+
@driver.find(@query).first.value.should == 'John'
|
60
|
+
@query = @xpath.field('Password').password_field('Password').to_s
|
61
|
+
@driver.find(@query).first.value.should == 'seeekrit'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#fillable_field' do
|
66
|
+
it "should find a text field, password field, or text area by id or label" do
|
67
|
+
@query = @xpath.fillable_field('First Name').to_s
|
68
|
+
@driver.find(@query).first.value.should == 'John'
|
69
|
+
@query = @xpath.fillable_field('Password').to_s
|
70
|
+
@driver.find(@query).first.value.should == 'seeekrit'
|
71
|
+
@query = @xpath.fillable_field('Description').to_s
|
72
|
+
@driver.find(@query).first.text.should == 'Descriptive text goes here'
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should be chainable" do
|
76
|
+
@query = @xpath.fillable_field('First Name').password_field('First Name').to_s
|
77
|
+
@driver.find(@query).first.value.should == 'John'
|
78
|
+
@query = @xpath.fillable_field('Password').password_field('Password').to_s
|
79
|
+
@driver.find(@query).first.value.should == 'seeekrit'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '#text_field' do
|
84
|
+
it "should find a text field by id or label" do
|
85
|
+
@query = @xpath.text_field('form_first_name').to_s
|
86
|
+
@driver.find(@query).first.value.should == 'John'
|
87
|
+
@query = @xpath.text_field('First Name').to_s
|
88
|
+
@driver.find(@query).first.value.should == 'John'
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should be chainable" do
|
92
|
+
@query = @xpath.text_field('First Name').password_field('First Name').to_s
|
93
|
+
@driver.find(@query).first.value.should == 'John'
|
94
|
+
@query = @xpath.text_field('Password').password_field('Password').to_s
|
95
|
+
@driver.find(@query).first.value.should == 'seeekrit'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#password_field' do
|
100
|
+
it "should find a password field by id or label" do
|
101
|
+
@query = @xpath.password_field('form_password').to_s
|
102
|
+
@driver.find(@query).first.value.should == 'seeekrit'
|
103
|
+
@query = @xpath.password_field('Password').to_s
|
104
|
+
@driver.find(@query).first.value.should == 'seeekrit'
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should be chainable" do
|
108
|
+
@query = @xpath.password_field('First Name').text_field('First Name').to_s
|
109
|
+
@driver.find(@query).first.value.should == 'John'
|
110
|
+
@query = @xpath.password_field('Password').text_field('Password').to_s
|
111
|
+
@driver.find(@query).first.value.should == 'seeekrit'
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe '#text_area' do
|
116
|
+
it "should find a text area by id or label" do
|
117
|
+
@query = @xpath.text_area('form_description').to_s
|
118
|
+
@driver.find(@query).first.text.should == 'Descriptive text goes here'
|
119
|
+
@query = @xpath.text_area('Description').to_s
|
120
|
+
@driver.find(@query).first.text.should == 'Descriptive text goes here'
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should be chainable" do
|
124
|
+
@query = @xpath.text_area('Description').password_field('Description').to_s
|
125
|
+
@driver.find(@query).first.text.should == 'Descriptive text goes here'
|
126
|
+
@query = @xpath.text_area('Password').password_field('Password').to_s
|
127
|
+
@driver.find(@query).first.value.should == 'seeekrit'
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe '#radio_button' do
|
132
|
+
it "should find a radio button by id or label" do
|
133
|
+
@query = @xpath.radio_button('Male').to_s
|
134
|
+
@driver.find(@query).first.value.should == 'male'
|
135
|
+
@query = @xpath.radio_button('gender_male').to_s
|
136
|
+
@driver.find(@query).first.value.should == 'male'
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should be chainable" do
|
140
|
+
@query = @xpath.radio_button('Male').password_field('Male').to_s
|
141
|
+
@driver.find(@query).first.value.should == 'male'
|
142
|
+
@query = @xpath.radio_button('Password').password_field('Password').to_s
|
143
|
+
@driver.find(@query).first.value.should == 'seeekrit'
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe '#checkbox' do
|
148
|
+
it "should find a checkbox by id or label" do
|
149
|
+
@query = @xpath.checkbox('Cat').to_s
|
150
|
+
@driver.find(@query).first.value.should == 'cat'
|
151
|
+
@query = @xpath.checkbox('form_pets_cat').to_s
|
152
|
+
@driver.find(@query).first.value.should == 'cat'
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should be chainable" do
|
156
|
+
@query = @xpath.checkbox('Cat').password_field('Cat').to_s
|
157
|
+
@driver.find(@query).first.value.should == 'cat'
|
158
|
+
@query = @xpath.checkbox('Password').password_field('Password').to_s
|
159
|
+
@driver.find(@query).first.value.should == 'seeekrit'
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe '#select' do
|
164
|
+
it "should find a select by id or label" do
|
165
|
+
@query = @xpath.select('Region').to_s
|
166
|
+
@driver.find(@query).first[:name].should == 'form[region]'
|
167
|
+
@query = @xpath.select('form_region').to_s
|
168
|
+
@driver.find(@query).first[:name].should == 'form[region]'
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should be chainable" do
|
172
|
+
@query = @xpath.select('Region').password_field('Region').to_s
|
173
|
+
@driver.find(@query).first[:name].should == 'form[region]'
|
174
|
+
@query = @xpath.select('Password').password_field('Password').to_s
|
175
|
+
@driver.find(@query).first.value.should == 'seeekrit'
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe '#file_field' do
|
180
|
+
it "should find a file field by id or label" do
|
181
|
+
@query = @xpath.file_field('Document').to_s
|
182
|
+
@driver.find(@query).first[:name].should == 'form[document]'
|
183
|
+
@query = @xpath.file_field('form_document').to_s
|
184
|
+
@driver.find(@query).first[:name].should == 'form[document]'
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should be chainable" do
|
188
|
+
@query = @xpath.file_field('Document').password_field('Document').to_s
|
189
|
+
@driver.find(@query).first[:name].should == 'form[document]'
|
190
|
+
@query = @xpath.file_field('Password').password_field('Password').to_s
|
191
|
+
@driver.find(@query).first.value.should == 'seeekrit'
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Nicklas
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-12 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -115,10 +115,9 @@ files:
|
|
115
115
|
- Rakefile
|
116
116
|
- lib/capybara.rb
|
117
117
|
- lib/capybara/cucumber.rb
|
118
|
+
- lib/capybara/driver/base.rb
|
118
119
|
- lib/capybara/driver/culerity_driver.rb
|
119
|
-
- lib/capybara/driver/firewatir_driver.rb
|
120
120
|
- lib/capybara/driver/rack_test_driver.rb
|
121
|
-
- lib/capybara/driver/safariwatir_driver.rb
|
122
121
|
- lib/capybara/driver/selenium_driver.rb
|
123
122
|
- lib/capybara/dsl.rb
|
124
123
|
- lib/capybara/node.rb
|
@@ -126,17 +125,17 @@ files:
|
|
126
125
|
- lib/capybara/save_and_open_page.rb
|
127
126
|
- lib/capybara/server.rb
|
128
127
|
- lib/capybara/session.rb
|
128
|
+
- lib/capybara/xpath.rb
|
129
129
|
- script/console
|
130
130
|
- script/destroy
|
131
131
|
- script/generate
|
132
132
|
- spec/driver/culerity_driver_spec.rb
|
133
|
-
- spec/driver/firewatir_driver_spec.rb
|
134
133
|
- spec/driver/rack_test_driver_spec.rb
|
135
|
-
- spec/driver/safariwarit_driver_spec.rb
|
136
134
|
- spec/driver/selenium_driver_spec.rb
|
137
135
|
- spec/drivers_spec.rb
|
138
136
|
- spec/dsl_spec.rb
|
139
137
|
- spec/fixtures/test_file.txt
|
138
|
+
- spec/public/jquery-ui.js
|
140
139
|
- spec/public/jquery.js
|
141
140
|
- spec/save_and_open_page_spec.rb
|
142
141
|
- spec/session/culerity_session_spec.rb
|
@@ -153,6 +152,7 @@ files:
|
|
153
152
|
- spec/views/with_js.erb
|
154
153
|
- spec/views/with_scope.erb
|
155
154
|
- spec/views/with_simple_html.erb
|
155
|
+
- spec/xpath_spec.rb
|
156
156
|
has_rdoc: true
|
157
157
|
homepage: http://github.com/jnicklas/capybara
|
158
158
|
licenses: []
|
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'watir'
|
2
|
-
Watir::Browser.default = "firefox"
|
3
|
-
|
4
|
-
class Capybara::Driver::FireWatir
|
5
|
-
class Node < Struct.new(:node)
|
6
|
-
def text
|
7
|
-
node.text
|
8
|
-
end
|
9
|
-
|
10
|
-
def attribute(name)
|
11
|
-
value = if name.to_sym == :class
|
12
|
-
node.class_name
|
13
|
-
else
|
14
|
-
node.send(name.to_sym)
|
15
|
-
end
|
16
|
-
return value if value and not value.empty?
|
17
|
-
end
|
18
|
-
|
19
|
-
def click
|
20
|
-
node.click
|
21
|
-
end
|
22
|
-
|
23
|
-
def tag_name
|
24
|
-
# FIXME: this might be the dumbest way ever of getting the tag name
|
25
|
-
# there has to be something better...
|
26
|
-
node.to_xml[/^\s*<([a-z0-9\-\:]+)/, 1]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
attr_reader :app, :rack_server
|
31
|
-
|
32
|
-
def initialize(app)
|
33
|
-
@app = app
|
34
|
-
@rack_server = Capybara::Server.new(@app)
|
35
|
-
@rack_server.boot
|
36
|
-
end
|
37
|
-
|
38
|
-
def visit(path)
|
39
|
-
browser.goto(url(path))
|
40
|
-
end
|
41
|
-
|
42
|
-
def body
|
43
|
-
browser.html
|
44
|
-
end
|
45
|
-
|
46
|
-
def find(selector)
|
47
|
-
browser.elements_by_xpath(selector).map { |node| Node.new(node) }
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
def url(path)
|
53
|
-
rack_server.url(path)
|
54
|
-
end
|
55
|
-
|
56
|
-
def browser
|
57
|
-
unless @_browser
|
58
|
-
@_browser = Watir::Browser.new
|
59
|
-
at_exit do
|
60
|
-
@_browser.exit
|
61
|
-
end
|
62
|
-
end
|
63
|
-
@_browser
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'safariwatir'
|
2
|
-
|
3
|
-
class Capybara::Driver::SafariWatir
|
4
|
-
class Node < Struct.new(:node)
|
5
|
-
def text
|
6
|
-
node.text
|
7
|
-
end
|
8
|
-
|
9
|
-
def attribute(name)
|
10
|
-
value = if name.to_sym == :class
|
11
|
-
node.class_name
|
12
|
-
else
|
13
|
-
node.send(name.to_sym)
|
14
|
-
end
|
15
|
-
return value if value and not value.empty?
|
16
|
-
end
|
17
|
-
|
18
|
-
def click
|
19
|
-
node.click
|
20
|
-
end
|
21
|
-
|
22
|
-
def tag_name
|
23
|
-
# FIXME: this might be the dumbest way ever of getting the tag name
|
24
|
-
# there has to be something better...
|
25
|
-
node.to_xml[/^\s*<([a-z0-9\-\:]+)/, 1]
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
attr_reader :app, :rack_server
|
30
|
-
|
31
|
-
def initialize(app)
|
32
|
-
@app = app
|
33
|
-
@rack_server = Capybara::Server.new(@app)
|
34
|
-
@rack_server.boot
|
35
|
-
end
|
36
|
-
|
37
|
-
def visit(path)
|
38
|
-
browser.goto(url(path))
|
39
|
-
end
|
40
|
-
|
41
|
-
def body
|
42
|
-
browser.html
|
43
|
-
end
|
44
|
-
|
45
|
-
def find(selector)
|
46
|
-
foo = Struct.new(:what).new
|
47
|
-
foo.what = selector
|
48
|
-
browser.send(:scripter).operate_by_xpath(foo){}.map { |node| Node.new(node) }
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
def url(path)
|
54
|
-
rack_server.url(path)
|
55
|
-
end
|
56
|
-
|
57
|
-
def browser
|
58
|
-
unless @_browser
|
59
|
-
@_browser = Watir::Safari.new
|
60
|
-
at_exit do
|
61
|
-
@_browser.exit
|
62
|
-
end
|
63
|
-
end
|
64
|
-
@_browser
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|