rwebunit 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,212 +7,211 @@ require 'test/unit'
7
7
 
8
8
  module RWebUnit
9
9
 
10
- class WebTestCase < Test::Unit::TestCase
11
- include RWebUnit::Utils
10
+ class WebTestCase < Test::Unit::TestCase
11
+ include RWebUnit::Utils
12
12
 
13
- attr_reader :web_tester
14
-
15
- def initialize(name=nil)
16
- super(name) if name
17
- @web_tester = WebTester.new
18
- end
13
+ attr_reader :web_tester
14
+
15
+ def initialize(name=nil)
16
+ super(name) if name
17
+ @web_tester = WebTester.new
18
+ end
19
19
 
20
- def default_test
21
- super unless(self.class == WebTestCase)
22
- end
20
+ def default_test
21
+ super unless(self.class == WebTestCase)
22
+ end
23
23
 
24
- def getTestContext
25
- @web_tester.test_context
26
- end
27
-
28
- def beginAt(url)
29
- @web_tester.beginAt(url)
30
- end
31
-
32
- def openBrowser(baseUrl, relativeUrl)
33
- getTestContext().base_url = baseUrl
34
- beginAt(relativeUrl)
35
- end
36
-
37
- def closeBrowser
38
- @web_tester.closeBrowser
39
- end
40
-
41
- def goBack()
42
- @web_tester.goBack
43
- end
44
-
45
- def goForward()
46
- @web_tester.goForward
47
- end
48
-
49
- def gotoPage(page)
50
- @web_tester.gotoPage(page)
51
- end
52
-
53
- # assertions
54
- def assertTitleEquals(title)
55
- @web_tester.assertTitleEquals(title)
56
- end
57
-
58
- def assertTextPresent(text)
59
- @web_tester.assertTextPresent(text)
60
- end
61
-
62
- def assertTextNotPresent(text)
63
- @web_tester.assertTextNotPresent(text)
64
- end
65
-
66
- def assertTextInTable(tableId, text)
67
- @web_tester.assertTextInTable(tableId, text)
68
- end
69
-
70
- def assertTextNotInTable(tableId, text)
71
- @web_tester.assertTextNotInTable(tableId, text)
72
- end
73
-
74
- # textfields
75
- def setFormElement(elementName, elementValue)
76
- @web_tester.setFormElement(elementName, elementValue)
77
- end
78
-
79
- def assertTextPresentInTextField(textfieldName, text, msg = nil)
80
- @web_tester.assertTextPresentInTextField(textfieldName, text, msg)
81
- end
82
-
83
- #links
84
- def clickLinkWithText(linkText)
85
- @web_tester.clickLinkWithText(linkText)
86
- end
87
-
88
- def assertLinkPresentWithText(linkText)
89
- @web_tester.assertLinkPresentWithText(linkText)
90
- end
91
-
92
- def assertLinkNotPresentWithText(linkText)
93
- @web_tester.assertLinkNotPresentWithText(linkText)
94
- end
95
-
96
- ##
97
- # buttons
98
-
99
- # submit the form using the first (index) submit button
100
- def submit()
101
- @web_tester.submit()
102
- end
103
-
104
- def submit(buttonId)
105
- @web_tester.submit(buttonId)
106
- end
107
-
108
- def clickButton(buttonId)
109
- @web_tester.clickButton(buttonId)
110
- end
111
-
112
- def clickButtonWithCaption(caption)
113
- @web_tester.clickButtonWithCaption(caption)
114
- end
115
-
116
- def clickButtonWithValue(value)
117
- @web_tester.clickButtonWithValue(value)
118
- end
119
-
120
- def assertButtonNotPresent(buttonID)
121
- @web_tester.assertButtonNotPresent(buttonID)
122
- end
123
-
124
- def assertButtonNotPresentWithText(text)
125
- @web_tester.assertButtonNotPresentWithText(text)
126
- end
127
-
128
- def assertButtonPresent(buttonID)
129
- @web_tester.assertButtonPresent(buttonID)
130
- end
131
-
132
- def assertButtonPresentWithText(buttonID)
133
- @web_tester.assertButtonPresentWithText(buttonID)
134
- end
135
-
136
- # checkbox
137
- def checkCheckbox(checkBoxName)
138
- @web_tester.checkCheckbox(checkBoxName)
139
- end
140
-
141
- def uncheckCheckbox(checkBoxName)
142
- @web_tester.uncheckCheckbox(checkBoxName)
143
- end
144
-
145
- def assertCheckboxNotSelected(checkBoxName)
146
- @web_tester.assertCheckboxNotSelected(checkBoxName)
147
- end
148
-
149
- def assertCheckboxSelected(checkBoxName)
150
- @web_tester.assertCheckboxSelected(checkBoxName)
151
- end
152
-
153
- # radio button
154
- def assertRadioOptionNotPresent(radioGroup, radioOption)
155
- @web_tester.assertRadioOptionNotPresent(radioGroup, radioOption)
156
- end
157
-
158
- def assertRadioOptionPresent(radioGroup, radioOption)
159
- @web_tester.assertRadioOptionPresent(radioGroup, radioOption)
160
- end
161
-
162
- def assertRadioOptionSelected(radioGroup, radioOption)
163
- @web_tester.assertRadioOptionSelected(radioGroup, radioOption)
164
- end
165
-
166
- def assertRadioOptionNotSelected(radioGroup, radioOption)
167
- @web_tester.assertRadioOptionNotSelected(radioGroup, radioOption)
168
- end
169
-
170
- # combo box
171
- def selectOption(selectName, option)
172
- @web_tester.selectOption(selectName, option)
173
- end
174
-
175
- # dhtml related
176
- def assertElementPresent(elementID)
177
- @web_tester.assertElementPresent(elementID)
178
- end
179
-
180
- def assertElementNotPresent(elementID)
181
- @web_tester.assertElementNotPresent(elementID)
182
- end
183
-
184
- # Wait for specific seconds for an Ajax update finish.
185
- # Trick: In your Rails application,
186
- # :loading => "Element.show('search_indicator');
187
- # :complete => "Element.hide('search_indicator');
188
- #
189
- # <%= image_tag("indicator.gif", :id => 'search_indicator', :style => 'display:none') %>
190
- #
191
- # In your test case:
192
- # wait_ajax_update(ie, 30, "search_indicator", "Indicator", "/images/indicator.gif")
193
- # or
194
- # wait_ajax_update(ie, 30, "search_indicator")
195
- #
196
- # Warning: this method has not been fully tested, if you are not using Rails, change your parameter accordingly.
197
- #
198
- def wait_ajax_update(ie, seconds, indicator_image_id, indicator_alt_text = "Indicator", indicator_image_url = "/images/indicator.gif")
199
- return if seconds < 1
200
- seconds.times do
201
- html_content = ie.html()
202
- indicator_image_html_fragment = '<IMG id=' + indicator_image_id + ' style="DISPLAY: none" alt=' + indicator_alt_text +' src="' + indicator_image_url + '">'
203
- puts "checking #{indicator_image_html_fragment}" if $DEBUG
204
- return if html_content.include? indicator_image_html_fragment
205
- sleep 1;
206
- end
207
- end
208
-
209
- # ---
210
- # For deubgging
211
- # ---
212
- def dumpResponse(stream = nil)
213
- @web_tester.dumpResponse(stream)
214
- end
24
+ def getTestContext
25
+ @web_tester.test_context
26
+ end
215
27
 
