celerity 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/History.txt +10 -0
  2. data/README.txt +8 -11
  3. data/Rakefile +5 -3
  4. data/benchmark/bm_2000_spans.rb +48 -0
  5. data/benchmark/bm_digg.rb +26 -0
  6. data/benchmark/bm_google_images.rb +36 -0
  7. data/benchmark/bm_input_locator.rb +69 -0
  8. data/benchmark/loader.rb +9 -0
  9. data/lib/celerity.rb +3 -1
  10. data/lib/celerity/container.rb +23 -171
  11. data/lib/celerity/disabled_element.rb +1 -1
  12. data/lib/celerity/element.rb +78 -47
  13. data/lib/celerity/element_collections.rb +16 -32
  14. data/lib/celerity/element_locator.rb +135 -0
  15. data/lib/celerity/elements/button.rb +15 -0
  16. data/lib/celerity/elements/file_field.rb +1 -1
  17. data/lib/celerity/elements/form.rb +2 -1
  18. data/lib/celerity/elements/frame.rb +18 -21
  19. data/lib/celerity/elements/image.rb +2 -8
  20. data/lib/celerity/elements/label.rb +1 -3
  21. data/lib/celerity/elements/link.rb +1 -1
  22. data/lib/celerity/elements/option.rb +16 -0
  23. data/lib/celerity/elements/radio_check.rb +18 -7
  24. data/lib/celerity/elements/select_list.rb +1 -17
  25. data/lib/celerity/elements/table.rb +4 -4
  26. data/lib/celerity/elements/table_body.rb +6 -8
  27. data/lib/celerity/elements/table_cell.rb +3 -14
  28. data/lib/celerity/elements/table_row.rb +4 -10
  29. data/lib/celerity/elements/text_field.rb +16 -4
  30. data/lib/celerity/extra/method_generator.rb +144 -0
  31. data/lib/celerity/identifier.rb +10 -0
  32. data/lib/celerity/ie.rb +28 -13
  33. data/lib/celerity/input_element.rb +0 -4
  34. data/lib/celerity/non_control_elements.rb +12 -12
  35. data/lib/celerity/version.rb +1 -1
  36. data/spec/area_spec.rb +41 -41
  37. data/spec/areas_spec.rb +11 -11
  38. data/spec/button_spec.rb +73 -68
  39. data/spec/buttons_spec.rb +10 -10
  40. data/spec/checkbox_spec.rb +102 -96
  41. data/spec/checkboxes_spec.rb +10 -10
  42. data/spec/div_spec.rb +78 -73
  43. data/spec/divs_spec.rb +10 -10
  44. data/spec/element_spec.rb +20 -11
  45. data/spec/filefield_spec.rb +36 -41
  46. data/spec/filefields_spec.rb +10 -10
  47. data/spec/form_spec.rb +29 -29
  48. data/spec/forms_spec.rb +11 -11
  49. data/spec/frame_spec.rb +54 -49
  50. data/spec/hidden_spec.rb +43 -43
  51. data/spec/hiddens_spec.rb +10 -10
  52. data/spec/html/2000_spans.html +2009 -0
  53. data/spec/html/forms_with_input_elements.html +15 -9
  54. data/spec/html/non_control_elements.html +4 -2
  55. data/spec/ie_spec.rb +82 -48
  56. data/spec/image_spec.rb +83 -100
  57. data/spec/images_spec.rb +10 -10
  58. data/spec/label_spec.rb +29 -29
  59. data/spec/labels_spec.rb +10 -10
  60. data/spec/li_spec.rb +41 -41
  61. data/spec/link_spec.rb +65 -59
  62. data/spec/links_spec.rb +11 -11
  63. data/spec/lis_spec.rb +10 -10
  64. data/spec/map_spec.rb +30 -30
  65. data/spec/maps_spec.rb +10 -10
  66. data/spec/p_spec.rb +49 -49
  67. data/spec/pre_spec.rb +41 -41
  68. data/spec/pres_spec.rb +10 -10
  69. data/spec/ps_spec.rb +10 -10
  70. data/spec/radio_spec.rb +104 -97
  71. data/spec/radios_spec.rb +11 -11
  72. data/spec/select_list_spec.rb +118 -106
  73. data/spec/select_lists_spec.rb +15 -15
  74. data/spec/span_spec.rb +54 -54
  75. data/spec/spans_spec.rb +11 -11
  76. data/spec/spec.opts +1 -1
  77. data/spec/spec_helper.rb +23 -3
  78. data/spec/table_bodies.rb +8 -8
  79. data/spec/table_bodies_spec.rb +9 -9
  80. data/spec/table_body_spec.rb +28 -27
  81. data/spec/table_cell_spec.rb +25 -25
  82. data/spec/table_cells_spec.rb +16 -16
  83. data/spec/table_row_spec.rb +16 -16
  84. data/spec/table_rows_spec.rb +12 -12
  85. data/spec/table_spec.rb +36 -36
  86. data/spec/tables_spec.rb +12 -12
  87. data/spec/text_field_spec.rb +111 -92
  88. data/spec/text_fields_spec.rb +13 -13
  89. data/tasks/benchmark.rake +3 -0
  90. data/tasks/rspec.rake +2 -2
  91. data/tasks/testserver.rake +15 -0
  92. metadata +58 -46
  93. data/tasks/simple_ci.rake +0 -94
