celerity 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. data/History.txt +33 -0
  2. data/README.txt +19 -9
  3. data/Rakefile +9 -3
  4. data/lib/celerity.rb +39 -39
  5. data/lib/celerity/browser.rb +538 -153
  6. data/lib/celerity/clickable_element.rb +48 -7
  7. data/lib/celerity/collections.rb +155 -131
  8. data/lib/celerity/container.rb +766 -385
  9. data/lib/celerity/default_viewer.rb +10 -0
  10. data/lib/celerity/disabled_element.rb +19 -2
  11. data/lib/celerity/element.rb +152 -83
  12. data/lib/celerity/element_collection.rb +106 -0
  13. data/lib/celerity/element_locator.rb +89 -66
  14. data/lib/celerity/elements/button.rb +23 -13
  15. data/lib/celerity/elements/file_field.rb +17 -5
  16. data/lib/celerity/elements/form.rb +21 -16
  17. data/lib/celerity/elements/frame.rb +75 -53
  18. data/lib/celerity/elements/image.rb +76 -63
  19. data/lib/celerity/elements/label.rb +4 -2
  20. data/lib/celerity/elements/link.rb +30 -18
  21. data/lib/celerity/elements/meta.rb +6 -0
  22. data/lib/celerity/{non_control_elements.rb → elements/non_control_elements.rb} +106 -76
  23. data/lib/celerity/elements/option.rb +16 -2
  24. data/lib/celerity/elements/radio_check.rb +55 -20
  25. data/lib/celerity/elements/select_list.rb +65 -29
  26. data/lib/celerity/elements/table.rb +141 -94
  27. data/lib/celerity/elements/table_cell.rb +13 -6
  28. data/lib/celerity/elements/{table_body.rb → table_elements.rb} +20 -8
  29. data/lib/celerity/elements/table_row.rb +23 -7
  30. data/lib/celerity/elements/text_field.rb +89 -33
  31. data/lib/celerity/exception.rb +77 -41
  32. data/lib/celerity/extra/method_generator.rb +42 -24
  33. data/lib/celerity/htmlunit.rb +49 -0
  34. data/lib/celerity/htmlunit/commons-collections-3.2.1.jar +0 -0
  35. data/lib/celerity/htmlunit/htmlunit-2.5-SNAPSHOT.jar +0 -0
  36. data/lib/celerity/htmlunit/htmlunit-core-js-2.5-SNAPSHOT.jar +0 -0
  37. data/lib/celerity/htmlunit/nekohtml-1.9.12-20090308.130127-11.jar +0 -0
  38. data/lib/celerity/htmlunit/serializer-2.7.1.jar +0 -0
  39. data/lib/celerity/htmlunit/xalan-2.7.1.jar +0 -0
  40. data/lib/celerity/htmlunit/xml-apis-1.3.04.jar +0 -0
  41. data/lib/celerity/identifier.rb +3 -2
  42. data/lib/celerity/input_element.rb +5 -5
  43. data/lib/celerity/listener.rb +135 -0
  44. data/lib/celerity/resources/no_viewer.png +0 -0
  45. data/lib/celerity/util.rb +88 -0
  46. data/lib/celerity/version.rb +4 -3
  47. data/lib/celerity/watir_compatibility.rb +35 -25
  48. data/tasks/jar.rake +57 -0
  49. metadata +35 -142
  50. data.tar.gz.sig +0 -0
  51. data/Manifest.txt +0 -150
  52. data/lib/celerity/element_collections.rb +0 -54
  53. data/lib/celerity/element_map.rb +0 -51
  54. data/lib/celerity/elements/table_footer.rb +0 -30
  55. data/lib/celerity/elements/table_header.rb +0 -30
  56. data/lib/celerity/htmlunit/commons-collections-3.2.jar +0 -0
  57. data/lib/celerity/htmlunit/download.sh +0 -23
  58. data/lib/celerity/htmlunit/htmlunit-2.2.jar +0 -0
  59. data/lib/celerity/htmlunit/htmlunit-core-js-2.2.jar +0 -0
  60. data/lib/celerity/htmlunit/nekohtml-1.9.8.jar +0 -0
  61. data/lib/celerity/htmlunit/xalan-2.7.0.jar +0 -0
  62. data/lib/celerity/htmlunit/xml-apis-1.0.b2.jar +0 -0
  63. data/spec/area_spec.rb +0 -97
  64. data/spec/areas_spec.rb +0 -40
  65. data/spec/browser_spec.rb +0 -266
  66. data/spec/button_spec.rb +0 -227
  67. data/spec/buttons_spec.rb +0 -39
  68. data/spec/checkbox_spec.rb +0 -302
  69. data/spec/checkboxes_spec.rb +0 -38
  70. data/spec/div_spec.rb +0 -207
  71. data/spec/divs_spec.rb +0 -39
  72. data/spec/element_spec.rb +0 -79
  73. data/spec/filefield_spec.rb +0 -123
  74. data/spec/filefields_spec.rb +0 -40
  75. data/spec/form_spec.rb +0 -59
  76. data/spec/forms_spec.rb +0 -41
  77. data/spec/frame_spec.rb +0 -121
  78. data/spec/frames_spec.rb +0 -71
  79. data/spec/hidden_spec.rb +0 -127
  80. data/spec/hiddens_spec.rb +0 -39
  81. data/spec/hn_spec.rb +0 -104
  82. data/spec/hns_spec.rb +0 -45
  83. data/spec/html/2000_spans.html +0 -2009
  84. data/spec/html/bug_duplicate_attributes.html +0 -14
  85. data/spec/html/bug_javascript_001.html +0 -11
  86. data/spec/html/form_js_bug.html +0 -11
  87. data/spec/html/forms_with_input_elements.html +0 -114
  88. data/spec/html/frame_1.html +0 -17
  89. data/spec/html/frame_2.html +0 -16
  90. data/spec/html/frames.html +0 -11
  91. data/spec/html/iframes.html +0 -12
  92. data/spec/html/images.html +0 -27
  93. data/spec/html/images/1.gif +0 -0
  94. data/spec/html/images/2.gif +0 -0
  95. data/spec/html/images/3.gif +0 -0
  96. data/spec/html/images/button.jpg +0 -0
  97. data/spec/html/images/circle.jpg +0 -0
  98. data/spec/html/images/map.gif +0 -0
  99. data/spec/html/images/map2.gif +0 -0
  100. data/spec/html/images/minus.gif +0 -0
  101. data/spec/html/images/originaltriangle.jpg +0 -0
  102. data/spec/html/images/plus.gif +0 -0
  103. data/spec/html/images/square.jpg +0 -0
  104. data/spec/html/images/triangle.jpg +0 -0
  105. data/spec/html/invalid_js.html +0 -11
  106. data/spec/html/latin1_text.html +0 -17
  107. data/spec/html/non_control_elements.html +0 -115
  108. data/spec/html/simple_ajax.html +0 -22
  109. data/spec/html/tables.html +0 -119
  110. data/spec/html/utf8_text.html +0 -15
  111. data/spec/htmlunit_spec.rb +0 -26
  112. data/spec/image_spec.rb +0 -220
  113. data/spec/images_spec.rb +0 -39
  114. data/spec/label_spec.rb +0 -79
  115. data/spec/labels_spec.rb +0 -40
  116. data/spec/li_spec.rb +0 -139
  117. data/spec/link_spec.rb +0 -189
  118. data/spec/links_spec.rb +0 -43
  119. data/spec/lis_spec.rb +0 -40
  120. data/spec/map_spec.rb +0 -102
  121. data/spec/maps_spec.rb +0 -40
  122. data/spec/meta_spec.rb +0 -8
  123. data/spec/ol_spec.rb +0 -87
  124. data/spec/ols_spec.rb +0 -40
  125. data/spec/option_spec.rb +0 -154
  126. data/spec/p_spec.rb +0 -171
  127. data/spec/pre_spec.rb +0 -135
  128. data/spec/pres_spec.rb +0 -40
  129. data/spec/ps_spec.rb +0 -40
  130. data/spec/radio_spec.rb +0 -299
  131. data/spec/radios_spec.rb +0 -42
  132. data/spec/select_list_spec.rb +0 -299
  133. data/spec/select_lists_spec.rb +0 -47
  134. data/spec/span_spec.rb +0 -184
  135. data/spec/spans_spec.rb +0 -64
  136. data/spec/spec.opts +0 -1
  137. data/spec/spec_helper.rb +0 -55
  138. data/spec/table_bodies_spec.rb +0 -57
  139. data/spec/table_body_spec.rb +0 -111
  140. data/spec/table_cell_spec.rb +0 -74
  141. data/spec/table_cells_spec.rb +0 -59
  142. data/spec/table_footer_spec.rb +0 -101
  143. data/spec/table_footers_spec.rb +0 -55
  144. data/spec/table_header_spec.rb +0 -101
  145. data/spec/table_headers_spec.rb +0 -55
  146. data/spec/table_row_spec.rb +0 -104
  147. data/spec/table_rows_spec.rb +0 -58
  148. data/spec/table_spec.rb +0 -160
  149. data/spec/tables_spec.rb +0 -42
  150. data/spec/text_field_spec.rb +0 -323
  151. data/spec/text_fields_spec.rb +0 -44
  152. data/spec/ul_spec.rb +0 -88
  153. data/spec/uls_spec.rb +0 -40
  154. data/spec/watir_compatibility_spec.rb +0 -260
  155. data/support/spec_server.rb +0 -73
  156. data/tasks/rspec.rake +0 -30
  157. data/tasks/specserver.rake +0 -21
  158. metadata.gz.sig +0 -0
