capybara 2.0.0.beta2 → 2.0.0.beta4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +30 -1
- data/README.md +52 -31
- data/lib/capybara.rb +1 -0
- data/lib/capybara/driver/base.rb +1 -1
- data/lib/capybara/driver/node.rb +1 -0
- data/lib/capybara/dsl.rb +12 -5
- data/lib/capybara/helpers.rb +33 -0
- data/lib/capybara/node/actions.rb +4 -2
- data/lib/capybara/node/base.rb +52 -1
- data/lib/capybara/node/element.rb +0 -12
- data/lib/capybara/node/finders.rb +1 -1
- data/lib/capybara/node/matchers.rb +57 -47
- data/lib/capybara/node/simple.rb +4 -0
- data/lib/capybara/query.rb +11 -11
- data/lib/capybara/rack_test/browser.rb +14 -15
- data/lib/capybara/rack_test/driver.rb +2 -2
- data/lib/capybara/rack_test/node.rb +15 -2
- data/lib/capybara/result.rb +7 -19
- data/lib/capybara/rspec.rb +7 -4
- data/lib/capybara/rspec/features.rb +4 -1
- data/lib/capybara/rspec/matchers.rb +8 -3
- data/lib/capybara/selector.rb +1 -2
- data/lib/capybara/selenium/driver.rb +2 -2
- data/lib/capybara/selenium/node.rb +9 -7
- data/lib/capybara/session.rb +47 -31
- data/lib/capybara/spec/fixtures/another_test_file.txt +1 -0
- data/lib/capybara/spec/public/test.js +1 -1
- data/lib/capybara/spec/session/all_spec.rb +60 -62
- data/lib/capybara/spec/session/assert_selector.rb +123 -0
- data/lib/capybara/spec/session/attach_file_spec.rb +72 -58
- data/lib/capybara/spec/session/body_spec.rb +21 -0
- data/lib/capybara/spec/session/check_spec.rb +67 -50
- data/lib/capybara/spec/session/choose_spec.rb +32 -21
- data/lib/capybara/spec/session/click_button_spec.rb +261 -221
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +40 -30
- data/lib/capybara/spec/session/click_link_spec.rb +95 -81
- data/lib/capybara/spec/session/current_url_spec.rb +70 -60
- data/lib/capybara/spec/session/evaluate_script_spec.rb +6 -0
- data/lib/capybara/spec/session/execute_script_spec.rb +7 -0
- data/lib/capybara/spec/session/fill_in_spec.rb +118 -92
- data/lib/capybara/spec/session/find_button_spec.rb +16 -14
- data/lib/capybara/spec/session/find_by_id_spec.rb +16 -14
- data/lib/capybara/spec/session/find_field_spec.rb +23 -21
- data/lib/capybara/spec/session/find_link_spec.rb +15 -14
- data/lib/capybara/spec/session/find_spec.rb +96 -91
- data/lib/capybara/spec/session/first_spec.rb +53 -55
- data/lib/capybara/spec/session/has_button_spec.rb +22 -24
- data/lib/capybara/spec/session/has_css_spec.rb +190 -205
- data/lib/capybara/spec/session/has_field_spec.rb +167 -169
- data/lib/capybara/spec/session/has_link_spec.rb +26 -29
- data/lib/capybara/spec/session/has_select_spec.rb +175 -176
- data/lib/capybara/spec/session/has_selector_spec.rb +94 -100
- data/lib/capybara/spec/session/has_table_spec.rb +22 -26
- data/lib/capybara/spec/session/has_text_spec.rb +159 -132
- data/lib/capybara/spec/session/has_xpath_spec.rb +100 -96
- data/lib/capybara/spec/session/headers.rb +4 -17
- data/lib/capybara/spec/session/html_spec.rb +15 -0
- data/lib/capybara/spec/session/node_spec.rb +172 -82
- data/lib/capybara/spec/session/reset_session_spec.rb +42 -0
- data/lib/capybara/spec/session/response_code.rb +4 -17
- data/lib/capybara/spec/session/save_page_spec.rb +46 -0
- data/lib/capybara/spec/session/screenshot.rb +8 -24
- data/lib/capybara/spec/session/select_spec.rb +100 -89
- data/lib/capybara/spec/session/source_spec.rb +12 -0
- data/lib/capybara/spec/session/text_spec.rb +15 -17
- data/lib/capybara/spec/session/uncheck_spec.rb +22 -17
- data/lib/capybara/spec/session/unselect_spec.rb +57 -52
- data/lib/capybara/spec/session/visit_spec.rb +58 -60
- data/lib/capybara/spec/session/within_frame_spec.rb +24 -26
- data/lib/capybara/spec/session/within_spec.rb +119 -121
- data/lib/capybara/spec/session/within_window_spec.rb +29 -31
- data/lib/capybara/spec/spec_helper.rb +84 -0
- data/lib/capybara/spec/test_app.rb +5 -3
- data/lib/capybara/spec/views/form.erb +1 -0
- data/lib/capybara/spec/views/with_html.erb +6 -1
- data/lib/capybara/spec/views/with_js.erb +1 -0
- data/lib/capybara/version.rb +1 -1
- data/spec/basic_node_spec.rb +2 -2
- data/spec/capybara_spec.rb +9 -0
- data/spec/dsl_spec.rb +22 -10
- data/spec/rack_test_spec.rb +28 -23
- data/spec/result_spec.rb +51 -0
- data/spec/rspec/features_spec.rb +19 -0
- data/spec/rspec/matchers_spec.rb +6 -0
- data/spec/rspec_spec.rb +1 -1
- data/spec/selenium_spec.rb +11 -25
- data/spec/server_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -46
- metadata +41 -98
- data/lib/capybara/spec/session.rb +0 -183
- data/lib/capybara/spec/session/javascript.rb +0 -290
- data/lib/capybara/util/save_and_open_page.rb +0 -45
- data/spec/save_and_open_page_spec.rb +0 -155
|
@@ -1,123 +1,127 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
Capybara::SpecHelper.spec '#has_xpath?' do
|
|
2
|
+
before do
|
|
3
|
+
@session.visit('/with_html')
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
it "should be true if the given selector is on the page" do
|
|
7
|
+
@session.should have_xpath("//p")
|
|
8
|
+
@session.should have_xpath("//p//a[@id='foo']")
|
|
9
|
+
@session.should have_xpath("//p[contains(.,'est')]")
|
|
10
|
+
end
|
|
6
11
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
it "should be false if the given selector is not on the page" do
|
|
13
|
+
@session.should_not have_xpath("//abbr")
|
|
14
|
+
@session.should_not have_xpath("//p//a[@id='doesnotexist']")
|
|
15
|
+
@session.should_not have_xpath("//p[contains(.,'thisstringisnotonpage')]")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "should use xpath even if default selector is CSS" do
|
|
19
|
+
Capybara.default_selector = :css
|
|
20
|
+
@session.should_not have_xpath("//p//a[@id='doesnotexist']")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "should respect scopes" do
|
|
24
|
+
@session.within "//p[@id='first']" do
|
|
25
|
+
@session.should have_xpath(".//a[@id='foo']")
|
|
26
|
+
@session.should_not have_xpath(".//a[@id='red']")
|
|
11
27
|
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "should wait for content to appear", :requires => [:js] do
|
|
31
|
+
@session.visit('/with_js')
|
|
32
|
+
@session.click_link('Click me')
|
|
33
|
+
@session.should have_xpath("//input[@type='submit' and @value='New Here']")
|
|
34
|
+
end
|
|
12
35
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
@session.
|
|
16
|
-
@session.
|
|
36
|
+
context "with count" do
|
|
37
|
+
it "should be true if the content occurs the given number of times" do
|
|
38
|
+
@session.should have_xpath("//p", :count => 3)
|
|
39
|
+
@session.should have_xpath("//p//a[@id='foo']", :count => 1)
|
|
40
|
+
@session.should have_xpath("//p[contains(.,'est')]", :count => 1)
|
|
41
|
+
@session.should have_xpath("//p//a[@id='doesnotexist']", :count => 0)
|
|
17
42
|
end
|
|
18
43
|
|
|
19
|
-
it "should
|
|
20
|
-
|
|
21
|
-
@session.should_not have_xpath("//p//a[@id='
|
|
44
|
+
it "should be false if the content occurs a different number of times than the given" do
|
|
45
|
+
@session.should_not have_xpath("//p", :count => 6)
|
|
46
|
+
@session.should_not have_xpath("//p//a[@id='foo']", :count => 2)
|
|
47
|
+
@session.should_not have_xpath("//p[contains(.,'est')]", :count => 5)
|
|
48
|
+
@session.should_not have_xpath("//p//a[@id='doesnotexist']", :count => 1)
|
|
22
49
|
end
|
|
50
|
+
end
|
|
23
51
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
end
|
|
52
|
+
context "with text" do
|
|
53
|
+
it "should discard all matches where the given string is not contained" do
|
|
54
|
+
@session.should have_xpath("//p//a", :text => "Redirect", :count => 1)
|
|
55
|
+
@session.should_not have_xpath("//p", :text => "Doesnotexist")
|
|
29
56
|
end
|
|
30
57
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
@session.should have_xpath("//p//a[@id='foo']", :count => 1)
|
|
35
|
-
@session.should have_xpath("//p[contains(.,'est')]", :count => 1)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it "should be false if the content is on the page the given number of times" do
|
|
39
|
-
@session.should_not have_xpath("//p", :count => 6)
|
|
40
|
-
@session.should_not have_xpath("//p//a[@id='foo']", :count => 2)
|
|
41
|
-
@session.should_not have_xpath("//p[contains(.,'est')]", :count => 5)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it "should be false if the content isn't on the page at all" do
|
|
45
|
-
@session.should_not have_xpath("//abbr", :count => 2)
|
|
46
|
-
@session.should_not have_xpath("//p//a[@id='doesnotexist']", :count => 1)
|
|
47
|
-
end
|
|
58
|
+
it "should discard all matches where the given regexp is not matched" do
|
|
59
|
+
@session.should have_xpath("//p//a", :text => /re[dab]i/i, :count => 1)
|
|
60
|
+
@session.should_not have_xpath("//p//a", :text => /Red$/)
|
|
48
61
|
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
49
64
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
end
|
|
65
|
+
Capybara::SpecHelper.spec '#has_no_xpath?' do
|
|
66
|
+
before do
|
|
67
|
+
@session.visit('/with_html')
|
|
68
|
+
end
|
|
55
69
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
end
|
|
70
|
+
it "should be false if the given selector is on the page" do
|
|
71
|
+
@session.should_not have_no_xpath("//p")
|
|
72
|
+
@session.should_not have_no_xpath("//p//a[@id='foo']")
|
|
73
|
+
@session.should_not have_no_xpath("//p[contains(.,'est')]")
|
|
61
74
|
end
|
|
62
75
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
76
|
+
it "should be true if the given selector is not on the page" do
|
|
77
|
+
@session.should have_no_xpath("//abbr")
|
|
78
|
+
@session.should have_no_xpath("//p//a[@id='doesnotexist']")
|
|
79
|
+
@session.should have_no_xpath("//p[contains(.,'thisstringisnotonpage')]")
|
|
80
|
+
end
|
|
67
81
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
end
|
|
82
|
+
it "should use xpath even if default selector is CSS" do
|
|
83
|
+
Capybara.default_selector = :css
|
|
84
|
+
@session.should have_no_xpath("//p//a[@id='doesnotexist']")
|
|
85
|
+
end
|
|
73
86
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
@session.
|
|
77
|
-
@session.should have_no_xpath("
|
|
87
|
+
it "should respect scopes" do
|
|
88
|
+
@session.within "//p[@id='first']" do
|
|
89
|
+
@session.should_not have_no_xpath(".//a[@id='foo']")
|
|
90
|
+
@session.should have_no_xpath(".//a[@id='red']")
|
|
78
91
|
end
|
|
92
|
+
end
|
|
79
93
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
94
|
+
it "should wait for content to disappear", :requires => [:js] do
|
|
95
|
+
@session.visit('/with_js')
|
|
96
|
+
@session.click_link('Click me')
|
|
97
|
+
@session.should have_no_xpath("//p[@id='change']")
|
|
98
|
+
end
|
|
84
99
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
100
|
+
context "with count" do
|
|
101
|
+
it "should be false if the content occurs the given number of times" do
|
|
102
|
+
@session.should_not have_no_xpath("//p", :count => 3)
|
|
103
|
+
@session.should_not have_no_xpath("//p//a[@id='foo']", :count => 1)
|
|
104
|
+
@session.should_not have_no_xpath("//p[contains(.,'est')]", :count => 1)
|
|
105
|
+
@session.should_not have_no_xpath("//p//a[@id='doesnotexist']", :count => 0)
|
|
90
106
|
end
|
|
91
107
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
it "should be true if the content is on the page the wrong number of times" do
|
|
100
|
-
@session.should have_no_xpath("//p", :count => 6)
|
|
101
|
-
@session.should have_no_xpath("//p//a[@id='foo']", :count => 2)
|
|
102
|
-
@session.should have_no_xpath("//p[contains(.,'est')]", :count => 5)
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
it "should be true if the content isn't on the page at all" do
|
|
106
|
-
@session.should have_no_xpath("//abbr", :count => 2)
|
|
107
|
-
@session.should have_no_xpath("//p//a[@id='doesnotexist']", :count => 1)
|
|
108
|
-
end
|
|
108
|
+
it "should be true if the content occurs a different number of times than the given" do
|
|
109
|
+
@session.should have_no_xpath("//p", :count => 6)
|
|
110
|
+
@session.should have_no_xpath("//p//a[@id='foo']", :count => 2)
|
|
111
|
+
@session.should have_no_xpath("//p[contains(.,'est')]", :count => 5)
|
|
112
|
+
@session.should have_no_xpath("//p//a[@id='doesnotexist']", :count => 1)
|
|
109
113
|
end
|
|
114
|
+
end
|
|
110
115
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
+
context "with text" do
|
|
117
|
+
it "should discard all matches where the given string is contained" do
|
|
118
|
+
@session.should_not have_no_xpath("//p//a", :text => "Redirect", :count => 1)
|
|
119
|
+
@session.should have_no_xpath("//p", :text => "Doesnotexist")
|
|
120
|
+
end
|
|
116
121
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
end
|
|
122
|
+
it "should discard all matches where the given regexp is matched" do
|
|
123
|
+
@session.should_not have_no_xpath("//p//a", :text => /re[dab]i/i, :count => 1)
|
|
124
|
+
@session.should have_no_xpath("//p//a", :text => /Red$/)
|
|
121
125
|
end
|
|
122
126
|
end
|
|
123
127
|
end
|
|
@@ -1,19 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
@session.response_headers['Content-Type'].should =~ %r(text/html)
|
|
6
|
-
end
|
|
7
|
-
end
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
shared_examples_for "session without headers support" do
|
|
11
|
-
describe "#response_headers" do
|
|
12
|
-
before{ @session.visit('/with_simple_html') }
|
|
13
|
-
it "should raise an error" do
|
|
14
|
-
running {
|
|
15
|
-
@session.response_headers
|
|
16
|
-
}.should raise_error(Capybara::NotSupportedByDriverError)
|
|
17
|
-
end
|
|
1
|
+
Capybara::SpecHelper.spec '#response_headers' do
|
|
2
|
+
it "should return response headers", :requires => [:response_headers] do
|
|
3
|
+
@session.visit('/with_simple_html')
|
|
4
|
+
@session.response_headers['Content-Type'].should =~ %r(text/html)
|
|
18
5
|
end
|
|
19
6
|
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Capybara::SpecHelper.spec '#html' do
|
|
2
|
+
it "should return the unmodified page body" do
|
|
3
|
+
# html and body should be aliased, but we can't just check for
|
|
4
|
+
# method(:html) == method(:body) because these shared examples get run
|
|
5
|
+
# against the DSL, which uses forwarding methods. So we test behavior.
|
|
6
|
+
@session.visit('/')
|
|
7
|
+
@session.html.should include('Hello world!')
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should return the current state of the page", :requires => [:js] do
|
|
11
|
+
@session.visit('/with_js')
|
|
12
|
+
@session.html.should include('I changed it')
|
|
13
|
+
@session.html.should_not include('This is text')
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -1,115 +1,205 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
Capybara::SpecHelper.spec "node" do
|
|
2
|
+
before do
|
|
3
|
+
@session.visit('/with_html')
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
it "should act like a session object" do
|
|
7
|
+
@session.visit('/form')
|
|
8
|
+
@form = @session.find(:css, '#get-form')
|
|
9
|
+
@form.should have_field('Middle Name')
|
|
10
|
+
@form.should have_no_field('Languages')
|
|
11
|
+
@form.fill_in('Middle Name', :with => 'Monkey')
|
|
12
|
+
@form.click_button('med')
|
|
13
|
+
extract_results(@session)['middle_name'].should == 'Monkey'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should scope CSS selectors" do
|
|
17
|
+
@session.find(:css, '#second').should have_no_css('h1')
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe "#parent" do
|
|
21
|
+
it "should have a reference to its parent if there is one" do
|
|
22
|
+
@node = @session.find(:css, '#first')
|
|
23
|
+
@node.parent.should == @node.session.document
|
|
24
|
+
@node.find(:css, '#foo').parent.should == @node
|
|
5
25
|
end
|
|
26
|
+
end
|
|
6
27
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
@
|
|
10
|
-
@
|
|
11
|
-
@form.should have_no_field('Languages')
|
|
12
|
-
@form.fill_in('Middle Name', :with => 'Monkey')
|
|
13
|
-
@form.click_button('med')
|
|
14
|
-
extract_results(@session)['middle_name'].should == 'Monkey'
|
|
28
|
+
describe "#text" do
|
|
29
|
+
it "should extract node texts" do
|
|
30
|
+
@session.all('//a')[0].text.should == 'labore'
|
|
31
|
+
@session.all('//a')[1].text.should == 'ullamco'
|
|
15
32
|
end
|
|
16
33
|
|
|
17
|
-
it "should
|
|
18
|
-
@session.
|
|
34
|
+
it "should return document text on /html selector" do
|
|
35
|
+
@session.visit('/with_simple_html')
|
|
36
|
+
@session.all('/html')[0].text.should == 'Bar'
|
|
19
37
|
end
|
|
38
|
+
end
|
|
20
39
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
end
|
|
40
|
+
describe "#[]" do
|
|
41
|
+
it "should extract node attributes" do
|
|
42
|
+
@session.all('//a')[0][:class].should == 'simple'
|
|
43
|
+
@session.all('//a')[1][:id].should == 'foo'
|
|
44
|
+
@session.all('//input')[0][:type].should == 'text'
|
|
27
45
|
end
|
|
28
46
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
end
|
|
47
|
+
it "should extract boolean node attributes" do
|
|
48
|
+
@session.find('//input[@id="checked_field"]')[:checked].should be_true
|
|
49
|
+
end
|
|
50
|
+
end
|
|
34
51
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
end
|
|
52
|
+
describe "#value" do
|
|
53
|
+
it "should allow retrieval of the value" do
|
|
54
|
+
@session.find('//textarea[@id="normal"]').value.should == 'banana'
|
|
39
55
|
end
|
|
40
56
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
@session.all('//input')[0][:type].should == 'text'
|
|
46
|
-
end
|
|
57
|
+
it "should not swallow extra newlines in textarea" do
|
|
58
|
+
@session.find('//textarea[@id="additional_newline"]').value.should == "\nbanana"
|
|
59
|
+
end
|
|
60
|
+
end
|
|
47
61
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
62
|
+
describe "#set" do
|
|
63
|
+
it "should allow assignment of field value" do
|
|
64
|
+
@session.first('//input').value.should == 'monkey'
|
|
65
|
+
@session.first('//input').set('gorilla')
|
|
66
|
+
@session.first('//input').value.should == 'gorilla'
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
describe "#tag_name" do
|
|
71
|
+
it "should extract node tag name" do
|
|
72
|
+
@session.all('//a')[0].tag_name.should == 'a'
|
|
73
|
+
@session.all('//a')[1].tag_name.should == 'a'
|
|
74
|
+
@session.all('//p')[1].tag_name.should == 'p'
|
|
51
75
|
end
|
|
76
|
+
end
|
|
52
77
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
end
|
|
78
|
+
describe "#visible?" do
|
|
79
|
+
it "should extract node visibility" do
|
|
80
|
+
@session.first('//a').should be_visible
|
|
57
81
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
82
|
+
@session.find('//div[@id="hidden"]').should_not be_visible
|
|
83
|
+
@session.find('//div[@id="hidden_via_ancestor"]').should_not be_visible
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
describe "#checked?" do
|
|
88
|
+
it "should extract node checked state" do
|
|
89
|
+
@session.visit('/form')
|
|
90
|
+
@session.find('//input[@id="gender_female"]').should be_checked
|
|
91
|
+
@session.find('//input[@id="gender_male"]').should_not be_checked
|
|
92
|
+
@session.first('//h1').should_not be_checked
|
|
61
93
|
end
|
|
94
|
+
end
|
|
62
95
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
96
|
+
describe "#selected?" do
|
|
97
|
+
it "should extract node selected state" do
|
|
98
|
+
@session.visit('/form')
|
|
99
|
+
@session.find('//option[@value="en"]').should be_selected
|
|
100
|
+
@session.find('//option[@value="sv"]').should_not be_selected
|
|
101
|
+
@session.first('//h1').should_not be_selected
|
|
69
102
|
end
|
|
103
|
+
end
|
|
70
104
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
end
|
|
105
|
+
describe "#==" do
|
|
106
|
+
it "preserve object identity" do
|
|
107
|
+
(@session.find('//h1') == @session.find('//h1')).should be_true
|
|
108
|
+
(@session.find('//h1') === @session.find('//h1')).should be_true
|
|
109
|
+
(@session.find('//h1').eql? @session.find('//h1')).should be_false
|
|
77
110
|
end
|
|
111
|
+
end
|
|
78
112
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
113
|
+
describe "#trigger", :requires => [:js, :trigger] do
|
|
114
|
+
it "should allow triggering of custom JS events" do
|
|
115
|
+
@session.visit('/with_js')
|
|
116
|
+
@session.find(:css, '#with_focus_event').trigger(:focus)
|
|
117
|
+
@session.should have_css('#focus_event_triggered')
|
|
118
|
+
end
|
|
119
|
+
end
|
|
82
120
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
121
|
+
describe '#drag_to', :requires => [:js, :drag] do
|
|
122
|
+
it "should drag and drop an object" do
|
|
123
|
+
@session.visit('/with_js')
|
|
124
|
+
element = @session.find('//div[@id="drag"]')
|
|
125
|
+
target = @session.find('//div[@id="drop"]')
|
|
126
|
+
element.drag_to(target)
|
|
127
|
+
@session.find('//div[contains(., "Dropped!")]').should_not be_nil
|
|
86
128
|
end
|
|
129
|
+
end
|
|
87
130
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
@session.
|
|
93
|
-
@session.
|
|
131
|
+
describe '#reload', :requires => [:js] do
|
|
132
|
+
context "without automatic reload" do
|
|
133
|
+
before { Capybara.automatic_reload = false }
|
|
134
|
+
it "should reload the current context of the node" do
|
|
135
|
+
@session.visit('/with_js')
|
|
136
|
+
node = @session.find(:css, '#reload-me')
|
|
137
|
+
@session.click_link('Reload!')
|
|
138
|
+
sleep(0.3)
|
|
139
|
+
node.reload.text.should == 'has been reloaded'
|
|
140
|
+
node.text.should == 'has been reloaded'
|
|
94
141
|
end
|
|
95
|
-
end
|
|
96
142
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
@session.
|
|
100
|
-
@session.
|
|
101
|
-
|
|
102
|
-
|
|
143
|
+
it "should reload a parent node" do
|
|
144
|
+
@session.visit('/with_js')
|
|
145
|
+
node = @session.find(:css, '#reload-me').find(:css, 'em')
|
|
146
|
+
@session.click_link('Reload!')
|
|
147
|
+
sleep(0.3)
|
|
148
|
+
node.reload.text.should == 'has been reloaded'
|
|
149
|
+
node.text.should == 'has been reloaded'
|
|
103
150
|
end
|
|
104
|
-
end
|
|
105
151
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
(
|
|
152
|
+
it "should not automatically reload" do
|
|
153
|
+
@session.visit('/with_js')
|
|
154
|
+
node = @session.find(:css, '#reload-me')
|
|
155
|
+
@session.click_link('Reload!')
|
|
156
|
+
sleep(0.3)
|
|
157
|
+
expect { node.text.to == 'has been reloaded' }.to raise_error
|
|
111
158
|
end
|
|
159
|
+
after { Capybara.automatic_reload = true }
|
|
112
160
|
end
|
|
113
161
|
|
|
162
|
+
context "with automatic reload" do
|
|
163
|
+
it "should reload the current context of the node automatically" do
|
|
164
|
+
@session.visit('/with_js')
|
|
165
|
+
node = @session.find(:css, '#reload-me')
|
|
166
|
+
@session.click_link('Reload!')
|
|
167
|
+
sleep(0.3)
|
|
168
|
+
node.text.should == 'has been reloaded'
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
it "should reload a parent node automatically" do
|
|
172
|
+
@session.visit('/with_js')
|
|
173
|
+
node = @session.find(:css, '#reload-me').find(:css, 'em')
|
|
174
|
+
@session.click_link('Reload!')
|
|
175
|
+
sleep(0.3)
|
|
176
|
+
node.text.should == 'has been reloaded'
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
it "should reload a node automatically when using find" do
|
|
180
|
+
@session.visit('/with_js')
|
|
181
|
+
node = @session.find(:css, '#reload-me')
|
|
182
|
+
@session.click_link('Reload!')
|
|
183
|
+
sleep(0.3)
|
|
184
|
+
node.find(:css, 'a').text.should == 'has been reloaded'
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
it "should not reload nodes which haven't been found" do
|
|
188
|
+
@session.visit('/with_js')
|
|
189
|
+
node = @session.all(:css, '#the-list li')[1]
|
|
190
|
+
@session.click_link('Fetch new list!')
|
|
191
|
+
sleep(0.3)
|
|
192
|
+
expect { node.text.to == 'Foo' }.to raise_error
|
|
193
|
+
expect { node.text.to == 'Bar' }.to raise_error
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
it "should reload nodes with options" do
|
|
197
|
+
@session.visit('/with_js')
|
|
198
|
+
node = @session.find(:css, 'em', :text => "reloaded")
|
|
199
|
+
@session.click_link('Reload!')
|
|
200
|
+
sleep(1)
|
|
201
|
+
node.text.should == 'has been reloaded'
|
|
202
|
+
end
|
|
203
|
+
end
|
|
114
204
|
end
|
|
115
205
|
end
|