rsel 0.1.1 → 0.1.2

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.
Files changed (48) hide show
  1. data/.gitignore +1 -0
  2. data/Rakefile +22 -8
  3. data/docs/development.md +1 -0
  4. data/docs/history.md +11 -1
  5. data/docs/index.md +1 -0
  6. data/docs/scoping.md +1 -1
  7. data/docs/studying.md +76 -0
  8. data/lib/rsel/selenium_test.rb +505 -90
  9. data/lib/rsel/study_html.rb +198 -0
  10. data/lib/rsel/support.rb +105 -4
  11. data/rsel.gemspec +1 -1
  12. data/spec/spec_helper.rb +4 -22
  13. data/spec/st_alerts.rb +48 -0
  14. data/spec/st_browser_spec.rb +58 -0
  15. data/spec/st_buttons_spec.rb +95 -0
  16. data/spec/st_checkboxes_spec.rb +235 -0
  17. data/spec/st_conditionals_spec.rb +180 -0
  18. data/spec/st_dropdowns_spec.rb +140 -0
  19. data/spec/st_field_equals_among_spec.rb +48 -0
  20. data/spec/st_fields_equal_among_spec.rb +74 -0
  21. data/spec/st_fields_equal_spec.rb +90 -0
  22. data/spec/st_fields_spec.rb +167 -0
  23. data/spec/st_initialization_spec.rb +33 -0
  24. data/spec/st_links_spec.rb +84 -0
  25. data/spec/st_method_missing_spec.rb +59 -0
  26. data/spec/st_navigation_spec.rb +56 -0
  27. data/spec/st_radiobuttons_spec.rb +123 -0
  28. data/spec/st_respond_to_spec.rb +16 -0
  29. data/spec/st_scenario_spec.rb +26 -0
  30. data/spec/st_set_field_among_spec.rb +45 -0
  31. data/spec/st_set_field_spec.rb +842 -0
  32. data/spec/st_set_fields_among_spec.rb +74 -0
  33. data/spec/st_set_fields_spec.rb +97 -0
  34. data/spec/st_spec_helper.rb +43 -0
  35. data/spec/st_stop_on_failure_spec.rb +199 -0
  36. data/spec/st_tables_spec.rb +42 -0
  37. data/spec/st_temporal_visibility_spec.rb +122 -0
  38. data/spec/st_visibility_spec.rb +125 -0
  39. data/spec/st_waiting_spec.rb +37 -0
  40. data/spec/study_html_spec.rb +310 -0
  41. data/spec/support_spec.rb +163 -13
  42. data/test/server/README.txt +3 -0
  43. data/test/views/alert.erb +15 -0
  44. data/test/views/form.erb +6 -1
  45. data/test/views/index.erb +2 -0
  46. data/test/views/slowtext.erb +1 -1
  47. metadata +38 -9
  48. data/spec/selenium_test_spec.rb +0 -2656