@@ -7,12 +7,12 @@
7
7
  <body>
8
8
  <h1><a href="">User administration</a></h1>
9
9
  <h2>Add user</h2>
10
- <form action="forms_with_input_elements.html" method="post" id="new_user" class="user">
10
+ <form enctype="multipart/form-data" action="post_to_me" method="post" id="new_user" class="user">
11
11
  <fieldset>
12
12
  <legend>Personal information</legend>
13
13
  <label for="new_user_first_name" id="first_label">First name</label>
14
14
  <input name="new_user_first_name" id="new_user_first_name" class="name" /> <br />
15
- <label for="new_user_first_name">Last name</label>
15
+ <label for="new_user_last_name">Last name</label>
16
16
  <input type="no_such_type" name="new_user_last_name" id="new_user_last_name" class="name" /> <br />
17
17
  <label for="new_user_email">Email address</label>
18
18
  <input type="text" name="new_user_email" id="new_user_email" /> <br />
@@ -21,8 +21,8 @@
21
21
  <option class="scandinavia">Denmark</option>
22
22
  <option class="scandinavia" selected="selected">Norway</option>
23
23
  <option class="scandinavia">Sweden</option>
24
- <option>United Kingdom</option>
25
- <option>USA</option>
24
+ <option >United Kingdom</option>
25
+ <option >USA</option>
26
26
  </select> <br />
27
27
  <label for="new_user_occupation">Occupation</label>
28
28
  <input type="text" name="new_user_occupation" id="new_user_occupation" value="Developer" /> <br />
@@ -31,7 +31,7 @@
31
31
  <label for="new_user_code">Personal code</label>
32
32
  <input type="text" title="Your personal code" name="new_user_code" id="new_user_code" value="HE2FF8" readonly="readonly" /> <br />
33
33
  <label for="new_user_languages">Languages</label>
34
- <select name="new_user_languages" id="new_user_languages" multiple="multiple">
34
+ <select name="new_user_languages" id="new_user_languages" multiple="multiple" onchange="document.getElementById('changed_language').innerHTML += 'changed language'">
35
35
  <option>Danish</option>
36
36
  <option selected="selected">English</option>
37
37
  <option selected="selected">Norwegian</option>
@@ -45,7 +45,7 @@
45
45
  <fieldset>
46
46
  <legend>Login information</legend>
47
47
  <label for="new_user_username">Username (max 20 characters)</label>