216
- end
28
+ def beginAt(url)
29
+ @web_tester.beginAt(url)
30
+ end
31
+
32
+ def openBrowser(baseUrl, relativeUrl)
33
+ getTestContext().base_url = baseUrl
34
+ beginAt(relativeUrl)
35
+ end
36
+
37
+ def closeBrowser
38
+ @web_tester.closeBrowser
39
+ end
40
+
41
+ def goBack()
42
+ @web_tester.goBack
43
+ end
217
44
 
218
- end
45
+ def goForward()
46
+ @web_tester.goForward
47
+ end
48
+
49
+ def gotoPage(page)
50
+ @web_tester.gotoPage(page)
51
+ end
52
+
53
+ # assertions
54
+ def assertTitleEquals(title)
55
+ @web_tester.assertTitleEquals(title)
56
+ end
57
+
58
+ def assertTextPresent(text)
59
+ @web_tester.assertTextPresent(text)
60
+ end
61
+
62
+ def assertTextNotPresent(text)
63
+ @web_tester.assertTextNotPresent(text)
64
+ end
65
+
66
+ def assertTextInTable(tableId, text)
67
+ @web_tester.assertTextInTable(tableId, text)
68
+ end
69
+
70
+ def assertTextNotInTable(tableId, text)
71
+ @web_tester.assertTextNotInTable(tableId, text)
72
+ end
73
+
74
+ # textfields
75
+ def setFormElement(elementName, elementValue)
76
+ @web_tester.setFormElement(elementName, elementValue)
77
+ end
78
+
79
+ def assertTextPresentInTextField(textfieldName, text, msg = nil)
80
+ @web_tester.assertTextPresentInTextField(textfieldName, text, msg)
81
+ end
82
+
83
+ #links
84
+ def clickLinkWithText(linkText)
85
+ @web_tester.clickLinkWithText(linkText)
86
+ end
87
+
88
+ def assertLinkPresentWithText(linkText)
89
+ @web_tester.assertLinkPresentWithText(linkText)
90
+ end
91
+
92
+ def assertLinkNotPresentWithText(linkText)
93
+ @web_tester.assertLinkNotPresentWithText(linkText)
94
+ end
95
+
96
+ ##
97
+ # buttons
98
+
99
+ # submit the form using the first (index) submit button
100
+ def submit()
101
+ @web_tester.submit()
102
+ end
103
+
104
+ def submit(buttonId)
105
+ @web_tester.submit(buttonId)
106
+ end
107
+
108
+ def clickButton(buttonId)
109
+ @web_tester.clickButton(buttonId)
110
+ end
111
+
112
+ def clickButtonWithCaption(caption)
113
+ @web_tester.clickButtonWithCaption(caption)
114
+ end
115
+
116
+ def clickButtonWithValue(value)
117
+ @web_tester.clickButtonWithValue(value)
118
+ end
119
+
120
+ def assertButtonNotPresent(buttonID)
121
+ @web_tester.assertButtonNotPresent(buttonID)
122
+ end
123
+
124
+ def assertButtonNotPresentWithText(text)
125
+ @web_tester.assertButtonNotPresentWithText(text)
126
+ end
127
+
128
+ def assertButtonPresent(buttonID)
129
+ @web_tester.assertButtonPresent(buttonID)
130
+ end
131
+
132
+ def assertButtonPresentWithText(buttonID)
133
+ @web_tester.assertButtonPresentWithText(buttonID)
134
+ end
135
+
136
+ # checkbox
137
+ def checkCheckbox(checkBoxName)
138
+ @web_tester.checkCheckbox(checkBoxName)
139
+ end
140
+
141
+ def uncheckCheckbox(checkBoxName)
142
+ @web_tester.uncheckCheckbox(checkBoxName)
143
+ end
144
+
145
+ def assertCheckboxNotSelected(checkBoxName)
146
+ @web_tester.assertCheckboxNotSelected(checkBoxName)
147
+ end
148
+
149
+ def assertCheckboxSelected(checkBoxName)
150
+ @web_tester.assertCheckboxSelected(checkBoxName)
151
+ end
152
+
153
+ # radio button
154
+ def assertRadioOptionNotPresent(radioGroup, radioOption)
155
+ @web_tester.assertRadioOptionNotPresent(radioGroup, radioOption)
156
+ end
157
+
158
+ def assertRadioOptionPresent(radioGroup, radioOption)
159
+ @web_tester.assertRadioOptionPresent(radioGroup, radioOption)
160
+ end
161
+
162
+ def assertRadioOptionSelected(radioGroup, radioOption)
163
+ @web_tester.assertRadioOptionSelected(radioGroup, radioOption)
164
+ end
165
+
166
+ def assertRadioOptionNotSelected(radioGroup, radioOption)
167
+ @web_tester.assertRadioOptionNotSelected(radioGroup, radioOption)
168
+ end
169
+
170
+ # combo box
171
+ def selectOption(selectName, option)
172
+ @web_tester.selectOption(selectName, option)
173
+ end
174
+
175
+ # dhtml related
176
+ def assertElementPresent(elementID)
177
+ @web_tester.assertElementPresent(elementID)
178
+ end
179
+
180
+ def assertElementNotPresent(elementID)
181
+ @web_tester.assertElementNotPresent(elementID)
182
+ end
183
+
184
+ # Wait for specific seconds for an Ajax update finish.
185
+ # Trick: In your Rails application,
186
+ # :loading => "Element.show('search_indicator');
187
+ # :complete => "Element.hide('search_indicator');
188
+ #
189
+ # <%= image_tag("indicator.gif", :id => 'search_indicator', :style => 'display:none') %>
190
+ #
191
+ # In your test case:
192
+ # wait_ajax_update("search_indicator", "30)
193
+ #
194
+ # Warning: this method has not been fully tested, if you are not using Rails, change your parameter accordingly.
195
+ #
196
+ def wait_ajax_update(element_id, seconds)
197
+ count = 0
198
+ while count < (seconds / 2) do
199
+ search_indicator = @web_tester.getElementById(element_id)
200
+ search_indicator_outer_html = search_indicator.outerHtml if search_indicator
201
+ return true if search_indicator_outer_html && search_indicator_outer_html.include?('style="DISPLAY: none"')
202
+ sleep 2;
203
+ count = count + 1
204
+ end
205
+ return false
206
+ end
207
+
208
+ # ---
209
+ # For deubgging
210
+ # ---
211
+ def dumpResponse(stream = nil)
212
+ @web_tester.dumpResponse(stream)
213
+ end
214
+
215
+ end
216
+
217
+ end