@@ -1,54 +0,0 @@
1
- module Celerity
2
- # This class is the superclass for the iterator classes (Buttons, Links, Spans etc.)
3
- # It would normally only be accessed by the iterator methods (Browser#spans, Browser#links, ...).
4
- class ElementCollections
5
- include Enumerable
6
-
7
- # @api internal
8
- def initialize(container, how = nil, what = nil)
9
- @container = container
10
- @object = (how == :object ? what : nil)
11
- @length = length
12
- end
13
-
14
- # @return [Fixnum] The number of elements in this collection.
15
- def length
16
- if @object
17
- @object.length
18
- else
19
- @elements ||= ElementLocator.new(@container.object, element_class).elements_by_idents
20
- @elements.size
21
- end
22
- end
23
- alias_method :size, :length
24
-
25
- # @yield [element] Iterate through the elements in this collection.
26
- def each
27
- if @elements
28
- @elements.each { |e| yield(element_class.new(@container, :object, e)) }
29
- @length
30
- else
31
- 0.upto(@length - 1) { |i| yield iterator_object(i) }
32
- end
33
- end
34
-
35
- # Get the element at the given index.
36
- # NB! This is 1-indexed to keep compatibility with Watir. Subject to change.
37
- #
38
- # @return [Celerity::Element]
39
- def [](n)
40
- @elements ? element_class.new(@container, :object, @elements[n-1]) : iterator_object(n-1)
41
- end
42
-
43
- def to_s
44
- map { |e| e.to_s }.join("\n")
45
- end
46
-
47
- private
48
-
49
- def iterator_object(i)
50
- element_class.new(@container, :index, i+1)
51
- end
52
-
53
- end # ElementCollections
54
- end # Celerity
@@ -1,51 +0,0 @@
1
- module Celerity
2
- module ElementMap
3
- # Some HtmlUnit classes are missing equivalents in Celerity. Shouldn't be too hard to fix.
4
- # This is mostly used to implement Element#parent easily.
5
- HtmlUnit2CelerityElement = {
6
- HtmlUnit::Html::HtmlAnchor => Celerity::Link,
7
- HtmlUnit::Html::HtmlArea => Celerity::Area,
8
- HtmlUnit::Html::HtmlButton => Celerity::Button,
9
- HtmlUnit::Html::HtmlButtonInput => Celerity::Button,
10
- HtmlUnit::Html::HtmlCaption => Celerity::Button, # ?
11
- HtmlUnit::Html::HtmlCheckBoxInput => Celerity::CheckBox,
12
- HtmlUnit::Html::HtmlDivision => Celerity::Div,
13
- HtmlUnit::Html::HtmlFileInput => Celerity::FileField,
14
- HtmlUnit::Html::HtmlForm => Celerity::Form,
15
- HtmlUnit::Html::HtmlFrame => Celerity::Frame,
16
- HtmlUnit::Html::HtmlHeading1 => Celerity::H1,
17
- HtmlUnit::Html::HtmlHeading2 => Celerity::H2,
18
- HtmlUnit::Html::HtmlHeading3 => Celerity::H3,
19
- HtmlUnit::Html::HtmlHeading4 => Celerity::H4,
20
- HtmlUnit::Html::HtmlHeading5 => Celerity::H5,
21
- HtmlUnit::Html::HtmlHeading6 => Celerity::H6,
22
- HtmlUnit::Html::HtmlHiddenInput => Celerity::Hidden,
23
- HtmlUnit::Html::HtmlImage => Celerity::Image,
24
- HtmlUnit::Html::HtmlLabel => Celerity::Label,
25
- HtmlUnit::Html::HtmlLink => Celerity::Link,
26
- HtmlUnit::Html::HtmlListItem => Celerity::Li,
27
- HtmlUnit::Html::HtmlMap => Celerity::Map,
28
- HtmlUnit::Html::HtmlOption => Celerity::Option,
29
- HtmlUnit::Html::HtmlOrderedList => Celerity::Ol,
30
- HtmlUnit::Html::HtmlParagraph => Celerity::P,
31
- HtmlUnit::Html::HtmlPasswordInput => Celerity::TextField,
32
- HtmlUnit::Html::HtmlPreformattedText => Celerity::Pre,
33
- HtmlUnit::Html::HtmlRadioButtonInput => Celerity::Radio,
34
- HtmlUnit::Html::HtmlSelect => Celerity::SelectList,
35
- HtmlUnit::Html::HtmlSpan => Celerity::Span,
36
- HtmlUnit::Html::HtmlTable => Celerity::Table,
37
- HtmlUnit::Html::HtmlTableBody => Celerity::TableBody,
38
- HtmlUnit::Html::HtmlTableCell => Celerity::TableCell,
39
- HtmlUnit::Html::HtmlTableFooter => Celerity::TableFooter,
40
- HtmlUnit::Html::HtmlTableHeader => Celerity::TableHeader,
41
- HtmlUnit::Html::HtmlTableRow => Celerity::TableRow,
42
- HtmlUnit::Html::HtmlTextArea => Celerity::Area,
43
- HtmlUnit::Html::HtmlTextInput => Celerity::TextField,
44
- HtmlUnit::Html::HtmlUnorderedList => Celerity::Ul
45
- }
46
- end
47
- end
48
-
49
- class Celerity::Element
50
- include Celerity::ElementMap
51
- end
@@ -1,30 +0,0 @@
1
- module Celerity
2
- class TableFooter < Element
3
- include Enumerable # specs for this?
4
-
5
- TAGS = [ Identifier.new('tfoot') ]
6
- ATTRIBUTES = BASE_ATTRIBUTES | CELLHALIGN_ATTRIBUTES | CELLVALIGN_ATTRIBUTES
7
- DEFAULT_HOW = :id
8
-
9
- def locate
10
- super
11
- @rows = @object.getRows if @object
12
- end
13
-
14
- def [](index)
15
- assert_exists
16
- TableRow.new(self, :object, @rows[index-1])
17
- end
18
-
19
- def length
20
- assert_exists
21
- @object.getRows.length
22
- end
23
-
24
- def each
25
- assert_exists
26
- @rows.each { |row| yield TableRow.new(self, :object, row) }
27
- end
28
-
29
- end
30
- end
@@ -1,30 +0,0 @@
1
- module Celerity
2
- class TableHeader < Element
3
- include Enumerable # specs for this?
4
-
5
- TAGS = [ Identifier.new('thead') ]
6
- ATTRIBUTES = BASE_ATTRIBUTES | CELLHALIGN_ATTRIBUTES | CELLVALIGN_ATTRIBUTES
7
- DEFAULT_HOW = :id
8
-
9
- def locate
10
- super
11
- @rows = @object.getRows if @object
12
- end
13
-
14
- def [](index)
15
- assert_exists
16
- TableRow.new(self, :object, @rows[index-1])
17
- end
18
-
19
- def length
20
- assert_exists
21
- @object.getRows.length
22
- end
23
-
24
- def each
25
- assert_exists
26
- @rows.each { |row| yield TableRow.new(self, :object, row) }
27
- end
28
-
29
- end
30
- end
@@ -1,23 +0,0 @@
1
- wget http://mirrors.sunsite.dk/maven2/commons-codec/commons-codec/1.3/commons-codec-1.3.jar
2
- wget http://mirrors.sunsite.dk/maven2/commons-collections/commons-collections/3.2/commons-collections-3.2.jar
3
- # wget http://mirrors.sunsite.dk/maven2/commons-fileupload/commons-fileupload/1.2.1/commons-fileupload-1.2.1.jar
4
- wget http://mirrors.sunsite.dk/maven2/commons-httpclient/commons-httpclient/3.1/commons-httpclient-3.1.jar
5
- wget http://mirrors.sunsite.dk/maven2/commons-io/commons-io/1.4/commons-io-1.4.jar
6
- wget http://mirrors.sunsite.dk/maven2/commons-lang/commons-lang/2.4/commons-lang-2.4.jar
7
- wget http://mirrors.sunsite.dk/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar
8
- wget http://mirrors.sunsite.dk/maven2/net/sourceforge/cssparser/cssparser/0.9.5/cssparser-0.9.5.jar
9
- # wget http://mirrors.sunsite.dk/maven2/gsbase/gsbase/2.0.1/gsbase-2.0.1.jar
10
- wget http://mirrors.sunsite.dk/maven2/net/sourceforge/htmlunit/htmlunit-core-js/0.1-SNAPSHOT/htmlunit-core-js-0.1-SNAPSHOT.jar
11
- # wget http://mirrors.sunsite.dk/maven2/org/mortbay/jetty/jetty/6.1.9/jetty-6.1.9.jar
12
- # wget http://mirrors.sunsite.dk/maven2/org/mortbay/jetty/jetty-util/6.1.9/jetty-util-6.1.9.jar
13
- # wget http://mirrors.sunsite.dk/maven2/junit/junit/4.4/junit-4.4.jar
14
- # wget http://mirrors.sunsite.dk/maven2/junitperf/junitperf/1.8/junitperf-1.8.jar
15
- # wget http://mirrors.sunsite.dk/maven2/log4j/log4j/1.2.14/log4j-1.2.14.jar
16
- wget http://mirrors.sunsite.dk/maven2/net/sourceforge/nekohtml/nekohtml/1.9.8-SNAPSHOT/nekohtml-1.9.8-SNAPSHOT.jar
17
- wget http://mirrors.sunsite.dk/maven2/org/w3c/css/sac/1.3/sac-1.3.jar
18
- # wget http://mirrors.sunsite.dk/maven2/org/mortbay/jetty/servlet-api-2.5/6.1.9/servlet-api-2.5-6.1.9.jar
19
- # wget http://mirrors.sunsite.dk/maven2/org/slf4j/slf4j-api/1.4.3/slf4j-api-1.4.3.jar
20
- # wget http://mirrors.sunsite.dk/maven2/org/slf4j/slf4j-log4j12/1.4.3/slf4j-log4j12-1.4.3.jar
21
- wget http://mirrors.sunsite.dk/maven2/xalan/xalan/2.7.0/xalan-2.7.0.jar
22
- wget http://mirrors.sunsite.dk/maven2/xerces/xercesImpl/2.8.1/xercesImpl-2.8.1.jar
23
- wget http://mirrors.sunsite.dk/maven2/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar
Binary file
Binary file
data/spec/area_spec.rb DELETED
@@ -1,97 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
2
-
3
- describe "Area" do
4
-
5
- before :all do
6
- @browser = Browser.new
7
- end
8
-
9
- before :each do
10
- @browser.goto(TEST_HOST + "/images.html")
11
- end
12
-
13
- # Exists method
14
- describe "#exist?" do
15
- it "should return true if the area exists" do
16
- @browser.area(:id, "NCE").should exist
17
- @browser.area(:id, /NCE/).should exist
18
- @browser.area(:name, "NCE").should exist
19
- @browser.area(:name, /NCE/).should exist
20
- @browser.area(:title, "Tables").should exist
21
- @browser.area(:title, /Tables/).should exist
22
- @browser.area(:url, "tables.html").should exist
23
- @browser.area(:url, /tables/).should exist
24
- @browser.area(:index, 1).should exist
25
- @browser.area(:xpath, "//area[@id='NCE']").should exist
26
- end
27
-
28
- it "should return true if the element exists (default how = :id)" do
29
- @browser.area("NCE").should exist
30
- end
31
-
32
- it "should return false if the area doesn't exist" do
33
- @browser.area(:id, "no_such_id").should_not exist
34
- @browser.area(:id, /no_such_id/).should_not exist
35
- @browser.area(:name, "no_such_id").should_not exist
36
- @browser.area(:name, /no_such_id/).should_not exist
37
- @browser.area(:title, "no_such_title").should_not exist
38
- @browser.area(:title, /no_such_title/).should_not exist
39
- @browser.area(:url, "no_such_href").should_not exist
40
- @browser.area(:url, /no_such_href/).should_not exist
41
- @browser.area(:index, 1337).should_not exist
42
- @browser.area(:xpath, "//area[@id='no_such_id']").should_not exist
43
- end
44
-
45
- it "should raise ArgumentError when 'what' argument is invalid" do
46
- lambda { @browser.area(:id, 3.14).exists? }.should raise_error(ArgumentError)
47
- end
48
-
49
- it "should raise MissingWayOfFindingObjectException when 'how' argument is invalid" do
50
- lambda { @browser.area(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
51
- end
52
- end
53
-
54
- # Attribute methods
55
- describe "#id" do
56
- it "should return the id attribute" do
57
- @browser.area(:index, 1).id.should == "NCE"
58
- end
59
-
60
- it "should return an empty string if the element exists and the attribute doesn't" do
61
- @browser.area(:index, 3).id.should == ''
62
- end
63
-
64
- it "should raise UnknownObjectException if the area doesn't exist" do
65
- lambda { @browser.area(:id, "no_such_id").id }.should raise_error(UnknownObjectException)
66
- lambda { @browser.area(:index, 1337).id }.should raise_error(UnknownObjectException)
67
- end
68
-
69
- end
70
-
71
- describe "#name" do
72
- it "should return the name attribute" do
73
- @browser.area(:index, 1).name.should == "NCE"
74
- end
75
-
76
- it "should return an empty string if the element exists and the attribute doesn't" do
77
- @browser.area(:index, 3).name.should == ''
78
- end
79
-
80
- it "should raise UnknownObjectException if the area doesn't exist" do
81
- lambda { @browser.area(:id, "no_such_id").name }.should raise_error(UnknownObjectException)
82
- lambda { @browser.area(:index, 1337).name }.should raise_error(UnknownObjectException)
83
- end
84
- end
85
-
86
- describe "#respond_to?" do
87
- it "should return true for all attribute methods" do
88
- @browser.area(:index, 1).should respond_to(:id)
89
- @browser.area(:index, 1).should respond_to(:name)
90
- end
91
- end
92
-
93
- after :all do
94
- @browser.close
95
- end
96
-
97
- end
data/spec/areas_spec.rb DELETED
@@ -1,40 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
2
-
3
- describe "Areas" do
4
-
5
- before :all do
6
- @browser = Browser.new
7
- end
8
-
9
- before :each do
10
- @browser.goto(TEST_HOST + "/images.html")
11
- end
12
-
13
- describe "#length" do
14
- it "should return the number of areas" do
15
- @browser.areas.length.should == 3
16
- end
17
- end
18
-
19
- describe "#[]" do
20
- it "should return the area at the given index" do
21
- @browser.areas[1].id.should == "NCE"
22
- end
23
- end
24
-
25
- describe "#each" do
26
- it "should iterate through areas correctly" do
27
- @browser.areas.each_with_index do |a, index|
28
- a.name.should == @browser.area(:index, index+1).name
29
- a.id.should == @browser.area(:index, index+1).id
30
- a.value.should == @browser.area(:index, index+1).value
31
- end
32
- end
33
- end
34
-
35
- after :all do
36
- @browser.close
37
- end
38
-
39
- end
40
-
data/spec/browser_spec.rb DELETED
@@ -1,266 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
2
-
3
- describe "Browser" do
4
-
5
- before :all do
6
- @browser = Browser.new
7
- end
8
-
9
- # Exists
10
- describe "#exists?" do
11
- it "should return true if we are at a page" do
12
- @browser.should_not exist
13
- @browser.goto(TEST_HOST + "/non_control_elements.html")
14
- @browser.should exist
15
- end
16
-
17
- it "should return false after IE#close" do
18
- @browser.close
19
- @browser.should_not exist
20
- end
21
- end
22
-
23
- describe "#html" do
24
- it "should return the html of the page" do
25
- @browser.goto(TEST_HOST + "/non_control_elements.html")
26
- @browser.html.should == File.read(File.dirname(__FILE__) + "/html/non_control_elements.html")
27
- end
28
- end
29
-
30
- describe "#title" do
31
- it "should return the current page title" do
32
- @browser.goto(TEST_HOST + "/non_control_elements.html")
33
- @browser.title.should == "Non-control elements"
34
- end
35
- end
36
-
37
- describe "#text" do
38
- it "should return the text of the page" do
39
- @browser.goto(TEST_HOST + "/non_control_elements.html")
40
- @browser.text.should include("Dubito, ergo cogito, ergo sum.")
41
- end
42
-
43
- it "should return the text also if the content-type is text/plain" do
44
- # more specs for text/plain? what happens if we call other methods?
45
- @browser.goto(TEST_HOST + "/plain_text")
46
- @browser.text.strip.should == 'This is text/plain'
47
- end
48
-
49
- it "should return a text representation including newlines" do
50
- @browser.goto(TEST_HOST + "/forms_with_input_elements.html")
51
- @browser.text.should == <<-TEXT
52
- Forms with input elementsUser administration
53
-
54
- Add user
55
-
56
- Personal informationFirst name
57
-
58
- Last name
59
-
60
- Email address
61
-
62
- Country Denmark Norway Sweden United Kingdom USA
63
-
64
- Occupation
65
-
66
- Species
67
-
68
- Personal code
69
-
70
- Languages Danish English Norwegian Swedish
71
-
72
- Portrait
73
-
74
- Dental records Login informationUsername (max 20 characters) 0
75
-
76
- Password
77
-
78
- Role Administrator Moderator Regular user Interests Books Bowling Cars Dancing Dentistry Food Preferences
79
-
80
- Do you want to recieve our newslettter?
81
-
82
- Yes No Certainly Absolutely Nah Actions Button 2
83
-
84
- Delete user
85
-
86
- Username Username 1 Username 2 Username 3
87
-
88
- Comment Default comment.
89
- TEXT
90
- end
91
- end
92
-
93
- describe "#url" do
94
- it "should return the current url" do
95
- @browser.goto(TEST_HOST + "/non_control_elements.html")
96
- @browser.url.should == TEST_HOST + "/non_control_elements.html"
97
- end
98
- end
99
-
100
- describe "#document" do
101
- it "should return the underlying object" do
102
- @browser.goto(TEST_HOST + "/non_control_elements.html")
103
- if RUBY_PLATFORM =~ /java/
104
- @browser.document.should be_instance_of(Java::ComGargoylesoftwareHtmlunitHtml::HtmlHtml)
105
- else
106
- @browser.document.should be_instance_of(WIN32OLE)
107
- end
108
- end
109
- end
110
-
111
- # Show methods
112
- describe "#show_«collection»" do
113
- it "should print a human readable representation of elements matching the given name" do
114
- @browser.goto(TEST_HOST + "/non_control_elements.html")
115
- temp_stdout = StringIO.new
116
- old_stdout = $stdout
117
- $stdout = temp_stdout
118
- begin
119
- @browser.show_divs
120
- ensure
121
- $stdout = old_stdout
122
- end
123
- temp_stdout.string.should ==
124
- 'Found 8 divs
125
- 1:
126
- 2: id="outer_container"
127
- 3: id="header" title="Header and primary navigation" class="profile"
128
- 4: id="promo" name="invalid_attribute" value="invalid_attribute"
129
- 5: id="content"
130
- 6: id="best_language" onclick="this.innerHTML = \'Ruby!\'" style="color: red; text-decoration: underline; cursor: pointer;"
131
- 7: id="html_test" class="some_class" title="This is a title"
132
- 8: id="footer" title="Closing remarks" class="profile"
133
- '
134
- end
135
-
136
- it "should raise NoMethodError if the collection does not exist" do
137
- @browser.goto(TEST_HOST + "/non_control_elements.html")
138
- lambda { @browser.show_no_such_collection }.should raise_error(NoMethodError)
139
- end
140
- end
141
-
142
- # Manipulation methods
143
- describe ".start" do
144
- it "should go to the given URL and return an instance of itself" do
145
- @browser = Browser.start(TEST_HOST + "/non_control_elements.html")
146
- @browser.should be_instance_of(Browser)
147
- @browser.title.should == "Non-control elements"
148
- end
149
- end
150
-
151
- describe "#goto" do
152
- # waiting for JRuby OpenSSL
153
- # it "should handle HTTPS" do
154
- # pending
155
- # end
156
-
157
- it "should add http:// to URLs with no protocol specified" do
158
- url = TEST_HOST[%r{http://(.*)}, 1]
159
- url.should_not be_nil
160
- @browser.goto(url)
161
- @browser.url.should == "http://#{url}"
162
- end
163
-
164
- it "should go to the given url without raising errors" do
165
- lambda { @browser.goto(TEST_HOST + "/non_control_elements.html") }.should_not raise_error
166
- end
167
- end
168
-
169
- describe "#refresh" do
170
- it "should refresh the page" do
171
- @browser.goto(TEST_HOST + "/non_control_elements.html")
172
- @browser.span(:name, 'footer').click
173
- @browser.span(:name, 'footer').text.should include('Javascript')
174
- @browser.refresh
175
- @browser.span(:name, 'footer').text.should_not include('Javascript')
176
- end
177
- end
178
-
179
- describe "#execute_script" do
180
- it "should execute the given JavaScript on the current page" do
181
- @browser.goto(TEST_HOST + "/non_control_elements.html")
182
- @browser.pre(:id, 'rspec').text.should_not == "javascript text"
183
- @browser.execute_script("document.getElementById('rspec').innerHTML = 'javascript text'")
184
- @browser.pre(:id, 'rspec').text.should == "javascript text"
185
- end
186
- end
187
-
188
- describe "#back" do
189
- it "should go to the previous page" do
190
- @browser.goto(TEST_HOST + "/non_control_elements.html")
191
- orig_url = @browser.url
192
- @browser.goto(TEST_HOST + "/tables.html")
193
- new_url = @browser.url
194
- orig_url.should_not == new_url
195
- @browser.back
196
- orig_url.should == @browser.url
197
- end
198
- end
199
-
200
- # Other
201
- describe "#contains_text" do
202
- before :each do
203
- @browser.goto(TEST_HOST + "/non_control_elements.html")
204
- end
205
-
206
- it "should raise ArgumentError when called with no or wrong arguments" do
207
- lambda { @browser.contains_text }.should raise_error(ArgumentError)
208
- lambda { @browser.contains_text(nil) }.should raise_error(ArgumentError)
209
- lambda { @browser.contains_text(42) }.should raise_error(ArgumentError)
210
- end
211
-
212
- it "should return the index if the given text exists" do
213
- @browser.contains_text('Dubito, ergo cogito, ergo sum.').should be_instance_of(Fixnum)
214
- @browser.contains_text(/Dubito.*sum./).should_not be_nil
215
- end
216
-
217
- it "should return nil if the text doesn't exist" do
218
- @browser.contains_text('no_such_text').should be_nil
219
- @browser.contains_text(/no_such_text/).should be_nil
220
- end
221
-
222
- it "should not raise error on a blank page" do
223
- @browser = Browser.new
224
- lambda { @browser.contains_text('') }.should_not raise_error
225
- end
226
- end
227
-
228
- describe "#add_checker" do
229
- it "should raise ArgumentError when not given any arguments" do
230
- lambda { @browser.add_checker }.should raise_error(ArgumentError)
231
- end
232
-
233
- it "should run the given proc on each page load" do
234
- output = ''
235
- proc = Proc.new { |ie| output << ie.text }
236
- @browser.add_checker(proc)
237
- @browser.goto(TEST_HOST + "/non_control_elements.html")
238
- output.should include('Dubito, ergo cogito, ergo sum')
239
- end
240
-
241
- it "should run the given block on each page load" do
242
- output = ''
243
- @browser.add_checker { |ie| output << ie.text }
244
- @browser.goto(TEST_HOST + "/non_control_elements.html")
245
- output.should include('Dubito, ergo cogito, ergo sum')
246
- end
247
- end
248
-
249
- describe "#disable_checker" do
250
- it "should remove a previously added checker" do
251
- output = ''
252
- checker = lambda { |ie| output << ie.text }
253
- @browser.add_checker(checker)
254
- @browser.goto(TEST_HOST + "/non_control_elements.html")
255
- output.should include('Dubito, ergo cogito, ergo sum')
256
- @browser.disable_checker(checker)
257
- @browser.goto(TEST_HOST + "/non_control_elements.html")
258
- output.should include('Dubito, ergo cogito, ergo sum')
259
- end
260
- end
261
-
262
- after :all do
263
- @browser.close
264
- end
265
-
266
- end