48
- <input type="text" name="new_user_username" id="new_user_username" maxlength="20" size="20" /> <br />
48
+ <input type="text" name="new_user_username" id="new_user_username" maxlength="20" size="20" onkeypress="var elem = document.getElementById('current_length'); elem.innerHTML = parseInt(elem.innerHTML)+1"/> <span id="current_length">0</span><br />
49
49
  <label for="new_user_password">Password</label>
50
50
  <input type="password" name="new_user_password" id="new_user_password" /> <br />
51
51
  <label for="new_user_role">Role</label>
@@ -68,9 +68,9 @@
68
68
  <fieldset>
69
69
  <legend>Preferences</legend>
70
70
  <p>Do you want to recieve our newslettter?</p>
71
- <input type="radio" name="new_user_newsletter" id="new_user_newsletter_yes" value="yes" checked="checked" class="huge" />
71
+ <input type="radio" name="new_user_newsletter" id="new_user_newsletter_yes" value="yes" checked="checked" class="huge" onclick="document.getElementById('wants_newsletter').innerHTML = ''"/>
72
72
  <label for="new_user_newsletter_yes">Yes</label>
73
- <input type="radio" name="new_user_newsletter" id="new_user_newsletter_no" value="no" title="Traitor!" />
73
+ <input type="radio" name="new_user_newsletter" id="new_user_newsletter_no" value="no" title="Traitor!" onclick="document.getElementById('wants_newsletter').innerHTML = this.title" />
74
74
  <label for="new_user_newsletter_no">No</label>
75
75
  <input type="radio" name="new_user_newsletter" value="certainly" />
76
76
  <label>Certainly</label>
@@ -86,7 +86,8 @@
86
86
  <input type="button" name="new_user_button" id="new_user_button" value="Button" onclick="this.value = 'new_value_set_by_onclick_event'" />
87
87
  <button name="new_user_button_2">Button 2</button>
88
88
  <input type="image" class="image" name="new_user_image" src="images/button.jpg" alt="Submittable button" />
89
- <input type="submit" name="new_user_submit_disabled" value="Disabled" disabled="disabled" />
89
+ <input type="submit" name="new_user_submit_disabled" id="disabled_button" value="Disabled" disabled="disabled" />
90
+ <input type="checkbox" name="new_user_submit_disabled" id="toggle_button_checkbox" onclick="var elem = document.getElementById('disabled_button'); elem.disabled = !elem.disabled" />
90
91
  </fieldset>
91
92
  </form>
92
93
  <h2>Delete user</h2>
@@ -103,5 +104,10 @@
103
104
  <input type="submit" name="delete_user_submit" id="delete_user_submit" value="Delete" />
104
105
  </fieldset>
105
106
  </form>
107
+
108
+ <!-- used for testing javascript events -->
109
+ <div id="changed_language"></div>
110
+ <div id="wants_newsletter"></div>
111
+
106
112
  </body>
107
113
  </html>
@@ -33,9 +33,10 @@
33
33
  <p>Dubito, ergo cogito, ergo sum.</p>
34
34
  <p></p>
35
35
  <pre></pre>
36
+ <div id="best_language" onclick="this.innerHTML = 'Ruby!'">What's the best programming language?</div>
36
37
  <h2>Ruby RSpec example</h2>
37
38
  <pre class="ruby" id="rspec">
38
- @ie.pre(:id, "rspec").should exist
39
+ @browser.pre(:id, "rspec").should exist
39
40
  </pre>
40
41
  <h2>PHP Hello World</h2>
41
42
  <pre class="php">
@@ -54,7 +55,7 @@
54
55
  return 0;
55
56
  }
56
57
  </pre>
57
- <h2>LISP</h2>
58
+ <h2>Haskell</h2>
58
59
  <pre class="haskell">
59
60
  main = putStrLn "Hello World"
60
61
  </pre>
