|
1 /* |
|
2 * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 import com.sun.swingset3.demos.optionpane.OptionPaneDemo; |
|
25 import static com.sun.swingset3.demos.optionpane.OptionPaneDemo.*; |
|
26 import javax.swing.UIManager; |
|
27 import static org.jemmy2ext.JemmyExt.*; |
|
28 import static org.testng.AssertJUnit.*; |
|
29 import org.testng.annotations.Test; |
|
30 import org.netbeans.jemmy.ClassReference; |
|
31 import org.netbeans.jemmy.operators.JButtonOperator; |
|
32 import org.netbeans.jemmy.operators.JComboBoxOperator; |
|
33 import org.netbeans.jemmy.operators.JDialogOperator; |
|
34 import org.netbeans.jemmy.operators.JFrameOperator; |
|
35 import org.netbeans.jemmy.operators.JLabelOperator; |
|
36 import org.netbeans.jemmy.operators.JTextFieldOperator; |
|
37 |
|
38 |
|
39 /* |
|
40 * @test |
|
41 * @key headful |
|
42 * @summary Verifies SwingSet3 OptionPaneDemo page by opening all the dialogs |
|
43 * and choosing different options in them. |
|
44 * |
|
45 * @library /sanity/client/lib/jemmy/src |
|
46 * @library /sanity/client/lib/Jemmy2Ext/src |
|
47 * @library /sanity/client/lib/SwingSet3/src |
|
48 * @build org.jemmy2ext.JemmyExt |
|
49 * @build com.sun.swingset3.demos.optionpane.OptionPaneDemo |
|
50 * @run testng OptionPaneDemoTest |
|
51 */ |
|
52 public class OptionPaneDemoTest { |
|
53 |
|
54 public static final String SOME_TEXT_TO_TYPE = "I am some text"; |
|
55 public static final String MESSAGE = UIManager.getString("OptionPane.messageDialogTitle"); |
|
56 public static final String OK = "OK"; |
|
57 public static final String CANCEL = "Cancel"; |
|
58 public static final String INPUT = UIManager.getString("OptionPane.inputDialogTitle"); |
|
59 public static final String TEXT_TO_TYPE = "Hooray! I'm a textField"; |
|
60 public static final String NO = "No"; |
|
61 public static final String YES = "Yes"; |
|
62 public static final String SELECT_AN__OPTION = UIManager.getString("OptionPane.titleText"); |
|
63 |
|
64 @Test |
|
65 public void test() throws Exception { |
|
66 captureDebugInfoOnFail(() -> { |
|
67 new ClassReference(OptionPaneDemo.class.getCanonicalName()).startApplication(); |
|
68 |
|
69 JFrameOperator frame = new JFrameOperator(DEMO_TITLE); |
|
70 |
|
71 showInputDialog(frame); |
|
72 showWarningDialog(frame); |
|
73 showMessageDialog(frame); |
|
74 showComponentDialog(frame); |
|
75 showConfirmationDialog(frame); |
|
76 }); |
|
77 } |
|
78 |
|
79 public void showInputDialog(JFrameOperator jfo) throws Exception { |
|
80 // Cancel with text case |
|
81 { |
|
82 new JButtonOperator(jfo, INPUT_BUTTON).pushNoBlock(); |
|
83 |
|
84 JDialogOperator jdo = new JDialogOperator(INPUT); |
|
85 JTextFieldOperator jto = new JTextFieldOperator(jdo); |
|
86 jto.setText(SOME_TEXT_TO_TYPE); |
|
87 |
|
88 assertTrue("Show Input Dialog cancel w/ Text", jdo.isShowing()); |
|
89 |
|
90 new JButtonOperator(jdo, CANCEL).push(); |
|
91 |
|
92 assertFalse("Show Input Dialog cancel w/ Text", jdo.isShowing()); |
|
93 } |
|
94 |
|
95 // Cancel with *NO* text case |
|
96 { |
|
97 new JButtonOperator(jfo, INPUT_BUTTON).pushNoBlock(); |
|
98 |
|
99 JDialogOperator jdo = new JDialogOperator(INPUT); |
|
100 |
|
101 assertTrue("Show Input Dialog cancel w/o Text", jdo.isShowing()); |
|
102 |
|
103 new JButtonOperator(jdo, CANCEL).push(); |
|
104 |
|
105 assertFalse("Show Input Dialog cancel w/o Text", jdo.isShowing()); |
|
106 } |
|
107 |
|
108 // Text field has *NO* input |
|
109 { |
|
110 new JButtonOperator(jfo, INPUT_BUTTON).pushNoBlock(); |
|
111 |
|
112 JDialogOperator jdo = new JDialogOperator(INPUT); |
|
113 |
|
114 assertTrue("Show Input Dialog w/o Input", jdo.isShowing()); |
|
115 |
|
116 new JButtonOperator(jdo, OK).push(); |
|
117 |
|
118 assertFalse("Show Input Dialog w/o Input", jdo.isShowing()); |
|
119 } |
|
120 |
|
121 // Text field has input |
|
122 { |
|
123 final String enteredText = "Rambo"; |
|
124 |
|
125 new JButtonOperator(jfo, INPUT_BUTTON).pushNoBlock(); |
|
126 |
|
127 JDialogOperator jdo = new JDialogOperator(INPUT); |
|
128 JTextFieldOperator jto = new JTextFieldOperator(jdo); |
|
129 jto.setText(enteredText); |
|
130 new JButtonOperator(jdo, OK).pushNoBlock(); |
|
131 |
|
132 JDialogOperator jdo1 = new JDialogOperator(MESSAGE); |
|
133 |
|
134 assertTrue("Show Input Dialog w/ Input", jdo1.isShowing()); |
|
135 |
|
136 final String labelText = enteredText + INPUT_RESPONSE; |
|
137 JLabelOperator jLabelOperator = new JLabelOperator(jdo1, labelText); |
|
138 assertEquals("Text from the field made it into the dialog", labelText, jLabelOperator.getText()); |
|
139 |
|
140 new JButtonOperator(jdo1, OK).push(); |
|
141 |
|
142 assertFalse("Show Input Dialog w/ Input", jdo1.isShowing()); |
|
143 } |
|
144 } |
|
145 |
|
146 public void showWarningDialog(JFrameOperator jfo) throws Exception { |
|
147 new JButtonOperator(jfo, WARNING_BUTTON).pushNoBlock(); |
|
148 |
|
149 JDialogOperator jdo = new JDialogOperator(WARNING_TITLE); |
|
150 |
|
151 assertTrue("Show Warning Dialog", jdo.isShowing()); |
|
152 |
|
153 new JButtonOperator(jdo, OK).push(); |
|
154 |
|
155 assertFalse("Show Warning Dialog", jdo.isShowing()); |
|
156 } |
|
157 |
|
158 public void showMessageDialog(JFrameOperator jfo) throws Exception { |
|
159 new JButtonOperator(jfo, MESSAGE_BUTTON).pushNoBlock(); |
|
160 |
|
161 JDialogOperator jdo = new JDialogOperator(MESSAGE); |
|
162 |
|
163 assertTrue("Show Message Dialog", jdo.isShowing()); |
|
164 |
|
165 new JButtonOperator(jdo, OK).push(); |
|
166 |
|
167 assertFalse("Show Message Dialog", jdo.isShowing()); |
|
168 } |
|
169 |
|
170 public void showComponentDialog(JFrameOperator jfo) throws Exception { |
|
171 // Case: Cancel |
|
172 { |
|
173 new JButtonOperator(jfo, COMPONENT_BUTTON).pushNoBlock(); |
|
174 |
|
175 JDialogOperator jdo = new JDialogOperator(COMPONENT_TITLE); |
|
176 |
|
177 assertTrue("Show Component Dialog Cancel Option", jdo.isShowing()); |
|
178 |
|
179 new JButtonOperator(jdo, COMPONENT_OP5).push(); |
|
180 |
|
181 assertFalse("Show Component Dialog Cancel Option", jdo.isShowing()); |
|
182 } |
|
183 |
|
184 // Case: Yes option selected |
|
185 { |
|
186 new JButtonOperator(jfo, COMPONENT_BUTTON).pushNoBlock(); |
|
187 |
|
188 JDialogOperator jdo = new JDialogOperator(COMPONENT_TITLE); |
|
189 new JButtonOperator(jdo, COMPONENT_OP1).pushNoBlock(); |
|
190 |
|
191 JDialogOperator jdo1 = new JDialogOperator(MESSAGE); |
|
192 |
|
193 assertTrue("Component Dialog Example Yes Option", jdo1.isShowing()); |
|
194 |
|
195 final String labelText = COMPONENT_R1; |
|
196 JLabelOperator jLabelOperator = new JLabelOperator(jdo1, labelText); |
|
197 assertEquals("Dialog contains appropriate text", labelText, jLabelOperator.getText()); |
|
198 |
|
199 new JButtonOperator(jdo1, OK).push(); |
|
200 |
|
201 assertFalse("Component Dialog Example Yes Option", jdo1.isShowing()); |
|
202 } |
|
203 |
|
204 // Case: No option selected |
|
205 { |
|
206 new JButtonOperator(jfo, COMPONENT_BUTTON).pushNoBlock(); |
|
207 |
|
208 JDialogOperator jdo = new JDialogOperator(COMPONENT_TITLE); |
|
209 new JButtonOperator(jdo, COMPONENT_OP2).pushNoBlock(); |
|
210 |
|
211 JDialogOperator jdo1 = new JDialogOperator(MESSAGE); |
|
212 |
|
213 assertTrue("Component Dialog Example No Option", jdo1.isShowing()); |
|
214 |
|
215 final String labelText = COMPONENT_R2; |
|
216 JLabelOperator jLabelOperator = new JLabelOperator(jdo1, labelText); |
|
217 assertEquals("Dialog contains appropriate text", labelText, jLabelOperator.getText()); |
|
218 |
|
219 new JButtonOperator(jdo1, OK).push(); |
|
220 |
|
221 assertFalse("Component Dialog Example No Option", jdo1.isShowing()); |
|
222 } |
|
223 |
|
224 // Case: Maybe option selected |
|
225 { |
|
226 new JButtonOperator(jfo, COMPONENT_BUTTON).pushNoBlock(); |
|
227 |
|
228 JDialogOperator jdo = new JDialogOperator(COMPONENT_TITLE); |
|
229 new JButtonOperator(jdo, COMPONENT_OP3).pushNoBlock(); |
|
230 |
|
231 JDialogOperator jdo1 = new JDialogOperator(MESSAGE); |
|
232 |
|
233 assertTrue("Component Dialog Maybe Yes Option", jdo1.isShowing()); |
|
234 |
|
235 final String labelText = COMPONENT_R3; |
|
236 JLabelOperator jLabelOperator = new JLabelOperator(jdo1, labelText); |
|
237 assertEquals("Dialog contains appropriate text", labelText, jLabelOperator.getText()); |
|
238 |
|
239 new JButtonOperator(jdo1, OK).push(); |
|
240 |
|
241 assertFalse("Component Dialog Maybe Yes Option", jdo1.isShowing()); |
|
242 } |
|
243 |
|
244 // Case: Probably option selected |
|
245 { |
|
246 new JButtonOperator(jfo, COMPONENT_BUTTON).pushNoBlock(); |
|
247 |
|
248 JDialogOperator jdo = new JDialogOperator(COMPONENT_TITLE); |
|
249 new JButtonOperator(jdo, COMPONENT_OP4).pushNoBlock(); |
|
250 |
|
251 JDialogOperator jdo1 = new JDialogOperator(MESSAGE); |
|
252 |
|
253 assertTrue("Component Dialog Example Probably Option", jdo1.isShowing()); |
|
254 |
|
255 final String labelText = COMPONENT_R4; |
|
256 JLabelOperator jLabelOperator = new JLabelOperator(jdo1, labelText); |
|
257 assertEquals("Dialog contains appropriate text", labelText, jLabelOperator.getText()); |
|
258 |
|
259 new JButtonOperator(jdo1, OK).push(); |
|
260 |
|
261 assertFalse("Component Dialog Example Probably Option", jdo1.isShowing()); |
|
262 } |
|
263 |
|
264 // Case TextField and ComboBox functional |
|
265 { |
|
266 new JButtonOperator(jfo, COMPONENT_BUTTON).push(); |
|
267 |
|
268 JDialogOperator jdo = new JDialogOperator(COMPONENT_TITLE); |
|
269 |
|
270 JTextFieldOperator jto = new JTextFieldOperator(jdo); |
|
271 jto.clearText(); |
|
272 jto.typeText(TEXT_TO_TYPE); |
|
273 |
|
274 JComboBoxOperator jcbo = new JComboBoxOperator(jdo); |
|
275 jcbo.selectItem(2); |
|
276 |
|
277 assertEquals("Show Component Dialog TextField", TEXT_TO_TYPE, jto.getText()); |
|
278 assertEquals("Show Component Dialog ComboBox", 2, jcbo.getSelectedIndex()); |
|
279 |
|
280 new JButtonOperator(jdo, "cancel").push(); |
|
281 } |
|
282 } |
|
283 |
|
284 public void showConfirmationDialog(JFrameOperator jfo) throws Exception { |
|
285 // Case: Yes option selected |
|
286 { |
|
287 new JButtonOperator(jfo, CONFIRM_BUTTON).pushNoBlock(); |
|
288 |
|
289 JDialogOperator jdo = new JDialogOperator(SELECT_AN__OPTION); |
|
290 new JButtonOperator(jdo, YES).pushNoBlock(); |
|
291 |
|
292 JDialogOperator jdo1 = new JDialogOperator(MESSAGE); |
|
293 |
|
294 assertTrue("Show Confirmation Dialog Yes Option", jdo1.isShowing()); |
|
295 |
|
296 final String labelText = CONFIRM_YES; |
|
297 JLabelOperator jLabelOperator = new JLabelOperator(jdo1, labelText); |
|
298 assertEquals("Dialog contains appropriate text", labelText, jLabelOperator.getText()); |
|
299 |
|
300 new JButtonOperator(jdo1, OK).push(); |
|
301 |
|
302 assertFalse("Show Confirmation Dialog Yes Option", jdo1.isShowing()); |
|
303 } |
|
304 |
|
305 // Case: No option selected |
|
306 { |
|
307 new JButtonOperator(jfo, CONFIRM_BUTTON).pushNoBlock(); |
|
308 |
|
309 JDialogOperator jdo = new JDialogOperator(SELECT_AN__OPTION); |
|
310 new JButtonOperator(jdo, NO).pushNoBlock(); |
|
311 |
|
312 JDialogOperator jdo1 = new JDialogOperator(MESSAGE); |
|
313 |
|
314 assertTrue("Show Confirmation Dialog No Option", jdo1.isShowing()); |
|
315 |
|
316 final String labelText = CONFIRM_NO; |
|
317 JLabelOperator jLabelOperator = new JLabelOperator(jdo1, labelText); |
|
318 assertEquals("Dialog contains appropriate text", labelText, jLabelOperator.getText()); |
|
319 |
|
320 new JButtonOperator(jdo1, OK).push(); |
|
321 |
|
322 assertFalse("Show Confirmation Dialog No Option", jdo1.isShowing()); |
|
323 } |
|
324 |
|
325 // Case: Cancel option selected |
|
326 { |
|
327 new JButtonOperator(jfo, CONFIRM_BUTTON).pushNoBlock(); |
|
328 |
|
329 JDialogOperator jdo = new JDialogOperator(SELECT_AN__OPTION); |
|
330 |
|
331 assertTrue("Show Confirmation Dialog Cancel Option", jdo.isShowing()); |
|
332 |
|
333 new JButtonOperator(jdo, CANCEL).push(); |
|
334 |
|
335 assertFalse("Show Confirmation Dialog Cancel Option", jdo.isShowing()); |
|
336 } |
|
337 } |
|
338 |
|
339 } |