39 import org.netbeans.jemmy.operators.ContainerOperator;
40 import org.netbeans.jemmy.operators.JCheckBoxOperator;
41 import org.netbeans.jemmy.operators.JFrameOperator;
42 import org.netbeans.jemmy.operators.JRadioButtonOperator;
43 import org.netbeans.jemmy.operators.JTabbedPaneOperator;
44 import org.testng.annotations.Listeners;
45
46 /*
47 * @test
48 * @key headful
49 * @summary Verifies SwingSet3 ToggleButtonDemo by toggling each radio button,
50 * each checkbox and each location of the direction dial toggle.
51 * It verifies initial selected values for all the elements and checks
52 * that those change upon clicking. When toggling radio buttons it
53 * verifies that other radio buttons in the same group are not longer
54 * selected.
55 *
56 * @library /sanity/client/lib/jemmy/src
57 * @library /sanity/client/lib/Extensions/src
58 * @library /sanity/client/lib/SwingSet3/src
59 * @build org.jemmy2ext.JemmyExt
60 * @build com.sun.swingset3.demos.togglebutton.ToggleButtonDemo
61 * @run testng ToggleButtonDemoTest
62 */
63 @Listeners(GuiTestListener.class)
64 public class ToggleButtonDemoTest {
65
66 @Test
67 public void test() throws Exception {
68 new ClassReference(ToggleButtonDemo.class.getCanonicalName()).startApplication();
69
70 JFrameOperator mainFrame = new JFrameOperator(ToggleButtonDemo.class.getAnnotation(DemoProperties.class).value());
71 JTabbedPaneOperator tabPane = new JTabbedPaneOperator(mainFrame);
72
73 // Radio Button Toggles
74 testRadioButtons(getBorderTitledJPanelOperator(mainFrame, TEXT_RADIO_BUTTONS), 3, null);
75 testRadioButtons(getBorderTitledJPanelOperator(mainFrame, IMAGE_RADIO_BUTTONS), 3, null);
76 testRadioButtons(getLabeledContainerOperator(mainFrame, PAD_AMOUNT), 3, (t, i) -> DEFAULT.equals(t));
77
78 // switch to the Check Boxes Tab
108
109 /**
110 * Tests a group of radio buttons
111 *
112 * @param parent container containing the buttons
113 * @param radioButtonCount number of radio buttons
114 * @param selectedRadioButton initial selected radio button
115 */
116 private void testRadioButtons(ContainerOperator<?> parent, int radioButtonCount, SelectedRadioButton selectedRadioButton) {
117 JRadioButtonOperator[] jrbo = new JRadioButtonOperator[radioButtonCount];
118 for (int i = 0; i < radioButtonCount; i++) {
119 jrbo[i] = new JRadioButtonOperator(parent, i);
120 if (selectedRadioButton != null && selectedRadioButton.apply(jrbo[i].getText(), i)) {
121 assertTrue("Radio Button " + i + " is initially selected", jrbo[i].isSelected());
122 } else {
123 assertFalse("Radio Button " + i + " is initially not selected", jrbo[i].isSelected());
124 }
125 }
126
127 for (int i = 0; i < radioButtonCount; i++) {
128 jrbo[i].doClick();
129 assertTrue("Radio Button " + i + " is selected", jrbo[i].isSelected());
130
131 for (int j = 0; j < radioButtonCount; j++) {
132 if (i != j) {
133 assertFalse("Radio Button " + j + " is not selected", jrbo[j].isSelected());
134 }
135 }
136 }
137 }
138
139 /**
140 * Will change the state of the CheckBox then change back to initial state.
141 *
142 * @param parent
143 * @param text
144 * @param expectedValue
145 * @throws Exception
146 */
147 private void testCheckBox(ContainerOperator<?> parent, String text, boolean expectedValue) {
148
149 parent.setComparator(EXACT_STRING_COMPARATOR);
150 JCheckBoxOperator jcbo = new JCheckBoxOperator(parent, text);
151 assertEquals("Initial selection state of the checkbox '" + text + "'", expectedValue, jcbo.isSelected());
152
153 // click check box (toggle the state)
154 jcbo.doClick();
155 assertEquals("Selection state of the checkbox '" + text + "' after click", !expectedValue, jcbo.isSelected());
156 if (jcbo.isSelected()) {
157 // toggle back to not-selected state
158 jcbo.doClick();
159 assertFalse("Check Box '" + text + "' is not selected", jcbo.isSelected());
160 } else {
161 // toggle back to selected state
162 jcbo.doClick();
163
164 assertTrue("Check Box '" + text + "' is selected", jcbo.isSelected());
165 }
166 }
167
168
169 /*
170 * testDirectionRadioButtons(JFrameOperator) will toggle each position of
171 * the direction radio button panels
172 */
173 private void testToggleButtons(JFrameOperator jfo) {
174 ComponentChooser directionPanelChooser = new ByClassChooser(DirectionPanel.class);
175
176 String text_Position = LayoutControlPanel.TEXT_POSITION;
177 ContainerOperator<?> textPositionContainer = getLabeledContainerOperator(jfo, text_Position);
178 ContainerOperator<?> directionPanelOperator = new ContainerOperator<>(textPositionContainer, directionPanelChooser);
179 testRadioButtons(directionPanelOperator, 9, (t, i) -> i == 5);
180
181 // Unfortunately, both directionPanels are in the same parent container
182 // so we have to use indexes here.
183 // There is no guarantee that if the UI changes, the code would be still
184 // valid in terms of which directionPanel is checked first. However, it
185 // does guarantee that two different directionPanels are checked.
|
39 import org.netbeans.jemmy.operators.ContainerOperator;
40 import org.netbeans.jemmy.operators.JCheckBoxOperator;
41 import org.netbeans.jemmy.operators.JFrameOperator;
42 import org.netbeans.jemmy.operators.JRadioButtonOperator;
43 import org.netbeans.jemmy.operators.JTabbedPaneOperator;
44 import org.testng.annotations.Listeners;
45
46 /*
47 * @test
48 * @key headful
49 * @summary Verifies SwingSet3 ToggleButtonDemo by toggling each radio button,
50 * each checkbox and each location of the direction dial toggle.
51 * It verifies initial selected values for all the elements and checks
52 * that those change upon clicking. When toggling radio buttons it
53 * verifies that other radio buttons in the same group are not longer
54 * selected.
55 *
56 * @library /sanity/client/lib/jemmy/src
57 * @library /sanity/client/lib/Extensions/src
58 * @library /sanity/client/lib/SwingSet3/src
59 * @modules java.desktop
60 * @build org.jemmy2ext.JemmyExt
61 * @build com.sun.swingset3.demos.togglebutton.ToggleButtonDemo
62 * @run testng ToggleButtonDemoTest
63 */
64 @Listeners(GuiTestListener.class)
65 public class ToggleButtonDemoTest {
66
67 @Test
68 public void test() throws Exception {
69 new ClassReference(ToggleButtonDemo.class.getCanonicalName()).startApplication();
70
71 JFrameOperator mainFrame = new JFrameOperator(ToggleButtonDemo.class.getAnnotation(DemoProperties.class).value());
72 JTabbedPaneOperator tabPane = new JTabbedPaneOperator(mainFrame);
73
74 // Radio Button Toggles
75 testRadioButtons(getBorderTitledJPanelOperator(mainFrame, TEXT_RADIO_BUTTONS), 3, null);
76 testRadioButtons(getBorderTitledJPanelOperator(mainFrame, IMAGE_RADIO_BUTTONS), 3, null);
77 testRadioButtons(getLabeledContainerOperator(mainFrame, PAD_AMOUNT), 3, (t, i) -> DEFAULT.equals(t));
78
79 // switch to the Check Boxes Tab
109
110 /**
111 * Tests a group of radio buttons
112 *
113 * @param parent container containing the buttons
114 * @param radioButtonCount number of radio buttons
115 * @param selectedRadioButton initial selected radio button
116 */
117 private void testRadioButtons(ContainerOperator<?> parent, int radioButtonCount, SelectedRadioButton selectedRadioButton) {
118 JRadioButtonOperator[] jrbo = new JRadioButtonOperator[radioButtonCount];
119 for (int i = 0; i < radioButtonCount; i++) {
120 jrbo[i] = new JRadioButtonOperator(parent, i);
121 if (selectedRadioButton != null && selectedRadioButton.apply(jrbo[i].getText(), i)) {
122 assertTrue("Radio Button " + i + " is initially selected", jrbo[i].isSelected());
123 } else {
124 assertFalse("Radio Button " + i + " is initially not selected", jrbo[i].isSelected());
125 }
126 }
127
128 for (int i = 0; i < radioButtonCount; i++) {
129 jrbo[i].push();
130 jrbo[i].waitSelected(true);
131
132 for (int j = 0; j < radioButtonCount; j++) {
133 if (i != j) {
134 jrbo[j].waitSelected(false);
135 }
136 }
137 }
138 }
139
140 /**
141 * Will change the state of the CheckBox then change back to initial state.
142 *
143 * @param parent
144 * @param text
145 * @param expectedValue
146 * @throws Exception
147 */
148 private void testCheckBox(ContainerOperator<?> parent, String text, boolean expectedValue) {
149
150 System.out.println("Testing " + text);
151 parent.setComparator(EXACT_STRING_COMPARATOR);
152 JCheckBoxOperator jcbo = new JCheckBoxOperator(parent, text);
153 jcbo.waitSelected(expectedValue);
154
155 // click check box (toggle the state)
156 jcbo.push();
157 jcbo.waitSelected(!expectedValue);
158
159 jcbo.push();
160 jcbo.waitSelected(expectedValue);
161 }
162
163
164 /*
165 * testDirectionRadioButtons(JFrameOperator) will toggle each position of
166 * the direction radio button panels
167 */
168 private void testToggleButtons(JFrameOperator jfo) {
169 ComponentChooser directionPanelChooser = new ByClassChooser(DirectionPanel.class);
170
171 String text_Position = LayoutControlPanel.TEXT_POSITION;
172 ContainerOperator<?> textPositionContainer = getLabeledContainerOperator(jfo, text_Position);
173 ContainerOperator<?> directionPanelOperator = new ContainerOperator<>(textPositionContainer, directionPanelChooser);
174 testRadioButtons(directionPanelOperator, 9, (t, i) -> i == 5);
175
176 // Unfortunately, both directionPanels are in the same parent container
177 // so we have to use indexes here.
178 // There is no guarantee that if the UI changes, the code would be still
179 // valid in terms of which directionPanel is checked first. However, it
180 // does guarantee that two different directionPanels are checked.
|