@@ -77,6 +78,7 @@
77
78
  >. Print newline
78
79
  </pre>
79
80
  </div>
81
+
80
82
  <div id="footer" title="Closing remarks" class="profile">
81
83
  <span class="footer" name="footer" onclick="this.innerHTML = 'This is a footer with text set by Javascript.'">This is a footer.</span>
82
84
  </div>
data/spec/ie_spec.rb CHANGED
@@ -3,49 +3,66 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
3
3
  describe "IE" do
4
4
 
5
5
  before :all do
6
- @ie = IE.new
7
- add_spec_checker(@ie)
6
+ @browser = IE.new
7
+ add_spec_checker(@browser)
8
8
  end
9
9
 
10
10
  # Exists
11
11
  describe "#exists?" do
12
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
13
+ @browser.should_not exist
14
+ @browser.goto(TEST_HOST + "/non_control_elements.html")
15
+ @browser.should exist
16
16
  end
17
- it "should not exist after closing" do
18
- @ie.close
19
- @ie.should_not exist
17
+ it "should return false after IE#close" do
18
+ @browser.close
19
+ @browser.should_not exist
20
20
  end
21
21
  end
22
22
 
23
- # Attribute methods
24
23
  describe "#html" do
25
24
  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"')
25
+ @browser.goto(TEST_HOST + "/non_control_elements.html")
26
+ @browser.html.should == File.read(File.dirname(__FILE__) + "/html/non_control_elements.html")
28
27
  end
29
28
  end
30
29
 
31
30
  describe "#title" do
32
31
  it "should return the current page title" do
33
- @ie.goto(TEST_HOST + "/non_control_elements.html")
34
- @ie.title.should == "Non-control elements"
32
+ @browser.goto(TEST_HOST + "/non_control_elements.html")
33
+ @browser.title.should == "Non-control elements"
35
34
  end
36
35
  end
37
36
 
38
37
  describe "#text" do
39
38
  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
39
+ @browser.goto(TEST_HOST + "/non_control_elements.html")
40
+ @browser.text.include?("Dubito, ergo cogito, ergo sum.").should be_true
42
41
  end
43
42
  end
44
43
 
45
44
  describe "#url" do
46
45
  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"
46
+ @browser.goto(TEST_HOST + "/non_control_elements.html")
47
+ @browser.url.should == TEST_HOST + "/non_control_elements.html"
48
+ end
49
+ end
50
+
51
+ describe "#document" do
52
+ it "should return the underlying object" do
53
+ @browser.goto(TEST_HOST + "/non_control_elements.html")
54
+ if RUBY_PLATFORM =~ /java/
55
+ @browser.document.should be_instance_of(Java::ComGargoylesoftwareHtmlunitHtml::HtmlHtml)
56
+ else
57
+ @browser.document.should be_instance_of(WIN32OLE)
58
+ end
59
+ end
60
+ end
61
+
62
+ describe "#base_url" do
63
+ it "should return the base URL of the current page" do
64
+ @browser.goto(TEST_HOST + "/non_control_elements.html")
65
+ @browser.base_url.should == "http://localhost"
49
66
  end
50
67
  end
51
68
 
@@ -53,74 +70,91 @@ describe "IE" do
53
70
  # Manipulation methods
54
71
  describe ".start" do
55
72
  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"
73
+ @browser = Celerity::IE.start(TEST_HOST + "/non_control_elements.html")
74
+ @browser.should be_instance_of(Celerity::IE)
75
+ @browser.title.should == "Non-control elements"
59
76
  end
60
77
  end
61
78
 
62
79
  describe "#goto" do
63
80
  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
81
+ lambda { @browser.goto(TEST_HOST + "/non_control_elements.html") }.should_not raise_error
65
82
  end
66
83
  end
67
84
 
68
85
  describe "#refresh" do
69
86
  it "should refresh the page" do
