celerity 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. data/History.txt +4 -0
  2. data/License.txt +621 -0
  3. data/README.txt +58 -0
  4. data/Rakefile +4 -0
  5. data/lib/celerity.rb +47 -0
  6. data/lib/celerity/clickable_element.rb +11 -0
  7. data/lib/celerity/collections.rb +99 -0
  8. data/lib/celerity/container.rb +369 -0
  9. data/lib/celerity/disabled_element.rb +20 -0
  10. data/lib/celerity/element.rb +114 -0
  11. data/lib/celerity/element_collections.rb +67 -0
  12. data/lib/celerity/elements/button.rb +13 -0
  13. data/lib/celerity/elements/file_field.rb +12 -0
  14. data/lib/celerity/elements/form.rb +15 -0
  15. data/lib/celerity/elements/frame.rb +44 -0
  16. data/lib/celerity/elements/image.rb +70 -0
  17. data/lib/celerity/elements/label.rb +10 -0
  18. data/lib/celerity/elements/link.rb +13 -0
  19. data/lib/celerity/elements/radio_check.rb +59 -0
  20. data/lib/celerity/elements/select_list.rb +84 -0
  21. data/lib/celerity/elements/table.rb +94 -0
  22. data/lib/celerity/elements/table_body.rb +38 -0
  23. data/lib/celerity/elements/table_cell.rb +30 -0
  24. data/lib/celerity/elements/table_row.rb +34 -0
  25. data/lib/celerity/elements/text_field.rb +80 -0
  26. data/lib/celerity/exception.rb +48 -0
  27. data/lib/celerity/htmlunit/commons-codec-1.3.jar +0 -0
  28. data/lib/celerity/htmlunit/commons-collections-3.2.jar +0 -0
  29. data/lib/celerity/htmlunit/commons-httpclient-3.1.jar +0 -0
  30. data/lib/celerity/htmlunit/commons-io-1.4.jar +0 -0
  31. data/lib/celerity/htmlunit/commons-lang-2.4.jar +0 -0
  32. data/lib/celerity/htmlunit/commons-logging-1.1.1.jar +0 -0
  33. data/lib/celerity/htmlunit/cssparser-0.9.5.jar +0 -0
  34. data/lib/celerity/htmlunit/htmlunit-2.2-SNAPSHOT.jar +0 -0
  35. data/lib/celerity/htmlunit/js-1.7R1.jar +0 -0
  36. data/lib/celerity/htmlunit/nekohtml-1.9.7.jar +0 -0
  37. data/lib/celerity/htmlunit/sac-1.3.jar +0 -0
  38. data/lib/celerity/htmlunit/xalan-2.7.0.jar +0 -0
  39. data/lib/celerity/htmlunit/xercesImpl-2.8.1.jar +0 -0
  40. data/lib/celerity/htmlunit/xml-apis-1.0.b2.jar +0 -0
  41. data/lib/celerity/ie.rb +126 -0
  42. data/lib/celerity/input_element.rb +29 -0
  43. data/lib/celerity/non_control_elements.rb +50 -0
  44. data/lib/celerity/version.rb +9 -0
  45. data/setup.rb +1585 -0
  46. data/spec/area_spec.rb +79 -0
  47. data/spec/areas_spec.rb +41 -0
  48. data/spec/button_spec.rb +171 -0
  49. data/spec/buttons_spec.rb +40 -0
  50. data/spec/checkbox_spec.rb +259 -0
  51. data/spec/checkboxes_spec.rb +39 -0
  52. data/spec/div_spec.rb +174 -0
  53. data/spec/divs_spec.rb +40 -0
  54. data/spec/element_spec.rb +29 -0
  55. data/spec/filefield_spec.rb +110 -0
  56. data/spec/filefields_spec.rb +41 -0
  57. data/spec/form_spec.rb +53 -0
  58. data/spec/forms_spec.rb +42 -0
  59. data/spec/frame_spec.rb +103 -0
  60. data/spec/hidden_spec.rb +105 -0
  61. data/spec/hiddens_spec.rb +40 -0
  62. data/spec/html/forms_with_input_elements.html +107 -0
  63. data/spec/html/frame_1.html +17 -0
  64. data/spec/html/frame_2.html +16 -0
  65. data/spec/html/frames.html +11 -0
  66. data/spec/html/iframes.html +12 -0
  67. data/spec/html/images.html +24 -0
  68. data/spec/html/images/1.gif +0 -0
  69. data/spec/html/images/2.gif +0 -0
  70. data/spec/html/images/3.gif +0 -0
  71. data/spec/html/images/button.jpg +0 -0
  72. data/spec/html/images/circle.jpg +0 -0
  73. data/spec/html/images/map.gif +0 -0
  74. data/spec/html/images/map2.gif +0 -0
  75. data/spec/html/images/minus.gif +0 -0
  76. data/spec/html/images/originaltriangle.jpg +0 -0
  77. data/spec/html/images/plus.gif +0 -0
  78. data/spec/html/images/square.jpg +0 -0
  79. data/spec/html/images/triangle.jpg +0 -0
  80. data/spec/html/non_control_elements.html +85 -0
  81. data/spec/html/tables.html +119 -0
  82. data/spec/ie_spec.rb +146 -0
  83. data/spec/image_spec.rb +210 -0
  84. data/spec/images_spec.rb +39 -0
  85. data/spec/label_spec.rb +65 -0
  86. data/spec/labels_spec.rb +41 -0
  87. data/spec/li_spec.rb +114 -0
  88. data/spec/link_spec.rb +147 -0
  89. data/spec/links_spec.rb +43 -0
  90. data/spec/lis_spec.rb +40 -0
  91. data/spec/map_spec.rb +83 -0
  92. data/spec/maps_spec.rb +41 -0
  93. data/spec/p_spec.rb +140 -0
  94. data/spec/pre_spec.rb +110 -0
  95. data/spec/pres_spec.rb +41 -0
  96. data/spec/ps_spec.rb +40 -0
  97. data/spec/radio_spec.rb +260 -0
  98. data/spec/radios_spec.rb +43 -0
  99. data/spec/select_list_spec.rb +286 -0
  100. data/spec/select_lists_spec.rb +47 -0
  101. data/spec/span_spec.rb +156 -0
  102. data/spec/spans_spec.rb +65 -0
  103. data/spec/spec.opts +1 -0
  104. data/spec/spec_helper.rb +90 -0
  105. data/spec/table_bodies.rb +40 -0
  106. data/spec/table_bodies_spec.rb +42 -0
  107. data/spec/table_body_spec.rb +72 -0
  108. data/spec/table_cell_spec.rb +61 -0
  109. data/spec/table_cells_spec.rb +60 -0
  110. data/spec/table_row_spec.rb +59 -0
  111. data/spec/table_rows_spec.rb +57 -0
  112. data/spec/table_spec.rb +111 -0
  113. data/spec/tables_spec.rb +42 -0
  114. data/spec/text_field_spec.rb +234 -0
  115. data/spec/text_fields_spec.rb +45 -0
  116. data/tasks/environment.rake +7 -0
  117. data/tasks/rspec.rake +23 -0
  118. data/tasks/simple_ci.rake +94 -0
  119. data/tasks/testserver.rake +17 -0
  120. metadata +174 -0
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3
+ <head>
4
+ <title>Iframes</title>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ </head>
7
+ <body>
8
+ <h1>Iframes</h1>
9
+ <iframe src="frame_1.html" id="frame_1" name="frame1" class="iframe"></iframe>
10
+ <iframe src="frame_2.html" id="frame_2" name="frame2" class="iframe"></iframe>
11
+ </body>
12
+ </html>
@@ -0,0 +1,24 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3
+ <head>
4
+ <title>Images</title>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ </head>
7
+ <body>
8
+ <img />
9
+ <img src="images/1.gif" alt="1" title="The number one!" />
10
+ <img src="images/2.gif" alt="2" />
11
+ <img src="images/3.gif" alt="3" />
12
+ <img src="images/circle.jpg" name="circle" alt="circle" title="Circle" />
13
+ <img src="images/square.jpg" name="square" alt="square" id="square" title="Square" />
14
+ <img src="images/triangle.jpg" id="triangle" usemap="#triangle_map" />
15
+ <img src="images/no_such_file.jpg" id="no_such_file" />
16
+ <map id ="triangle_map" name="triangle_map">
17
+ <area id="NCE" name="NCE" shape ="rect" coords ="40,0,70,25" href ="non_control_elements.html" alt="Non-control elements" title="Non-control elements" />
18
+ <area id="tables" name="tables" shape ="rect" coords ="0,80,20,98" href ="tables.html" alt="Tables" title="Tables" />
19
+ </map>
20
+ <map>
21
+ <area></area>
22
+ </map>
23
+ </body>
24
+ </html>
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,85 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3
+ <head>
4
+ <title>Non-control elements</title>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ </head>
7
+ <body>
8
+ <div></div>
9
+ <div id="outer_container">
10
+ <div id="header" title="Header and primary navigation" class="profile">
11
+ <h1>Header 1</h1>
12
+ <ul id="navbar">
13
+ <li><a></a></li>
14
+ <li><a id="link_2" title="link_title_2" href="non_control_elements.html" class="external">Link 2</a></li>
15
+ <li><a id="link_3" title="link_title_3" href="forms_with_input_elements.html" name="bad_attribute" value="bad_attribute" class="external">Link 3</a></li>
16
+ <li></li>
17
+ <li id="non_link_1" class="nonlink" title="This is not a link!">Non-link 1</li>
18
+ <li id="non_link_2">Non-link 2</li>
19
+ <li>Non-link 3</li>
20
+ </ul>
21
+ </div>
22
+ <div id="promo" name="invalid_attribute" value="invalid_attribute">
23
+ <span id="lead" class="lead" title="Lorem ipsum">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur eu pede. Ut justo. Praesent feugiat, elit in feugiat iaculis, sem risus rutrum justo, eget fermentum dolor arcu non nunc.</span>
24
+ <span name="invalid_attribute" value="invalid_attribute">Sed pretium metus et quam. Nullam odio dolor, vestibulum non, tempor ut, vehicula sed, sapien. Vestibulum placerat ligula at quam. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</span>
25
+ <span>Suspendisse at ipsum a turpis viverra venenatis. Praesent ut nibh. Nullam eu odio. Donec tempor, elit ut lacinia porttitor, augue neque vehicula diam, in elementum ligula nisi a tellus. Aliquam vestibulum ultricies tortor. </span>
26
+ <span>Dubito, ergo cogito, ergo sum.</span>
27
+ <span></span>
28
+ </div>
29
+ <div id="content">
30
+ <p id="lead" class="lead" title="Lorem ipsum">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur eu pede. Ut justo. Praesent feugiat, elit in feugiat iaculis, sem risus rutrum justo, eget fermentum dolor arcu non nunc.</p>
31
+ <p name="invalid_attribute" value="invalid_attribute">Sed pretium metus et quam. Nullam odio dolor, vestibulum non, tempor ut, vehicula sed, sapien. Vestibulum placerat ligula at quam. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
32
+ <p>Suspendisse at ipsum a turpis viverra venenatis. Praesent ut nibh. Nullam eu odio. Donec tempor, elit ut lacinia porttitor, augue neque vehicula diam, in elementum ligula nisi a tellus. Aliquam vestibulum ultricies tortor. </p>
33
+ <p>Dubito, ergo cogito, ergo sum.</p>
34
+ <p></p>
35
+ <pre></pre>
36
+ <h2>Ruby RSpec example</h2>
37
+ <pre class="ruby" id="rspec">
38
+ @ie.pre(:id, "rspec").should exist
39
+ </pre>
40
+ <h2>PHP Hello World</h2>
41
+ <pre class="php">
42
+ &lt;?php
43
+ echo "Hello, World!\n";
44
+ ?&gt;
45
+ </pre>
46
+ <h2>Ruby Hello World</h2>
47
+ <pre class="ruby">
48
+ puts "Hello, World!"
49
+ </pre>
50
+ <h2>C++ Hello World</h2>
51
+ <pre class="c++">
52
+ main() {
53
+ cout << "Hello World!\n";
54
+ return 0;
55
+ }
56
+ </pre>
57
+ <h2>LISP</h2>
58
+ <pre class="haskell">
59
+ main = putStrLn "Hello World"
60
+ </pre>
61
+ <h2>Brainfuck</h2>
62
+ <pre class="brainfuck" title="The brainfuck language is an esoteric programming language noted for its extreme minimalism">
63
+ ++++++++++
64
+ [>+++++++>++++++++++>+++>+<<<<-] The initial loop to set up useful values in the array
65
+ >++. Print 'H'
66
+ >+. Print 'e'
67
+ +++++++. Print 'l'
68
+ . Print 'l'
69
+ +++. Print 'o'
70
+ >++. Print ' '
71
+ <<+++++++++++++++. Print 'W'
72
+ >. Print 'o'
73
+ +++. Print 'r'
74
+ ------. Print 'l'
75
+ --------. Print 'd'
76
+ >+. Print '!'
77
+ >. Print newline
78
+ </pre>
79
+ </div>
80
+ <div id="footer" title="Closing remarks" class="profile">
81
+ <span class="footer" name="footer" onclick="this.innerHTML = 'This is a footer with text set by Javascript.'">This is a footer.</span>
82
+ </div>
83
+ </div>
84
+ </body>
85
+ </html>
@@ -0,0 +1,119 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3
+ <head>
4
+ <title>Tables</title>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ </head>
7
+ <body>
8
+ <h1>Tables</h1>
9
+ <h2>Semantic table</h2>
10
+ <table cellspacing="0" cellpadding="5" rules="groups" frame="box" border="1" id="axis_example" summary="Hugh Laurie made more money than Gregory House in both March and April of 2008.">
11
+ <caption>Income tax information for Gregory House and Hugh Laurie</caption>
12
+ <colgroup width="25%" align="left"></colgroup>
13
+ <colgroup width="25%" span="3" align="right"></colgroup>
14
+ <thead>
15
+ <tr style="border-bottom: 1px solid black;" class="dark">
16
+ <th></th>
17
+ <th id="before_tax" axis="cash" abbr="Before tax">Before income tax</th>
18
+ <th id="tax" axis="cash" abbr="Tax">Income tax</th>
19
+ <th id="after_tax" axis="cash" abbr="After tax">After income tax</th>
20
+ </tr>
21
+ </thead>
22
+ <tfoot>
23
+ <tr class="dark">
24
+ <th axis="sum">Sum</th>
25
+ <td headers="before_tax">24 349</td>
26
+ <td headers="tax">5 577</td>
27
+ <td headers="after_tax">18 722</td>
28
+ </tr>
29
+ </tfoot>
30
+ <tbody id="first">
31
+ <tr>
32
+ <th id="d1" axis="date" scope="rowgroup">March 2008</th>
33
+ <th></th>
34
+ <th></th>
35
+ <th></th>
36
+ </tr>
37
+ <tr>
38
+ <td id="p1" abbr="Dr. House">Gregory House</td>
39
+ <td headers="before_tax p1 d1">5 934</td>
40
+ <td headers="tax p1 d1">1 347</td>
41
+ <td headers="after_tax p1 d1">4 587</td>
42
+ </tr>
43
+ <tr>
44
+ <td id="p2" abbr="Laurie">Hugh Laurie</td>
45
+ <td headers="before_tax p2 d1">6 300</td>
46
+ <td headers="tax p2 d1">1 479</td>
47
+ <td headers="after_tax p2 d1">4 821</td>
48
+ </tr>
49
+ </tbody>
50
+ <tbody name="second">
51
+ <tr>
52
+ <th id="d2" axis="date" scope="rowgroup">April 2008</th>
53
+ <th></th>
54
+ <th></th>
55
+ <th></th>
56
+ </tr>
57
+ <tr>
58
+ <td id="p3" abbr="Dr. House">Gregory House</td>
59
+ <td headers="before_tax p3 d2">5 863</td>
60
+ <td headers="tax p3 d2">1 331</td>
61
+ <td headers="after_tax p3 d2">4 532</td>
62
+ </tr>
63
+ <tr>
64
+ <td id="p4" abbr="Laurie">Hugh Laurie</td>
65
+ <td headers="before_tax p4 d2">6 252</td>
66
+ <td headers="tax p4 d2">1 420</td>
67
+ <td headers="after_tax p4 d2">4 832</td>
68
+ </tr>
69
+ </tbody>
70
+ </table>
71
+ <h2>Table inside a table</h2>
72
+ <table border="1" id="outer">
73
+ <tr id="outer_first">
74
+ <td>
75
+ Table 1, Row 1, Cell 1
76
+ </td>
77
+ <td>
78
+ Table 1, Row 1, Cell 2
79
+ </td>
80
+ </tr>
81
+ <tr>
82
+ <td id="t1_r2_c1">
83
+ Table 1, Row 2, Cell 1
84
+ </td>
85
+ <td>
86
+ Table 1, Row 2, Cell 2
87
+ <table border="1" id="inner">
88
+ <tr id="inner_first">
89
+ <td id="t2_r1_c1">
90
+ Table 2, Row 1, Cell 1
91
+ </td>
92
+ <td>
93
+ Table 2, Row 1, Cell 2
94
+ </td>
95
+ </tr>
96
+ </table>
97
+ </td>
98
+ </tr>
99
+ <tr id="outer_last">
100
+ <td>
101
+ Table 1, Row 3, Cell 1
102
+ </td>
103
+ <td>
104
+ Table 1, Row 3, Cell 2
105
+ </td>
106
+ </tr>
107
+ </table>
108
+ <h2>Colspan</h2>
109
+ <table border="1" id="colspan">
110
+ <tr>
111
+ <td colspan="2" id="colspan_2">Colspan 2</td>
112
+ </tr>
113
+ <tr>
114
+ <td id="no_colspan">No colspan attribute</td>
115
+ <td>No colspan attribute</td>
116
+ </tr>
117
+ </table>
118
+ </body>
119
+ </html>
@@ -0,0 +1,146 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "IE" do
4
+
5
+ before :all do
6
+ @ie = IE.new
7
+ add_spec_checker(@ie)
8
+ end
9
+
10
+ # Exists
11
+ describe "#exists?" do
12
+ it "should return true if we are at a page" do
13
+ @ie.should_not exist
14
+ @ie.goto(TEST_HOST + "/non_control_elements.html")
15
+ @ie.should exist
16
+ end
17
+ it "should not exist after closing" do
18
+ @ie.close
19
+ @ie.should_not exist
20
+ end
21
+ end
22
+
23
+ # Attribute methods
24
+ describe "#html" do
25
+ it "should return the html of the page" do
26
+ @ie.goto(TEST_HOST + "/non_control_elements.html")
27
+ @ie.html.should include('<meta http-equiv="Content-Type"')
28
+ end
29
+ end
30
+
31
+ describe "#title" do
32
+ it "should return the current page title" do
33
+ @ie.goto(TEST_HOST + "/non_control_elements.html")
34
+ @ie.title.should == "Non-control elements"
35
+ end
36
+ end
37
+
38
+ describe "#text" do
39
+ it "should return the text of the page" do
40
+ @ie.goto(TEST_HOST + "/non_control_elements.html")
41
+ @ie.text.include?("Dubito, ergo cogito, ergo sum.").should be_true
42
+ end
43
+ end
44
+
45
+ describe "#url" do
46
+ it "should return the current url" do
47
+ @ie.goto(TEST_HOST + "/non_control_elements.html")
48
+ @ie.url.should == TEST_HOST + "/non_control_elements.html"
49
+ end
50
+ end
51
+
52
+
53
+ # Manipulation methods
54
+ describe ".start" do
55
+ it "should go to the given URL and return an instance of itself" do
56
+ @ie = Celerity::IE.start(TEST_HOST + "/non_control_elements.html")
57
+ @ie.should be_instance_of(Celerity::IE)
58
+ @ie.title.should == "Non-control elements"
59
+ end
60
+ end
61
+
62
+ describe "#goto" do
63
+ it "should go to the given url without raising errors" do
64
+ lambda { @ie.goto(TEST_HOST + "/non_control_elements.html") }.should_not raise_error
65
+ end
66
+ end
67
+
68
+ describe "#refresh" do
69
+ it "should refresh the page" do
70
+ @ie.refresh
71
+ end
72
+ end
73
+
74
+ describe "#back" do
75
+ it "should go to the previous page" do
76
+ @ie.goto(TEST_HOST + "/non_control_elements.html")
77
+ orig_url = @ie.url
78
+ @ie.goto(TEST_HOST + "/tables.html")
79
+ new_url = @ie.url
80
+ orig_url.should_not == new_url
81
+ @ie.back
82
+ orig_url.should == @ie.url
83
+ end
84
+ end
85
+
86
+ # Other
87
+ describe "#contains_text" do
88
+ before :each do
89
+ @ie.goto(TEST_HOST + "/non_control_elements.html")
90
+ end
91
+ it "should raise ArgumentError when called with no or wrong arguments" do
92
+ lambda { @ie.contains_text }.should raise_error(ArgumentError)
93
+ lambda { @ie.contains_text(nil) }.should raise_error(ArgumentError)
94
+ lambda { @ie.contains_text(42) }.should raise_error(ArgumentError)
95
+ end
96
+ it "should return the index if the given text exists" do
97
+ @ie.contains_text('Dubito, ergo cogito, ergo sum.').should be_instance_of(Fixnum)
98
+ @ie.contains_text(/Dubito.*sum./).should_not be_nil
99
+ end
100
+ it "should return nil if the text doesn't exist" do
101
+ @ie.contains_text('no_such_text').should be_nil
102
+ @ie.contains_text(/no_such_text/).should be_nil
103
+ end
104
+ it "should not raise error on a blank page" do
105
+ @ie = IE.new
106
+ lambda { @ie.contains_text('') }.should_not raise_error
107
+ end
108
+ end
109
+
110
+ describe "#add_checker" do
111
+ it "should raise ArgumentError when not given any arguments" do
112
+ lambda { @ie.add_checker }.should raise_error(ArgumentError)
113
+ end
114
+ it "should run the given proc on each page load" do
115
+ output = ''
116
+ @ie.add_checker(Proc.new { |ie| output << ie.text })
117
+ @ie.goto(TEST_HOST + "/non_control_elements.html")
118
+ output.should include('Dubito, ergo cogito, ergo sum')
119
+ end
120
+ it "should run the given block on each page load" do
121
+ output = ''
122
+ @ie.add_checker { |ie| output << ie.text }
123
+ @ie.goto(TEST_HOST + "/non_control_elements.html")
124
+ output.should include('Dubito, ergo cogito, ergo sum')
125
+ end
126
+ end
127
+
128
+ describe "#disable_checker" do
129
+ it "should remove a previously added checker" do
130
+ output = ''
131
+ checker = lambda { |ie| output << ie.text }
132
+ @ie.add_checker(checker)
133
+ @ie.goto(TEST_HOST + "/non_control_elements.html")
134
+ output.should include('Dubito, ergo cogito, ergo sum')
135
+
136
+ @ie.disable_checker(checker)
137
+ @ie.goto(TEST_HOST + "/non_control_elements.html")
138
+ output.should include('Dubito, ergo cogito, ergo sum')
139
+ end
140
+ end
141
+
142
+ after :all do
143
+ @ie.close
144
+ end
145
+
146
+ end
@@ -0,0 +1,210 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "Image" do
4
+
5
+ before :all do
6
+ @ie = IE.new
7
+ add_spec_checker(@ie)
8
+ end
9
+
10
+ before :each do
11
+ @ie.goto(TEST_HOST + "/images.html")
12
+ end
13
+
14
+ # Exists method
15
+ describe "#exists" do
16
+ it "should return true when the image exists" do
17
+ @ie.image(:id, 'square').should exist
18
+ @ie.image(:id, /square/).should exist
19
+ @ie.image(:name, 'circle').should exist
20
+ @ie.image(:name, /circle/).should exist
21
+ @ie.image(:src, 'images/circle.jpg').should exist
22
+ @ie.image(:src, /circle/).should exist
23
+ @ie.image(:alt, 'circle').should exist
24
+ @ie.image(:alt, /cir/).should exist
25
+ @ie.image(:title, 'Circle').should exist
26
+ end
27
+ it "should return false when the image exists" do
28
+ @ie.image(:id, 'no_such_id').should_not exist
29
+ @ie.image(:id, /no_such_id/).should_not exist
30
+ @ie.image(:name, 'no_such_name').should_not exist
31
+ @ie.image(:name, /no_such_name/).should_not exist
32
+ @ie.image(:src, 'no_such_src').should_not exist
33
+ @ie.image(:src, /no_such_src/).should_not exist
34
+ @ie.image(:alt, 'no_such_alt').should_not exist
35
+ @ie.image(:alt, /no_such_alt/).should_not exist
36
+ @ie.image(:title, 'no_such_title').should_not exist
37
+ @ie.image(:title, /no_such_title/).should_not exist
38
+ end
39
+ it "should raise ArgumentError when what argument is invalid" do
40
+ lambda { @ie.button(:id, 3.14).exists? }.should raise_error(ArgumentError)
41
+ end
42
+ it "should raise MissingWayOfFindingObjectException when how argument is invalid" do
43
+ lambda { @ie.button(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
44
+ end
45
+ end
46
+
47
+ # Attribute methods
48
+ describe "#alt" do
49
+ it "should return the alt attribute of the image if the image exists" do
50
+ @ie.image(:name, 'square').alt.should == "square"
51
+ @ie.image(:name, 'circle').alt.should == 'circle'
52
+ end
53
+ it "should return an empty string if the image exists and the attribute doesn't" do
54
+ @ie.image(:index, 1).alt.should == ""
55
+ end
56
+ it "should raise UnknownObjectException if the image doesn't exist" do
57
+ lambda { @ie.image(:index, 1337).alt }.should raise_error(UnknownObjectException)
58
+ end
59
+ end
60
+
61
+ describe "#id" do
62
+ it "should return the id attribute of the image if the image exists" do
63
+ @ie.image(:name, 'square').id.should == 'square'
64
+ end
65
+ it "should return an empty string if the image exists and the attribute doesn't" do
66
+ @ie.image(:index, 1).id.should == ""
67
+ end
68
+ it "should raise UnknownObjectException if the image doesn't exist" do
69
+ lambda { @ie.image(:index, 1337).id }.should raise_error(UnknownObjectException)
70
+ end
71
+ end
72
+
73
+ describe "#name" do
74
+ it "should return the name attribute of the image if the image exists" do
75
+ @ie.image(:name, 'square').name.should == 'square'
76
+ end
77
+ it "should return an empty string if the image exists and the attribute doesn't" do
78
+ @ie.image(:index, 1).name.should == ""
79
+ end
80
+ it "should raise UnknownObjectException if the image doesn't exist" do
81
+ lambda { @ie.image(:index, 1337).name }.should raise_error(UnknownObjectException)
82
+ end
83
+ end
84
+
85
+ describe "#src" do
86
+ it "should return the src attribute of the image if the image exists" do
87
+ @ie.image(:name, 'square').src.should match(/square\.jpg/i)
88
+ end
89
+ it "should return an empty string if the image exists and the attribute doesn't" do
90
+ @ie.image(:index, 1).src.should == ""
91
+ end
92
+ it "should raise UnknownObjectException if the image doesn't exist" do
93
+ lambda { @ie.image(:index, 1337).src }.should raise_error(UnknownObjectException)
94
+ end
95
+ end
96
+
97
+ describe "#title" do
98
+ it "should return the title attribute of the image if the image exists" do
99
+ @ie.image(:id, 'square').title.should == 'Square'
100
+ end
101
+ it "should return an empty string if the image exists and the attribute doesn't" do
102
+ @ie.image(:index, 1).title.should == ""
103
+ end
104
+ it "should raise UnknownObjectException if the image doesn't exist" do
105
+ lambda { @ie.image(:index, 1337).title }.should raise_error(UnknownObjectException)
106
+ end
107
+ end
108
+
109
+ # Manipulation methods
110
+ describe "#click" do
111
+ it "should raise UnknownObjectException when the image doesn't exist" do
112
+ lambda { @ie.image(:id, 'missing_attribute').click }.should raise_error(UnknownObjectException)
113
+ lambda { @ie.image(:name, 'missing_attribute').click }.should raise_error(UnknownObjectException)
114
+ lambda { @ie.image(:src, 'missing_attribute').click }.should raise_error(UnknownObjectException)
115
+ lambda { @ie.image(:alt, 'missing_attribute').click }.should raise_error(UnknownObjectException)
116
+ end
117
+ end
118
+
119
+ # File methods
120
+ describe "#file_created_date" do
121
+ it "should return the date the image was created as reported by the file system" do
122
+ image = @ie.image(:index, 2)
123
+ path = File.dirname(__FILE__) + "/html/#{image.src}"
124
+ image.file_created_date.to_i.should == File.mtime(path).to_i
125
+ end
126
+ end
127
+
128
+ describe "#file_size" do
129
+ it "should return the file size of the image if the image exists" do
130
+ @ie.image(:id, 'square').file_size.should == 788
131
+ end
132
+ it "should raise UnknownObjectException if the image doesn't exist" do
133
+ lambda { @ie.image(:index, 1337).file_size }.should raise_error(UnknownObjectException)
134
+ end
135
+ end
136
+
137
+ describe "#height" do
138
+ it "should return the height of the image if the image exists" do
139
+ @ie.image(:id, 'square').height.should == 88
140
+ end
141
+ it "should raise UnknownObjectException if the image doesn't exist" do
142
+ lambda { @ie.image(:index, 1337).height }.should raise_error(UnknownObjectException)
143
+ end
144
+ end
145
+
146
+ describe "#width" do
147
+ it "should return the width of the image if the image exists" do
148
+ @ie.image(:id, 'square').width.should == 88
149
+ end
150
+ it "should raise UnknownObjectException if the image doesn't exist" do
151
+ lambda { @ie.image(:index, 1337).width }.should raise_error(UnknownObjectException)
152
+ end
153
+ end
154
+
155
+ # Other
156
+ describe "#loaded?" do
157
+ it "should return true if the image has been loaded" do
158
+ @ie.image(:name, 'circle').should be_loaded
159
+ @ie.image(:alt, 'circle').should be_loaded
160
+ @ie.image(:alt, /circle/).should be_loaded
161
+ end
162
+ it "should return false if the image has not been loaded" do
163
+ @ie.image(:id, 'no_such_file').should_not be_loaded
164
+ end
165
+ it "should raise UnknownObjectException if the image doesn't exist" do
166
+ lambda { @ie.image(:name, 'no_such_image').loaded? }.should raise_error(UnknownObjectException)
167
+ lambda { @ie.image(:id, 'no_such_image').loaded? }.should raise_error(UnknownObjectException)
168
+ lambda { @ie.image(:src, 'no_such_image').loaded? }.should raise_error(UnknownObjectException)
169
+ lambda { @ie.image(:alt, 'no_such_image').loaded? }.should raise_error(UnknownObjectException)
170
+ lambda { @ie.image(:index, 1337).loaded? }.should raise_error(UnknownObjectException)
171
+ end
172
+ end
173
+
174
+ describe "#html" do
175
+ it "should return the image as a string of html" do
176
+ @ie.image(:id, 'triangle').html.chomp.should == '<img src="images/triangle.jpg" id="triangle" usemap="#triangle_map" />'
177
+ end
178
+ end
179
+
180
+ describe "#save" do
181
+ it "should save an image to file" do
182
+ file = "sample.img.dat"
183
+ @ie.image(:index, 2).save(file)
184
+ File.exist?(file).should be_true
185
+ File.delete(file)
186
+ end
187
+ end
188
+
189
+ # Image elements can't be disabled - the element doesn't get disabled when clicking the button in Firefox.
190
+ # describe "#disabled?" do
191
+ # it "should return true if the image is disabled" do
192
+ # @ie.text_field(:name, 'text1').clear
193
+ # @ie.button(:value, /Pos/).click
194
+ # @ie.text_field(:name, 'text1').value.should == 'clicked'
195
+ # @ie.image(:name, 'disabler_test').should_not be_disabled
196
+ #
197
+ # @ie.button(:name, 'disable_img').click
198
+ # @ie.image(:name, 'disabler_test').should be_disabled
199
+ #
200
+ # @ie.button(:name, 'disable_img').click
201
+ # @ie.image(:src, /button/).click
202
+ # @ie.text.include?('PASS').should be_true
203
+ # end
204
+ # end
205
+
206
+ after :all do
207
+ @ie.close
208
+ end
209
+
210
+ end