@@ -0,0 +1,33 @@
1
+ require 'spec/st_spec_helper'
2
+
3
+ describe 'initialization' do
4
+ it "sets correct default configuration" do
5
+ st = Rsel::SeleniumTest.new('http://some.host.org:8070/')
6
+ st.url.should == "http://some.host.org:8070/"
7
+ # Defaults
8
+ st.browser.host.should == "localhost"
9
+ st.browser.port.should == 4444
10
+ st.browser.browser_string.should == "*firefox"
11
+ st.browser.default_timeout_in_seconds.should == 300
12
+ st.stop_on_failure.should == false
13
+ st.found_failure.should == false
14
+ end
15
+
16
+ context "stop_on_failure option" do
17
+ it "can be initialized with a string" do
18
+ st = Rsel::SeleniumTest.new('localhost', :stop_on_failure => 'true')
19
+ st.stop_on_failure.should be_true
20
+ st = Rsel::SeleniumTest.new('localhost', :stop_on_failure => 'FALSE')
21
+ st.stop_on_failure.should be_false
22
+ end
23
+
24
+ it "can be initialized with a boolean" do
25
+ st = Rsel::SeleniumTest.new('localhost', :stop_on_failure => true)
26
+ st.stop_on_failure.should be_true
27
+ st = Rsel::SeleniumTest.new('localhost', :stop_on_failure => false)
28
+ st.stop_on_failure.should be_false
29
+ end
30
+ end
31
+
32
+ end
33
+
@@ -0,0 +1,84 @@
1
+ require 'spec/st_spec_helper'
2
+
3
+ describe 'links' do
4
+ before(:each) do
5
+ @st.visit("/").should be_true
6
+ end
7
+
8
+ describe "#click" do
9
+ context "passes when" do
10
+ it "link exists" do
11
+ @st.click("About this site").should be_true
12
+ end
13
+ end
14
+
15
+ context "fails when" do
16
+ it "link does not exist" do
17
+ @st.click("Bogus link").should be_false
18
+ end
19
+ end
20
+ end
21
+
22
+ describe "#click_link" do
23
+ context "passes when" do
24
+ it "link exists" do
25
+ @st.click_link("About this site").should be_true
26
+ end
27
+
28
+ it "link exists within scope" do
29
+ @st.click_link("About this site", :within => "header").should be_true
30
+ end
31
+
32
+ it "link exists in table row" do
33
+ @st.visit("/table")
34
+ @st.click_link("Edit", :in_row => "Marcus").should be_true
35
+ @st.page_loads_in_seconds_or_less(10).should be_true
36
+ @st.see_title("Editing Marcus").should be_true
37
+ end
38
+ end
39
+
40
+ context "fails when" do
41
+ it "link does not exist" do
42
+ @st.click_link("Bogus link").should be_false
43
+ end
44
+
45
+ it "link exists, but not within scope" do
46
+ @st.click_link("About this site", :within => "footer").should be_false
47
+ end
48
+
49
+ it "link exists, but not in table row" do
50
+ @st.visit("/table")
51
+ @st.click_link("Edit", :in_row => "Ken").should be_false
52
+ end
53
+ end
54
+ end
55
+
56
+ describe "#link_exists" do
57
+ context "passes when" do
58
+ it "link with the given text exists" do
59
+ @st.link_exists("About this site").should be_true
60
+ @st.link_exists("Form test").should be_true
61
+ end
62
+
63
+ it "link with the given text exists within scope" do
64
+ @st.link_exists("About this site", :within => "header").should be_true
65
+ @st.link_exists("Form test", :within => "footer").should be_true
66
+ @st.link_exists("Table test", :within => "footer").should be_true
67
+ end
68
+ end
69
+
70
+ context "fails when" do
71
+ it "no such link exists" do
72
+ @st.link_exists("Welcome").should be_false
73
+ @st.link_exists("Don't click here").should be_false
74
+ end
75
+
76
+ it "link exists, but not within scope" do
77
+ @st.link_exists("About this site", :within => "footer").should be_false
78
+ @st.link_exists("Form test", :within => "header").should be_false
79
+ @st.link_exists("Table test", :within => "header").should be_false
80
+ end
81
+ end
82
+ end
83
+
84
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec/st_spec_helper'
2
+
3
+ describe '#method_missing' do
4
+ context "method is defined in Selenium::Client::Driver" do
5
+ before(:each) do
6
+ @st.visit("/form").should be_true
7
+ end
8
+
9
+ context "method returning Boolean" do
10
+ it "passes if method returns true" do
11
+ @st.is_element_present("id=first_name").should be_true
12
+ @st.is_visible("id=first_name").should be_true
13
+ @st.is_text_present("This page has some random forms").should be_true
14
+ end
15
+
16
+ it "fails if method returns false" do
17
+ @st.is_element_present("id=bogus_id").should be_false
18
+ @st.is_visible("id=bogus_id").should be_false
19
+ @st.is_text_present("This text is not there").should be_false
20
+ end
21
+ end
22
+
23
+ context "method returning String" do
24
+ it "returns the string" do
25
+ @st.get_text("id=salami_checkbox").should eq("I like salami")
26
+ end
27
+ end
28
+
29
+ context "method verifying String" do
30
+ it "verifies the right string" do
31
+ @st.check_get_text("id=salami_checkbox", "I like salami").should be_true
32
+ end
33
+ it "does not verify the wrong string" do
34
+ @st.check_get_text("id=salami_checkbox", "I like lima beans").should be_false
35
+ end
36
+ end
37
+
38
+ context "method not returning Boolean or String" do
39
+ it "passes if method doesn't raise an exception" do
40
+ @st.get_title.should be_true
41
+ @st.mouse_over("id=first_name").should be_true
42
+ end
43
+
44
+ it "fails if method raises an exception" do
45
+ @st.double_click("id=bogus_id").should be_false
46
+ @st.mouse_over("id=bogus_id").should be_false
47
+ end
48
+ end
49
+ end # Selenium::Client::Driver
50
+
51
+ context "method is not defined in Selenium::Client::Driver" do
52
+ it "raises an exception" do
53
+ lambda do
54
+ @st.really_undefined_method
55
+ end.should raise_error
56
+ end
57
+ end
58
+ end
59
+
@@ -0,0 +1,56 @@
1
+ require 'spec/st_spec_helper'
2
+
3
+ describe 'navigation' do
4
+ before(:each) do
5
+ @st.visit("/").should be_true
6
+ end
7
+
8
+ describe "#visit" do
9
+ context "passes when" do
10
+ it "page exists" do
11
+ @st.visit("/about").should be_true
12
+ end
13
+ end
14
+
15
+ # FIXME: Selenium server 2.3.0 and 2.4.0 no longer fail
16
+ # when a 404 or 500 error is raised
17
+ #context "fails when" do
18
+ #it "page gets a 404 error" do
19
+ #@st.visit("/404").should be_false
20
+ #end
21
+ #it "page gets a 500 error" do
22
+ #@st.visit("/500").should be_false
23
+ #end
24
+ #end
25
+ end
26
+
27
+ describe "#refresh_page" do
28
+ before(:each) do
29
+ @st.visit("/slowtext").should be_true
30
+ end
31
+
32
+ it "reloads the page" do
33
+ @st.see("The text is coming...").should be_true
34
+ @st.do_not_see("The text is here!").should be_true
35
+ @st.see_within_seconds("The text is here!").should be_true
36
+ @st.refresh_page
37
+ @st.page_loads_in_seconds_or_less(10)
38
+ @st.do_not_see("The text is here!").should be_true
39
+ end
40
+ end
41
+
42
+ describe "#click_back" do
43
+ it "passes and loads the correct URL" do
44
+ @st.visit("/about")
45
+ @st.visit("/")
46
+ @st.click_back.should be_true
47
+ @st.see_title("About this site").should be_true
48
+ end
49
+
50
+ #it "fails when there is no previous page in the history" do
51
+ # TODO: No obvious way to test this, since everything is running in the
52
+ # same session
53
+ #end
54
+ end
55
+
56
+ end
@@ -0,0 +1,123 @@
1
+ require 'spec/st_spec_helper'
2
+
3
+ describe 'radiobuttons' do
4
+ before(:each) do
5
+ @st.visit("/form").should be_true
6
+ end
7
+
8
+ context "#select_radio" do
9
+ context "passes when" do
10
+ context "radiobutton with label" do
11
+ it "exists" do
12
+ @st.select_radio("Briefs").should be_true
13
+ end
14
+
15
+ it "exists within scope" do
16
+ @st.select_radio("Briefs", :within => "clothing").should be_true
17
+ end
18
+
19
+ it "exists in table row" do
20
+ # TODO
21
+ end
22
+ end
23
+ end
24
+
25
+ context "fails when" do
26
+ context "radiobutton with label" do
27
+ it "does not exist" do
28
+ @st.select_radio("Naked").should be_false
29
+ end
30
+
31
+ it "exists, but not within scope" do
32
+ @st.select_radio("Briefs", :within => "food").should be_false
33
+ end
34
+
35
+ it "exists, but is read-only" do
36
+ @st.visit("/readonly_form").should be_true
37
+ @st.select_radio("Boxers").should be_false
38
+ end
39
+
40
+ it "exists, but not in table row" do
41
+ # TODO
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ describe "#radio_is_enabled" do
48
+ context "passes when" do
49
+ context "radiobutton with label" do
50
+ it "exists, and is enabled" do
51
+ @st.select_radio("Briefs")
52
+ @st.radio_is_enabled("Briefs").should be_true
53
+ end
54
+
55
+ it "exists within scope, and is enabled" do
56
+ @st.select_radio("Briefs", :within => "clothing")
57
+ @st.radio_is_enabled("Briefs", :within => "clothing").should be_true
58
+ end
59
+
60
+ it "exists in table row, and is enabled" do
61
+ # TODO
62
+ end
63
+ end
64
+ end
65
+
66
+ context "fails when" do
67
+ context "radiobutton with label" do
68
+ it "does not exist" do
69
+ @st.radio_is_enabled("Naked").should be_false
70
+ end
71
+
72
+ it "exists, but is not enabled" do
73
+ @st.select_radio("Briefs")
74
+ @st.radio_is_enabled("Boxers").should be_false
75
+ end
76
+
77
+ it "exists and is enabled, but not within scope" do
78
+ @st.select_radio("Briefs", :within => "clothing")
79
+ @st.radio_is_enabled("Briefs", :within => "food").should be_false
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ describe "#radio_is_disabled" do
86
+ context "passes when" do
87
+ context "radiobutton with label" do
88
+ it "exists, and is disabled" do
89
+ @st.select_radio("Briefs")
90
+ @st.radio_is_disabled("Boxers").should be_true
91
+ end
92
+
93
+ it "exists within scope, and is disabled" do
94
+ @st.select_radio("Briefs", :within => "clothing")
95
+ @st.radio_is_disabled("Boxers", :within => "clothing").should be_true
96
+ end
97
+
98
+ it "exists in table row, and is disabled" do
99
+ # TODO
100
+ end
101
+ end
102
+ end
103
+
104
+ context "fails when" do
105
+ context "radiobutton with label" do
106
+ it "does not exist" do
107
+ @st.radio_is_disabled("Naked").should be_false
108
+ end
109
+
110
+ it "exists, but is enabled" do
111
+ @st.select_radio("Briefs")
112
+ @st.radio_is_disabled("Briefs").should be_false
113
+ end
114
+
115
+ it "exists and is disabled, but not within scope" do
116
+ @st.select_radio("Briefs", :within => "clothing")
117
+ @st.radio_is_disabled("Briefs", :within => "food").should be_false
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
123
+
@@ -0,0 +1,16 @@
1
+ require 'spec/st_spec_helper'
2
+
3
+ describe 'respond_to?' do
4
+ it "returns true if a method is explicitly defined" do
5
+ @st.respond_to?('see').should == true
6
+ end
7
+
8
+ it "returns true if the Selenium::Client::Driver defines the method" do
9
+ @st.respond_to?('is_element_present').should == true
10
+ end
11
+
12
+ it "returns false if the method isn't defined" do
13
+ @st.respond_to?('junk').should == false
14
+ end
15
+ end
16
+
@@ -0,0 +1,26 @@
1
+ require 'spec/st_spec_helper'
2
+
3
+ describe 'scenarios' do
4
+ before(:each) do
5
+ @st.visit('/').should be_true
6
+ end
7
+
8
+ describe "#begin_scenario" do
9
+ it "returns true" do
10
+ @st.begin_scenario.should be_true
11
+ end
12
+
13
+ it "sets found_failure to false" do
14
+ @st.found_failure = true
15
+ @st.begin_scenario
16
+ @st.found_failure.should be_false
17
+ end
18
+ end
19
+
20
+ describe "#end_scenario" do
21
+ it "returns true" do
22
+ @st.end_scenario.should be_true
23
+ end
24
+ end
25
+ end
26
+
@@ -0,0 +1,45 @@
1
+ require 'spec/st_spec_helper'
2
+
3
+ # TODO: Add test cases with scopes to the next three functions described.
4
+ describe "#set_field_among" do
5
+ before(:each) do
6
+ @st.visit("/form").should be_true
7
+ end
8
+
9
+ context "passes when" do
10
+ context "text field with label" do
11
+ it "equals the page text" do
12
+ @st.set_field_among("First name", "Marcus", "Last name" => "nowhere").should be_true
13
+ @st.field_contains("First name", "Marcus").should be_true
14
+ end
15
+
16
+ it "equals the page text and has no ids" do
17
+ @st.set_field_among("First name", "Marcus", "").should be_true
18
+ @st.field_contains("First name", "Marcus").should be_true
19
+ end
20
+
21
+ it "equals the hash text" do
22
+ @st.set_field_among("Last name", "Marcus", "Last name" => "First name").should be_true
23
+ @st.field_contains("First name", "Marcus").should be_true
24
+ end
25
+
26
+ it "equals the escaped hash text" do
27
+ @st.set_field_among("Last:name", "Marcus", "Last\\;name" => "First name").should be_true
28
+ @st.field_contains("First name", "Marcus").should be_true
29
+ end
30
+ end
31
+ end
32
+
33
+ context "fails when" do
34
+ context "text field with label" do
35
+ it "does not exist" do
36
+ @st.set_field_among("Third name", "Smith").should be_false
37
+ end
38
+
39
+ it "has a hash value that does not exist" do
40
+ @st.set_field_among("Last name", "Smith", "Last name" => "Third name").should be_false
41
+ end
42
+ end
43
+ end
44
+ end # set_field_among
45
+