70
- @ie.refresh
87
+ @browser.goto(TEST_HOST + "/non_control_elements.html")
88
+ @browser.span(:name, 'footer').click
89
+ @browser.span(:name, 'footer').text.should include('Javascript')
90
+ @browser.refresh
91
+ @browser.span(:name, 'footer').text.should_not include('Javascript')
92
+ end
93
+ end
94
+
95
+ describe "#execute_script" do
96
+ it "should execute the given JavaScript on the current page" do
97
+ @browser.goto(TEST_HOST + "/non_control_elements.html")
98
+ @browser.pre(:id, 'rspec').text.should_not == "javascript text"
99
+ @browser.execute_script("document.getElementById('rspec').innerHTML = 'javascript text'")
100
+ @browser.pre(:id, 'rspec').text.should == "javascript text"
71
101
  end
72
102
  end
73
103
 
74
104
  describe "#back" do
75
105
  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
106
+ @browser.goto(TEST_HOST + "/non_control_elements.html")
107
+ orig_url = @browser.url
108
+ @browser.goto(TEST_HOST + "/tables.html")
109
+ new_url = @browser.url
80
110
  orig_url.should_not == new_url
81
- @ie.back
82
- orig_url.should == @ie.url
111
+ @browser.back
112
+ orig_url.should == @browser.url
83
113
  end
84
114
  end
85
115
 
86
116
  # Other
87
117
  describe "#contains_text" do
88
118
  before :each do
89
- @ie.goto(TEST_HOST + "/non_control_elements.html")
119
+ @browser.goto(TEST_HOST + "/non_control_elements.html")
90
120
  end
121
+
91
122
  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)
123
+ lambda { @browser.contains_text }.should raise_error(ArgumentError)
124
+ lambda { @browser.contains_text(nil) }.should raise_error(ArgumentError)
125
+ lambda { @browser.contains_text(42) }.should raise_error(ArgumentError)
95
126
  end
127
+
96
128
  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
129
+ @browser.contains_text('Dubito, ergo cogito, ergo sum.').should be_instance_of(Fixnum)
130
+ @browser.contains_text(/Dubito.*sum./).should_not be_nil
99
131
  end
132
+
100
133
  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
134
+ @browser.contains_text('no_such_text').should be_nil
135
+ @browser.contains_text(/no_such_text/).should be_nil
103
136
  end
137
+
104
138
  it "should not raise error on a blank page" do
105
- @ie = IE.new
106
- lambda { @ie.contains_text('') }.should_not raise_error
139
+ @browser = IE.new
140
+ lambda { @browser.contains_text('') }.should_not raise_error
107
141
  end
108
142
  end
109
143
 
110
144
  describe "#add_checker" do
111
145
  it "should raise ArgumentError when not given any arguments" do
112
- lambda { @ie.add_checker }.should raise_error(ArgumentError)
146
+ lambda { @browser.add_checker }.should raise_error(ArgumentError)
113
147
  end
114
148
  it "should run the given proc on each page load" do
115
149
  output = ''
116
- @ie.add_checker(Proc.new { |ie| output << ie.text })
117
- @ie.goto(TEST_HOST + "/non_control_elements.html")
150
+ @browser.add_checker(Proc.new { |ie| output << ie.text })
151
+ @browser.goto(TEST_HOST + "/non_control_elements.html")
118
152
  output.should include('Dubito, ergo cogito, ergo sum')
119
153
  end
120
154
  it "should run the given block on each page load" do
121
155
  output = ''
122
- @ie.add_checker { |ie| output << ie.text }
123
- @ie.goto(TEST_HOST + "/non_control_elements.html")
156
+ @browser.add_checker { |ie| output << ie.text }
157
+ @browser.goto(TEST_HOST + "/non_control_elements.html")
124
158
  output.should include('Dubito, ergo cogito, ergo sum')
125
159
  end
126
160
  end
@@ -129,18 +163,18 @@ describe "IE" do
129
163
  it "should remove a previously added checker" do
