rsel 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Rakefile +22 -8
- data/docs/development.md +1 -0
- data/docs/history.md +11 -1
- data/docs/index.md +1 -0
- data/docs/scoping.md +1 -1
- data/docs/studying.md +76 -0
- data/lib/rsel/selenium_test.rb +505 -90
- data/lib/rsel/study_html.rb +198 -0
- data/lib/rsel/support.rb +105 -4
- data/rsel.gemspec +1 -1
- data/spec/spec_helper.rb +4 -22
- data/spec/st_alerts.rb +48 -0
- data/spec/st_browser_spec.rb +58 -0
- data/spec/st_buttons_spec.rb +95 -0
- data/spec/st_checkboxes_spec.rb +235 -0
- data/spec/st_conditionals_spec.rb +180 -0
- data/spec/st_dropdowns_spec.rb +140 -0
- data/spec/st_field_equals_among_spec.rb +48 -0
- data/spec/st_fields_equal_among_spec.rb +74 -0
- data/spec/st_fields_equal_spec.rb +90 -0
- data/spec/st_fields_spec.rb +167 -0
- data/spec/st_initialization_spec.rb +33 -0
- data/spec/st_links_spec.rb +84 -0
- data/spec/st_method_missing_spec.rb +59 -0
- data/spec/st_navigation_spec.rb +56 -0
- data/spec/st_radiobuttons_spec.rb +123 -0
- data/spec/st_respond_to_spec.rb +16 -0
- data/spec/st_scenario_spec.rb +26 -0
- data/spec/st_set_field_among_spec.rb +45 -0
- data/spec/st_set_field_spec.rb +842 -0
- data/spec/st_set_fields_among_spec.rb +74 -0
- data/spec/st_set_fields_spec.rb +97 -0
- data/spec/st_spec_helper.rb +43 -0
- data/spec/st_stop_on_failure_spec.rb +199 -0
- data/spec/st_tables_spec.rb +42 -0
- data/spec/st_temporal_visibility_spec.rb +122 -0
- data/spec/st_visibility_spec.rb +125 -0
- data/spec/st_waiting_spec.rb +37 -0
- data/spec/study_html_spec.rb +310 -0
- data/spec/support_spec.rb +163 -13
- data/test/server/README.txt +3 -0
- data/test/views/alert.erb +15 -0
- data/test/views/form.erb +6 -1
- data/test/views/index.erb +2 -0
- data/test/views/slowtext.erb +1 -1
- metadata +38 -9
- data/spec/selenium_test_spec.rb +0 -2656
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'spec/st_spec_helper'
|
2
|
+
|
3
|
+
describe 'temporal visibility' do
|
4
|
+
describe "#see_within_seconds" do
|
5
|
+
before(:each) do
|
6
|
+
@st.visit("/slowtext").should be_true
|
7
|
+
end
|
8
|
+
|
9
|
+
context "passes when" do
|
10
|
+
it "text is already present" do
|
11
|
+
@st.see("Late text page").should be_true
|
12
|
+
@st.see_within_seconds("The text is coming...", 10).should be_true
|
13
|
+
end
|
14
|
+
it "text within an id is already present" do
|
15
|
+
@st.see_within_seconds("The text is coming...", 10, :within => 'oldtext').should be_true
|
16
|
+
end
|
17
|
+
it "text appears in time" do
|
18
|
+
@st.see("The text is coming...").should be_true
|
19
|
+
@st.do_not_see("The text is here!").should be_true
|
20
|
+
@st.see_within_seconds("The text is here!", "10").should be_true
|
21
|
+
@st.see("The text is here!").should be_true
|
22
|
+
end
|
23
|
+
it "text appears in an id in time" do
|
24
|
+
@st.see("The text is coming...").should be_true
|
25
|
+
@st.do_not_see("The text is here!").should be_true
|
26
|
+
@st.see_within_seconds("The text is here!", "10", :within => 'newtext').should be_true
|
27
|
+
@st.see("The text is here!").should be_true
|
28
|
+
end
|
29
|
+
it "text appears within default time" do
|
30
|
+
@st.see("The text is coming...").should be_true
|
31
|
+
@st.do_not_see("The text is here!").should be_true
|
32
|
+
@st.see_within_seconds("The text is here!").should be_true
|
33
|
+
@st.see("The text is here!").should be_true
|
34
|
+
end
|
35
|
+
it "text appears within default time in an id" do
|
36
|
+
@st.see("The text is coming...").should be_true
|
37
|
+
@st.do_not_see("The text is here!").should be_true
|
38
|
+
@st.see_within_seconds("The text is here!", :within => 'newtext').should be_true
|
39
|
+
@st.see("The text is here!").should be_true
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "fails when" do
|
44
|
+
it "text appears too late" do
|
45
|
+
@st.see("The text is coming...").should be_true
|
46
|
+
@st.do_not_see("The text is here!").should be_true
|
47
|
+
@st.see_within_seconds("The text is here!", 1).should be_false
|
48
|
+
end
|
49
|
+
it "text appears too late in an id" do
|
50
|
+
# FIXME: This test occasionally fails for no apparent reason
|
51
|
+
# (the text is found within the timeout)
|
52
|
+
@st.see_within_seconds("The text is here!", 1, :within => 'newtext').should be_false
|
53
|
+
end
|
54
|
+
it "text never appears" do
|
55
|
+
@st.see_within_seconds("Nonexistent", 5).should be_false
|
56
|
+
end
|
57
|
+
it "text never appears in the given id" do
|
58
|
+
@st.see_within_seconds("The text is coming...", 5, :within => 'newtext').should be_false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it "is case-sensitive" do
|
63
|
+
@st.see_within_seconds("The text is here!", 5).should be_true
|
64
|
+
@st.see_within_seconds("The text IS HERE!", 5).should be_false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#do_not_see_within_seconds" do
|
69
|
+
before(:each) do
|
70
|
+
@st.visit("/slowtext").should be_true
|
71
|
+
end
|
72
|
+
|
73
|
+
context "passes when" do
|
74
|
+
it "text is already absent" do
|
75
|
+
@st.see("Late text page").should be_true
|
76
|
+
@st.do_not_see_within_seconds("Some absent text", 10).should be_true
|
77
|
+
end
|
78
|
+
it "text is already absent from the given id" do
|
79
|
+
@st.see("Late text page").should be_true
|
80
|
+
@st.do_not_see_within_seconds("The text is coming...", 10, :within => 'newtext').should be_true
|
81
|
+
end
|
82
|
+
it "text disappears in time" do
|
83
|
+
@st.see_within_seconds("The text is here!", 10).should be_true
|
84
|
+
@st.do_not_see_within_seconds("The text is here!", "10").should be_true
|
85
|
+
@st.do_not_see("The text is here!").should be_true
|
86
|
+
end
|
87
|
+
it "text disappears from the given id in time" do
|
88
|
+
@st.see_within_seconds("The text is here!", 10).should be_true
|
89
|
+
@st.do_not_see_within_seconds("The text is here!", "10", :within => 'newtext').should be_true
|
90
|
+
@st.do_not_see("The text is here!").should be_true
|
91
|
+
end
|
92
|
+
it "text disappears within default time" do
|
93
|
+
@st.see_within_seconds("The text is here!", 10).should be_true
|
94
|
+
@st.do_not_see_within_seconds("The text is here!").should be_true
|
95
|
+
@st.do_not_see("The text is here!").should be_true
|
96
|
+
end
|
97
|
+
it "text disappears within default time from the given id" do
|
98
|
+
@st.see_within_seconds("The text is here!", 10).should be_true
|
99
|
+
@st.do_not_see_within_seconds("The text is here!", :within => 'newtext').should be_true
|
100
|
+
@st.do_not_see("The text is here!").should be_true
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context "fails when" do
|
105
|
+
it "text disappears too late" do
|
106
|
+
@st.see_within_seconds("The text is here!", 10).should be_true
|
107
|
+
@st.do_not_see_within_seconds("The text is here!", 1).should be_false
|
108
|
+
end
|
109
|
+
it "text disappears too late from an id" do
|
110
|
+
@st.see_within_seconds("The text is here!", 10).should be_true
|
111
|
+
@st.do_not_see_within_seconds("The text is here!", 1, :within => 'newtext').should be_false
|
112
|
+
end
|
113
|
+
it "text never disappears" do
|
114
|
+
@st.do_not_see_within_seconds("The text is coming...", 5).should be_false
|
115
|
+
end
|
116
|
+
it "text never disappears from an id" do
|
117
|
+
@st.do_not_see_within_seconds("The text is coming...", 3, :within => 'oldtext').should be_false
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'spec/st_spec_helper'
|
2
|
+
|
3
|
+
describe 'visibility' do
|
4
|
+
before(:each) do
|
5
|
+
@st.visit("/").should be_true
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#see" do
|
9
|
+
context "passes when" do
|
10
|
+
it "text is present" do
|
11
|
+
@st.see("Welcome").should be_true
|
12
|
+
@st.see("This is a Sinatra webapp").should be_true
|
13
|
+
end
|
14
|
+
|
15
|
+
it "sees text within an id" do
|
16
|
+
@st.see("About this site", :within => 'header').should be_true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "fails when" do
|
21
|
+
it "text is absent" do
|
22
|
+
@st.errors
|
23
|
+
@st.see("Nonexistent").should be_false
|
24
|
+
@st.see("Some bogus text").should be_false
|
25
|
+
@st.errors.should eq('')
|
26
|
+
end
|
27
|
+
it "text is present, but invisible" do
|
28
|
+
@st.errors
|
29
|
+
@st.see("unseen").should be_false
|
30
|
+
@st.errors.should eq('')
|
31
|
+
end
|
32
|
+
it "text is present, but invisible, using studying" do
|
33
|
+
@st.errors
|
34
|
+
@st.begin_study
|
35
|
+
@st.see("unseen").should be_false
|
36
|
+
@st.end_study
|
37
|
+
@st.errors.should eq('')
|
38
|
+
end
|
39
|
+
it "text is present, but not within the scope" do
|
40
|
+
@st.errors
|
41
|
+
@st.see("This is a Sinatra webapp", :within => 'header').should be_false
|
42
|
+
@st.errors.should eq("'This is a Sinatra webapp' not found in 'About this site'")
|
43
|
+
end
|
44
|
+
it "text is present, within scope, but invisible" do
|
45
|
+
@st.errors
|
46
|
+
@st.see("unseen", :within => 'header').should be_false
|
47
|
+
@st.errors.should eq("'unseen' not found in 'About this site'")
|
48
|
+
end
|
49
|
+
it "text is present, studied within scope, but invisible" do
|
50
|
+
@st.errors
|
51
|
+
@st.begin_study
|
52
|
+
@st.see("unseen", :within => 'header').should be_false
|
53
|
+
@st.end_study
|
54
|
+
@st.errors.should eq("'unseen' not found in 'About this site'")
|
55
|
+
end
|
56
|
+
it "scope is not present" do
|
57
|
+
@st.see("This is a Sinatra webapp", :within => 'bogus_id').should be_false
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it "is case-sensitive" do
|
62
|
+
@st.see("Sinatra webapp").should be_true
|
63
|
+
@st.see("sinatra Webapp").should be_false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#do_not_see" do
|
68
|
+
context "passes when" do
|
69
|
+
it "text is absent" do
|
70
|
+
@st.do_not_see("Nonexistent").should be_true
|
71
|
+
@st.do_not_see("Some bogus text").should be_true
|
72
|
+
end
|
73
|
+
it "text is present, but invisible" do
|
74
|
+
@st.errors
|
75
|
+
@st.do_not_see("unseen").should be_true
|
76
|
+
@st.errors.should eq('')
|
77
|
+
end
|
78
|
+
it "text is present, but invisible, using studying" do
|
79
|
+
@st.errors
|
80
|
+
@st.begin_study
|
81
|
+
@st.do_not_see("unseen").should be_true
|
82
|
+
@st.end_study
|
83
|
+
@st.errors.should eq('')
|
84
|
+
end
|
85
|
+
it "text is present, but not within the scope" do
|
86
|
+
@st.do_not_see("This is a Sinatra webapp", :within => 'header').should be_true
|
87
|
+
end
|
88
|
+
it "text is present, within scope, but invisible" do
|
89
|
+
@st.errors
|
90
|
+
@st.do_not_see("unseen", :within => 'header').should be_true
|
91
|
+
@st.errors.should eq('')
|
92
|
+
end
|
93
|
+
it "text is present, studied within scope, but invisible" do
|
94
|
+
@st.errors
|
95
|
+
@st.begin_study
|
96
|
+
@st.do_not_see("unseen", :within => 'header').should be_true
|
97
|
+
@st.end_study
|
98
|
+
@st.errors.should eq('')
|
99
|
+
end
|
100
|
+
it "scope is not present" do
|
101
|
+
@st.do_not_see("This is a Sinatra webapp", :within => 'bogus_id').should be_true
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "fails when" do
|
106
|
+
it "text is present" do
|
107
|
+
@st.errors
|
108
|
+
@st.do_not_see("Welcome").should be_false
|
109
|
+
@st.do_not_see("This is a Sinatra webapp").should be_false
|
110
|
+
@st.errors.should eq('')
|
111
|
+
end
|
112
|
+
it "sees text within an id" do
|
113
|
+
@st.errors
|
114
|
+
@st.do_not_see("About this site", :within => 'header').should be_false
|
115
|
+
@st.errors.should eq("'About this site' not expected, but found in 'About this site'")
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
it "is case-sensitive" do
|
120
|
+
@st.do_not_see("Sinatra webapp").should be_false
|
121
|
+
@st.do_not_see("sinatra Webapp").should be_true
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec/st_spec_helper'
|
2
|
+
|
3
|
+
describe 'waiting' do
|
4
|
+
before(:each) do
|
5
|
+
@st.visit("/").should be_true
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#page_loads_in_seconds_or_less" do
|
9
|
+
context "passes when" do
|
10
|
+
it "page is already loaded" do
|
11
|
+
@st.click_link("About this site").should be_true
|
12
|
+
sleep 1
|
13
|
+
@st.page_loads_in_seconds_or_less(10).should be_true
|
14
|
+
end
|
15
|
+
it "page loads before the timeout" do
|
16
|
+
@st.click_link("Slow page").should be_true
|
17
|
+
@st.page_loads_in_seconds_or_less(10).should be_true
|
18
|
+
@st.see("This page takes a few seconds to load").should be_true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "fails when" do
|
23
|
+
it "slow page does not load before the timeout" do
|
24
|
+
@st.click_link("Slow page").should be_true
|
25
|
+
@st.page_loads_in_seconds_or_less(1).should be_false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#pause_seconds" do
|
31
|
+
it "returns true" do
|
32
|
+
@st.pause_seconds(0).should == true
|
33
|
+
@st.pause_seconds(1).should == true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,310 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
require 'rsel/support'
|
4
|
+
require 'rsel/study_html'
|
5
|
+
|
6
|
+
describe Rsel::StudyHtml do
|
7
|
+
before(:all) do
|
8
|
+
@study = Rsel::StudyHtml.new
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#initialize" do
|
12
|
+
it "succeeds when reading html" do
|
13
|
+
@study = Rsel::StudyHtml.new(IO.read('test/views/form.erb'))
|
14
|
+
@study.clean?.should be_true
|
15
|
+
@study.keeping_clean?.should be_false
|
16
|
+
@study.get_node('xpath=/html/head/title').inner_text.should eq('Rsel Test Forms')
|
17
|
+
end
|
18
|
+
|
19
|
+
it "fails when reading non-html" do
|
20
|
+
lambda do
|
21
|
+
@study = Rsel::StudyHtml.new(42)
|
22
|
+
end.should raise_error
|
23
|
+
|
24
|
+
@study.clean?.should be_false
|
25
|
+
@study.keeping_clean?.should be_false
|
26
|
+
@study.get_node('xpath=/html/head/title').should eq(nil)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#study" do
|
31
|
+
it "succeeds when reading html" do
|
32
|
+
@study.study(IO.read('test/views/form.erb'), true)
|
33
|
+
@study.clean?.should be_true
|
34
|
+
@study.keeping_clean?.should be_true
|
35
|
+
@study.get_node('xpath=/html/head/title').inner_text.should eq('Rsel Test Forms')
|
36
|
+
end
|
37
|
+
|
38
|
+
it "fails when reading non-html" do
|
39
|
+
lambda do
|
40
|
+
@study.study(42, true)
|
41
|
+
end.should raise_error
|
42
|
+
|
43
|
+
@study.clean?.should be_false
|
44
|
+
@study.keeping_clean?.should be_false
|
45
|
+
@study.get_node('xpath=/html/head/title').should eq(nil)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#dirty" do
|
50
|
+
before(:all) do
|
51
|
+
@study.study(IO.read('test/views/form.erb'))
|
52
|
+
end
|
53
|
+
|
54
|
+
it "dirties a page" do
|
55
|
+
@study.clean?.should be_true
|
56
|
+
@study.dirty
|
57
|
+
@study.clean?.should be_false
|
58
|
+
end
|
59
|
+
end
|
60
|
+
describe "#undo_last_dirty" do
|
61
|
+
before(:all) do
|
62
|
+
@study.study(IO.read('test/views/form.erb'))
|
63
|
+
end
|
64
|
+
|
65
|
+
it "undirties a page dirtied once" do
|
66
|
+
@study.clean?.should be_true
|
67
|
+
@study.dirty
|
68
|
+
@study.clean?.should be_false
|
69
|
+
@study.undo_last_dirty
|
70
|
+
@study.clean?.should be_true
|
71
|
+
end
|
72
|
+
|
73
|
+
it "does not undirty a page dirtied twice" do
|
74
|
+
@study.clean?.should be_true
|
75
|
+
@study.dirty
|
76
|
+
@study.dirty
|
77
|
+
@study.clean?.should be_false
|
78
|
+
@study.undo_last_dirty
|
79
|
+
@study.clean?.should be_false
|
80
|
+
end
|
81
|
+
|
82
|
+
it "does not undirty a page whose load failed" do
|
83
|
+
lambda do
|
84
|
+
@study.study(42)
|
85
|
+
end.should raise_error
|
86
|
+
|
87
|
+
@study.undo_last_dirty
|
88
|
+
@study.clean?.should be_false
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "#undo_all_dirties" do
|
93
|
+
before(:all) do
|
94
|
+
@study.study(IO.read('test/views/form.erb'))
|
95
|
+
end
|
96
|
+
|
97
|
+
it "undirties a page dirtied once" do
|
98
|
+
@study.clean?.should be_true
|
99
|
+
@study.dirty
|
100
|
+
@study.clean?.should be_false
|
101
|
+
@study.undo_all_dirties
|
102
|
+
@study.clean?.should be_true
|
103
|
+
end
|
104
|
+
|
105
|
+
it "undirties a page dirtied twice" do
|
106
|
+
@study.clean?.should be_true
|
107
|
+
@study.dirty
|
108
|
+
@study.dirty
|
109
|
+
@study.clean?.should be_false
|
110
|
+
@study.undo_all_dirties.should be_true
|
111
|
+
@study.clean?.should be_true
|
112
|
+
end
|
113
|
+
|
114
|
+
it "does not undirty a page whose load failed" do
|
115
|
+
lambda do
|
116
|
+
@study.study(42)
|
117
|
+
end.should raise_error
|
118
|
+
|
119
|
+
@study.undo_all_dirties.should be_false
|
120
|
+
@study.clean?.should be_false
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe "#keep_clean" do
|
125
|
+
it "prevents dirty from working when used in study" do
|
126
|
+
@study.study(IO.read('test/views/form.erb'), true)
|
127
|
+
@study.clean?.should be_true
|
128
|
+
@study.dirty
|
129
|
+
@study.clean?.should be_true
|
130
|
+
end
|
131
|
+
it "prevents dirty from working when used after study" do
|
132
|
+
@study.study(IO.read('test/views/form.erb'))
|
133
|
+
@study.clean?.should be_true
|
134
|
+
@study.dirty
|
135
|
+
@study.clean?.should be_false
|
136
|
+
@study.keep_clean(true)
|
137
|
+
@study.clean?.should be_true
|
138
|
+
@study.dirty
|
139
|
+
@study.clean?.should be_true
|
140
|
+
end
|
141
|
+
it "stops working when turned off" do
|
142
|
+
@study.study(IO.read('test/views/form.erb'), true)
|
143
|
+
@study.keeping_clean?.should be_true
|
144
|
+
@study.keep_clean(false)
|
145
|
+
@study.keeping_clean?.should be_false
|
146
|
+
@study.clean?.should be_false
|
147
|
+
@study.undo_all_dirties.should be_true
|
148
|
+
@study.clean?.should be_true
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe "#begin_section" do
|
153
|
+
it "studies a new page" do
|
154
|
+
lambda do
|
155
|
+
@study = Rsel::StudyHtml.new(42)
|
156
|
+
end.should raise_error
|
157
|
+
|
158
|
+
@study.dirty
|
159
|
+
@study.begin_section {IO.read('test/views/form.erb')}
|
160
|
+
@study.get_node('xpath=/html/head/title').inner_text.should eq('Rsel Test Forms')
|
161
|
+
@study.end_section
|
162
|
+
@study.get_node('xpath=/html/head/title').should eq(nil)
|
163
|
+
end
|
164
|
+
it "continues with an old, studied page" do
|
165
|
+
@study.study(IO.read('test/views/form.erb'))
|
166
|
+
@study.begin_section {42}
|
167
|
+
@study.get_node('xpath=/html/head/title').inner_text.should eq('Rsel Test Forms')
|
168
|
+
@study.end_section
|
169
|
+
@study.clean?.should be_false
|
170
|
+
end
|
171
|
+
it "maintains studying after a new section" do
|
172
|
+
@study.study(IO.read('test/views/form.erb'), true)
|
173
|
+
@study.begin_section {42}
|
174
|
+
@study.get_node('xpath=/html/head/title').inner_text.should eq('Rsel Test Forms')
|
175
|
+
@study.end_section
|
176
|
+
@study.clean?.should be_true
|
177
|
+
@study.get_node('xpath=/html/head/title').inner_text.should eq('Rsel Test Forms')
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
describe "#end_section" do
|
182
|
+
it "works like keep_clean(false) if it runs out of stack parameters" do
|
183
|
+
@study.study(IO.read('test/views/form.erb'), true)
|
184
|
+
@study.keeping_clean?.should be_true
|
185
|
+
@study.end_section
|
186
|
+
@study.keeping_clean?.should be_false
|
187
|
+
@study.clean?.should be_false
|
188
|
+
@study.undo_all_dirties.should be_true
|
189
|
+
@study.clean?.should be_true
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
describe "#simplify_locator" do
|
194
|
+
before(:all) do
|
195
|
+
@study.study(IO.read('test/views/form.erb'))
|
196
|
+
end
|
197
|
+
|
198
|
+
context "does not simplify" do
|
199
|
+
it "an id" do
|
200
|
+
@study.simplify_locator('id=first_name').should eq('id=first_name')
|
201
|
+
end
|
202
|
+
it "a name" do
|
203
|
+
@study.simplify_locator('name=second_duplicate').should eq('name=second_duplicate')
|
204
|
+
end
|
205
|
+
it "a link" do
|
206
|
+
@study.simplify_locator('link=second duplicate').should eq('link=second duplicate')
|
207
|
+
end
|
208
|
+
it "a dom path" do
|
209
|
+
@study.simplify_locator('dom=document.links[42]').should eq('dom=document.links[42]')
|
210
|
+
@study.simplify_locator('document.links[42]').should eq('document.links[42]')
|
211
|
+
end
|
212
|
+
it "an element only accessible by xpath or css from css" do
|
213
|
+
@study.simplify_locator('#spouse_form button').should eq('#spouse_form button')
|
214
|
+
end
|
215
|
+
it "an element only accessible by xpath or css from xpath if ordered not to" do
|
216
|
+
@study.simplify_locator('//button[@value=\'submit_spouse_form\']', false).should eq('xpath=//button[@value=\'submit_spouse_form\']')
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
context "simplifies" do
|
221
|
+
it "a control to an id" do
|
222
|
+
my_xpath = @study.loc('First name', 'field')
|
223
|
+
@study.simplify_locator(my_xpath).should eq('id=first_name')
|
224
|
+
end
|
225
|
+
it "a css path to an id" do
|
226
|
+
@study.simplify_locator('css=#first_name').should eq('id=first_name')
|
227
|
+
end
|
228
|
+
it "an xpath to a name" do
|
229
|
+
my_xpath = @study.loc('duplicate', 'field', :within => 'other_form')
|
230
|
+
@study.simplify_locator(my_xpath).should eq('name=second_duplicate')
|
231
|
+
end
|
232
|
+
it "a css path to a name" do
|
233
|
+
@study.simplify_locator('css=#other_form #duplicate').should eq('name=second_duplicate')
|
234
|
+
end
|
235
|
+
it "an xpath to a link" do
|
236
|
+
my_xpath = @study.loc('Home', 'link')
|
237
|
+
@study.simplify_locator(my_xpath).should eq('link=Home')
|
238
|
+
end
|
239
|
+
it "a css path to a link" do
|
240
|
+
@study.simplify_locator('css=a').should eq('link=Home')
|
241
|
+
end
|
242
|
+
it "an element only accessible by xpath or css from an xpath" do
|
243
|
+
my_xpath = @study.loc('Submit spouse form', 'button')
|
244
|
+
@study.simplify_locator(my_xpath).should eq('xpath=/html/body/div[2]/form/p[4]/button')
|
245
|
+
@study.simplify_locator('//button[@value=\'submit_spouse_form\']').should eq('xpath=/html/body/div[2]/form/p[4]/button')
|
246
|
+
end
|
247
|
+
# TODO: Simplify an xpath to a css.
|
248
|
+
end
|
249
|
+
end
|
250
|
+
describe "#get_node" do
|
251
|
+
before(:all) do
|
252
|
+
@study.study(IO.read('test/views/form.erb'), true)
|
253
|
+
end
|
254
|
+
|
255
|
+
context "passes when" do
|
256
|
+
it "finds an id" do
|
257
|
+
@study.get_node('id=person_height').inner_text.should include('Average')
|
258
|
+
end
|
259
|
+
it "finds a name" do
|
260
|
+
@study.get_node('name=underwear briefs')['value'].should eq('briefs')
|
261
|
+
end
|
262
|
+
it "finds a link" do
|
263
|
+
@study.get_node('link=Home')['href'].should eq('/')
|
264
|
+
end
|
265
|
+
it "finds an element by css" do
|
266
|
+
@study.get_node('css=#other_form #duplicate')['name'].should eq('second_duplicate')
|
267
|
+
end
|
268
|
+
it "finds an element by xpath" do
|
269
|
+
my_xpath = @study.loc('duplicate', 'field', :within => 'other_form')
|
270
|
+
@study.get_node(my_xpath)['name'].should eq('second_duplicate')
|
271
|
+
end
|
272
|
+
it "finds an element by implied xpath" do
|
273
|
+
@study.get_node("//*[@name='underwear']")['value'].should eq('boxers')
|
274
|
+
end
|
275
|
+
it "finds an element by default" do
|
276
|
+
@study.get_node("underwear")['value'].should eq('boxers')
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
context "fails when" do
|
281
|
+
it "does not find an id" do
|
282
|
+
@study.get_node('id=impersonated').should eq(nil)
|
283
|
+
end
|
284
|
+
it "does not find a name" do
|
285
|
+
@study.get_node('name=impersonated').should eq(nil)
|
286
|
+
end
|
287
|
+
it "does not find a link" do
|
288
|
+
@study.get_node('link=impersonated').should eq(nil)
|
289
|
+
end
|
290
|
+
it "does not find an element by css" do
|
291
|
+
@study.get_node('css=#impersonated').should eq(nil)
|
292
|
+
end
|
293
|
+
it "does not find an element by xpath" do
|
294
|
+
@study.get_node('xpath=//impersonated').should eq(nil)
|
295
|
+
end
|
296
|
+
it "does not find an element by implied xpath" do
|
297
|
+
@study.get_node('//impersonated').should eq(nil)
|
298
|
+
end
|
299
|
+
it "does not find an element by default" do
|
300
|
+
@study.get_node('impersonated').should eq(nil)
|
301
|
+
end
|
302
|
+
it "is given a dom path" do
|
303
|
+
@study.get_node('dom=document.links[0]').should eq(nil)
|
304
|
+
end
|
305
|
+
it "is given an implied dom path" do
|
306
|
+
@study.get_node('document.links[0]').should eq(nil)
|
307
|
+
end
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|