130
164
  output = ''
131
165
  checker = lambda { |ie| output << ie.text }
132
- @ie.add_checker(checker)
133
- @ie.goto(TEST_HOST + "/non_control_elements.html")
166
+ @browser.add_checker(checker)
167
+ @browser.goto(TEST_HOST + "/non_control_elements.html")
134
168
  output.should include('Dubito, ergo cogito, ergo sum')
135
169
 
136
- @ie.disable_checker(checker)
137
- @ie.goto(TEST_HOST + "/non_control_elements.html")
170
+ @browser.disable_checker(checker)
171
+ @browser.goto(TEST_HOST + "/non_control_elements.html")
138
172
  output.should include('Dubito, ergo cogito, ergo sum')
139
173
  end
140
174
  end
141
175
 
142
176
  after :all do
143
- @ie.close
177
+ @browser.close
144
178
  end
145
179
 
146
180
  end
data/spec/image_spec.rb CHANGED
@@ -1,210 +1,193 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
3
  describe "Image" do
4
-
4
+
5
5
  before :all do
6
- @ie = IE.new
7
- add_spec_checker(@ie)
6
+ @browser = IE.new
7
+ add_spec_checker(@browser)
8
8
  end
9
9
 
10
10
  before :each do
11
- @ie.goto(TEST_HOST + "/images.html")
11
+ @browser.goto(TEST_HOST + "/images.html")
12
12
  end
13
-
13
+
14
14
  # Exists method
15
15
  describe "#exists" do
16
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
17
+ @browser.image(:id, 'square').should exist
18
+ @browser.image(:id, /square/).should exist
19
+ @browser.image(:name, 'circle').should exist
20
+ @browser.image(:name, /circle/).should exist
21
+ @browser.image(:src, 'images/circle.jpg').should exist
22
+ @browser.image(:src, /circle/).should exist
23
+ @browser.image(:alt, 'circle').should exist
24
+ @browser.image(:alt, /cir/).should exist
25
+ @browser.image(:title, 'Circle').should exist
26
26
  end
27
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
28
+ @browser.image(:id, 'no_such_id').should_not exist
29
+ @browser.image(:id, /no_such_id/).should_not exist
30
+ @browser.image(:name, 'no_such_name').should_not exist
31
+ @browser.image(:name, /no_such_name/).should_not exist
32
+ @browser.image(:src, 'no_such_src').should_not exist
33
+ @browser.image(:src, /no_such_src/).should_not exist
34
+ @browser.image(:alt, 'no_such_alt').should_not exist
35
+ @browser.image(:alt, /no_such_alt/).should_not exist
36
+ @browser.image(:title, 'no_such_title').should_not exist
37
+ @browser.image(:title, /no_such_title/).should_not exist
38
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)
39
+ it "should raise ArgumentError when 'what' argument is invalid" do
40
+ lambda { @browser.button(:id, 3.14).exists? }.should raise_error(ArgumentError)
41
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)
42
+ it "should raise MissingWayOfFindingObjectException when 'how' argument is invalid" do
43
+ lambda { @browser.button(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
44
44
  end
45
45
  end
46
-
46
+
47
47
  # Attribute methods
48
48
  describe "#alt" do
49
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'
50
+ @browser.image(:name, 'square').alt.should == "square"
51
+ @browser.image(:name, 'circle').alt.should == 'circle'
52
52
  end
53
53
  it "should return an empty string if the image exists and the attribute doesn't" do
54
- @ie.image(:index, 1).alt.should == ""
54
+ @browser.image(:index, 1).alt.should == ""
55
55
  end
56
56
  it "should raise UnknownObjectException if the image doesn't exist" do
57
- lambda { @ie.image(:index, 1337).alt }.should raise_error(UnknownObjectException)
57
+ lambda { @browser.image(:index, 1337).alt }.should raise_error(UnknownObjectException)
58
58
  end
59
59
  end
60
-
60
+
61
61
  describe "#id" do
62
62
  it "should return the id attribute of the image if the image exists" do
63
- @ie.image(:name, 'square').id.should == 'square'
63
+ @browser.image(:name, 'square').id.should == 'square'
64
64
  end
65
65
  it "should return an empty string if the image exists and the attribute doesn't" do
66
- @ie.image(:index, 1).id.should == ""
66
+ @browser.image(:index, 1).id.should == ""
67
67
  end
68
68
  it "should raise UnknownObjectException if the image doesn't exist" do
69
- lambda { @ie.image(:index, 1337).id }.should raise_error(UnknownObjectException)
69
+ lambda { @browser.image(:index, 1337).id }.should raise_error(UnknownObjectException)
70
70
  end
71
71
  end
72
-
72
+
73
73
  describe "#name" do
74
74
  it "should return the name attribute of the image if the image exists" do
75
- @ie.image(:name, 'square').name.should == 'square'
75
+ @browser.image(:name, 'square').name.should == 'square'
76
76
  end
77
77
  it "should return an empty string if the image exists and the attribute doesn't" do
78
- @ie.image(:index, 1).name.should == ""
78
+ @browser.image(:index, 1).name.should == ""
79
79
  end
80
80
  it "should raise UnknownObjectException if the image doesn't exist" do
81
- lambda { @ie.image(:index, 1337).name }.should raise_error(UnknownObjectException)
81
+ lambda { @browser.image(:index, 1337).name }.should raise_error(UnknownObjectException)
82
82
  end
83
83
  end
84
-
84
+
85
85
  describe "#src" do
86
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)
87
+ @browser.image(:name, 'square').src.should match(/square\.jpg/i)
88
88
  end
89
89
  it "should return an empty string if the image exists and the attribute doesn't" do
90
- @ie.image(:index, 1).src.should == ""
90
+ @browser.image(:index, 1).src.should == ""
91
91
  end
92
92
  it "should raise UnknownObjectException if the image doesn't exist" do
93
- lambda { @ie.image(:index, 1337).src }.should raise_error(UnknownObjectException)
93
+ lambda { @browser.image(:index, 1337).src }.should raise_error(UnknownObjectException)
94
94
  end
95
95
  end
96
-
96
+
97
97
  describe "#title" do
98
98
  it "should return the title attribute of the image if the image exists" do
99
- @ie.image(:id, 'square').title.should == 'Square'
99
+ @browser.image(:id, 'square').title.should == 'Square'
100
100
  end
101
101
  it "should return an empty string if the image exists and the attribute doesn't" do
102
- @ie.image(:index, 1).title.should == ""
102
+ @browser.image(:index, 1).title.should == ""
103
103
  end
104
104
  it "should raise UnknownObjectException if the image doesn't exist" do
105
- lambda { @ie.image(:index, 1337).title }.should raise_error(UnknownObjectException)
105
+ lambda { @browser.image(:index, 1337).title }.should raise_error(UnknownObjectException)
106
106
  end
107
107
  end
108
-
108
+
109
109
  # Manipulation methods
110
110
  describe "#click" do
111
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)
112
+ lambda { @browser.image(:id, 'missing_attribute').click }.should raise_error(UnknownObjectException)
113
+ lambda { @browser.image(:name, 'missing_attribute').click }.should raise_error(UnknownObjectException)
114
+ lambda { @browser.image(:src, 'missing_attribute').click }.should raise_error(UnknownObjectException)
115
+ lambda { @browser.image(:alt, 'missing_attribute').click }.should raise_error(UnknownObjectException)
116
116
  end
117
117
  end
118
-
118
+
119
119
  # File methods
120
120
  describe "#file_created_date" do
121
121
  it "should return the date the image was created as reported by the file system" do
122
- image = @ie.image(:index, 2)
122
+ image = @browser.image(:index, 2)
123
123
  path = File.dirname(__FILE__) + "/html/#{image.src}"
124
124
  image.file_created_date.to_i.should == File.mtime(path).to_i
125
125
  end
126
126
  end
127
-
128
- describe "#file_size" do
127
+
128
+ describe "#file_size" do
129
129
  it "should return the file size of the image if the image exists" do
130
- @ie.image(:id, 'square').file_size.should == 788
130
+ @browser.image(:id, 'square').file_size.should == 788
131
131
  end
132
132
  it "should raise UnknownObjectException if the image doesn't exist" do
133
- lambda { @ie.image(:index, 1337).file_size }.should raise_error(UnknownObjectException)
133
+ lambda { @browser.image(:index, 1337).file_size }.should raise_error(UnknownObjectException)
134
134
  end
135
135
  end
136
136
 
137
137
  describe "#height" do
138
138
  it "should return the height of the image if the image exists" do
139
- @ie.image(:id, 'square').height.should == 88
139
+ @browser.image(:id, 'square').height.should == 88
140
140
  end
141
141
  it "should raise UnknownObjectException if the image doesn't exist" do
142
- lambda { @ie.image(:index, 1337).height }.should raise_error(UnknownObjectException)
142
+ lambda { @browser.image(:index, 1337).height }.should raise_error(UnknownObjectException)
143
143
  end
144
144
  end
145
-
145
+
146
146
  describe "#width" do
147
147
  it "should return the width of the image if the image exists" do
148
- @ie.image(:id, 'square').width.should == 88
148
+ @browser.image(:id, 'square').width.should == 88
149
149
  end
150
150
  it "should raise UnknownObjectException if the image doesn't exist" do
151
- lambda { @ie.image(:index, 1337).width }.should raise_error(UnknownObjectException)
151
+ lambda { @browser.image(:index, 1337).width }.should raise_error(UnknownObjectException)
152
152
  end
153
153
  end
154
-
154
+
155
155
  # Other
156
156
  describe "#loaded?" do
157
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
158
+ @browser.image(:name, 'circle').should be_loaded
159
+ @browser.image(:alt, 'circle').should be_loaded
160
+ @browser.image(:alt, /circle/).should be_loaded
161
161
  end
162
162
  it "should return false if the image has not been loaded" do
163
- @ie.image(:id, 'no_such_file').should_not be_loaded
163
+ @browser.image(:id, 'no_such_file').should_not be_loaded
164
164
  end
165
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)
166
+ lambda { @browser.image(:name, 'no_such_image').loaded? }.should raise_error(UnknownObjectException)
167
+ lambda { @browser.image(:id, 'no_such_image').loaded? }.should raise_error(UnknownObjectException)
168
+ lambda { @browser.image(:src, 'no_such_image').loaded? }.should raise_error(UnknownObjectException)
169
+ lambda { @browser.image(:alt, 'no_such_image').loaded? }.should raise_error(UnknownObjectException)
170
+ lambda { @browser.image(:index, 1337).loaded? }.should raise_error(UnknownObjectException)
171
171
  end
172
172
  end
173
-
173
+
174
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" />'
175
+ it "should return the image element as a string of html" do
176
+ @browser.image(:id, 'triangle').html.chomp.should == '<img src="images/triangle.jpg" id="triangle" usemap="#triangle_map" />'
177
177
  end
178
178
  end
179
-
179
+
180
180
  describe "#save" do
181
181
  it "should save an image to file" do
182
182
  file = "sample.img.dat"
183
- @ie.image(:index, 2).save(file)
184
- File.exist?(file).should be_true
183
+ @browser.image(:index, 2).save(file)
184
+ File.exist?(file).should be_true
185
185
  File.delete(file)
186
186
  end
187
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
-
188
+
206
189
  after :all do
207
- @ie.close
190
+ @browser.close
208
191
  end
209
192
 
210
193
  end