Skip to content

Commit

Permalink
test: Work around limitations in Jemmy
Browse files Browse the repository at this point in the history
Jemmy appears to have problems manipulating JComponents with multiple borders through GUI methods, and with setting the selection through GUI methods on ComboBoxes that are not Strings.
  • Loading branch information
rhwood committed Jul 20, 2019
1 parent bd1f689 commit 1ac6e23
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
20 changes: 11 additions & 9 deletions java/test/jmri/jmrit/beantable/AbstractTableActionBase.java
Expand Up @@ -4,11 +4,13 @@
import javax.swing.JFrame;
import javax.swing.JTextField;
import jmri.util.JUnitUtil;
import jmri.util.swing.JemmyUtil;
import org.junit.After;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import org.netbeans.jemmy.QueueTool;
import org.netbeans.jemmy.operators.JFrameOperator;
import org.netbeans.jemmy.operators.JTableOperator;
import org.netbeans.jemmy.operators.JTextFieldOperator;
Expand Down Expand Up @@ -88,10 +90,10 @@ public void testAddButton() {
JFrame f = JFrameOperator.waitJFrame(getTableFrameName(), true, true);

// find the "Add... " button and press it.
jmri.util.swing.JemmyUtil.pressButton(new JFrameOperator(f),Bundle.getMessage("ButtonAdd"));
new org.netbeans.jemmy.QueueTool().waitEmpty();
JemmyUtil.pressButton(new JFrameOperator(f),Bundle.getMessage("ButtonAdd"));
new QueueTool().waitEmpty();
JFrame f1 = JFrameOperator.waitJFrame(getAddFrameName(), true, true);
jmri.util.swing.JemmyUtil.pressButton(new JFrameOperator(f1),Bundle.getMessage("ButtonCancel"));
JemmyUtil.pressButton(new JFrameOperator(f1),Bundle.getMessage("ButtonCancel"));
JUnitUtil.dispose(f1);
JUnitUtil.dispose(f);
}
Expand Down Expand Up @@ -119,18 +121,18 @@ public void testAddThroughDialog() {
JFrame f = JFrameOperator.waitJFrame(getTableFrameName(), true, true);

// find the "Add... " button and press it.
jmri.util.swing.JemmyUtil.pressButton(new JFrameOperator(f),Bundle.getMessage("ButtonAdd"));
JemmyUtil.pressButton(new JFrameOperator(f),Bundle.getMessage("ButtonAdd"));
JFrame f1 = JFrameOperator.waitJFrame(getAddFrameName(), true, true);
JFrameOperator jf = new JFrameOperator(f1);
//Enter 1 in the text field labeled "Hardware address:"
JTextField hwAddressField = JTextFieldOperator.findJTextField(f1, new NameComponentChooser("hwAddressTextField"));
Assert.assertNotNull("hwAddressTextField", hwAddressField);

// set to "1"
new JTextFieldOperator(hwAddressField).enterText("1");
new JTextFieldOperator(hwAddressField).setText("1");

//and press create
jmri.util.swing.JemmyUtil.pressButton(jf,Bundle.getMessage("ButtonCreate"));
JemmyUtil.pressButton(jf,Bundle.getMessage("ButtonCreate"));
JUnitUtil.dispose(f1);
JUnitUtil.dispose(f);
}
Expand All @@ -144,7 +146,7 @@ public void testEditButton() {

// find the "Add... " button and press it.
JFrameOperator jfo = new JFrameOperator(f);
jmri.util.swing.JemmyUtil.pressButton(jfo,Bundle.getMessage("ButtonAdd"));
JemmyUtil.pressButton(jfo,Bundle.getMessage("ButtonAdd"));
JFrame f1 = JFrameOperator.waitJFrame(getEditFrameName(), true, true);
JFrameOperator jf = new JFrameOperator(f1);
//Enter 1 in the text field labeled "Hardware address:"
Expand All @@ -155,13 +157,13 @@ public void testEditButton() {
new JTextFieldOperator(hwAddressField).enterText("1");

//and press create
jmri.util.swing.JemmyUtil.pressButton(jf,Bundle.getMessage("ButtonCreate"));
JemmyUtil.pressButton(jf,Bundle.getMessage("ButtonCreate"));

JTableOperator tbl = new JTableOperator(jfo, 0);
// find the "Edit" button and press it. This is in the table body.
tbl.clickOnCell(0,tbl.findColumn(Bundle.getMessage("ButtonEdit")));
JFrame f2 = JFrameOperator.waitJFrame(getAddFrameName(), true, true);
jmri.util.swing.JemmyUtil.pressButton(new JFrameOperator(f2),Bundle.getMessage("ButtonCancel"));
JemmyUtil.pressButton(new JFrameOperator(f2),Bundle.getMessage("ButtonCancel"));
JUnitUtil.dispose(f2);

JUnitUtil.dispose(f1);
Expand Down
27 changes: 7 additions & 20 deletions java/test/jmri/jmrit/beantable/LightTableActionTest.java
Expand Up @@ -178,7 +178,7 @@ public void testAddEditSensorLightControl() throws jmri.JmriException {
// create a new LightControl by Sensor S2
new JComboBoxOperator(jfoc, 0).selectItem(Bundle.getMessage("LightSensorControl"));

new JComboBoxOperator(jfoc, 1).selectItem(("ISS2")); // select Sensor S2
new JComboBoxOperator(jfoc, 1).setSelectedItem(sTwo); // select Sensor S2
new JComboBoxOperator(jfoc, 2).selectItem(Bundle.getMessage("SensorStateActive"));
JemmyUtil.pressButton(jfoc, Bundle.getMessage("ButtonCreate"));
// light control frame closes
Expand Down Expand Up @@ -274,20 +274,16 @@ public void testAddEditFastClockFollowerLightControl() throws jmri.JmriException
JFrameOperator jfoc = new JFrameOperator(fControl);

// create a new Light Controlled by Sensor S2
new JComboBoxOperator(jfoc, 0).selectItem(Bundle.getMessage("LightFastClockControl"));
new JComboBoxOperator(jfoc, 0).setSelectedItem(Bundle.getMessage("LightFastClockControl"));

Assert.assertEquals("default Hour ON Time ", "00", new JTextFieldOperator(jfoc, 0).getText());
Assert.assertEquals("default Minute ON Time ", "00", new JTextFieldOperator(jfoc, 1).getText());
Assert.assertEquals("default Hour OFF Time ", "00", new JTextFieldOperator(jfoc, 2).getText());
Assert.assertEquals("default Minute OFF Time ", "00", new JTextFieldOperator(jfoc, 3).getText());

new JTextFieldOperator(jfoc, 0).clearText();
new JTextFieldOperator(jfoc, 0).setText("01");
new JTextFieldOperator(jfoc, 1).clearText();
new JTextFieldOperator(jfoc, 1).setText("02");
new JTextFieldOperator(jfoc, 2).clearText();
new JTextFieldOperator(jfoc, 2).setText("03");
new JTextFieldOperator(jfoc, 3).clearText();
new JTextFieldOperator(jfoc, 3).setText("04");

JemmyUtil.pressButton(jfoc, Bundle.getMessage("ButtonCreate"));
Expand Down Expand Up @@ -328,13 +324,9 @@ public void testAddEditFastClockFollowerLightControl() throws jmri.JmriException
Assert.assertEquals("Correct Hour OFF Time ", "03", new JTextFieldOperator(jfof3, 2).getText());
Assert.assertEquals("Correct Minute OFF Time ", "04", new JTextFieldOperator(jfof3, 3).getText());

new JTextFieldOperator(jfof3, 0).clearText();
new JTextFieldOperator(jfof3, 0).setText("21");
new JTextFieldOperator(jfof3, 1).clearText();
new JTextFieldOperator(jfof3, 1).setText("22");
new JTextFieldOperator(jfof3, 2).clearText();
new JTextFieldOperator(jfof3, 2).setText("23");
new JTextFieldOperator(jfof3, 3).clearText();
new JTextFieldOperator(jfof3, 3).setText("24");

JemmyUtil.pressButton(jfof3, Bundle.getMessage("ButtonUpdate"));
Expand Down Expand Up @@ -366,13 +358,9 @@ public void testAddEditFastClockFollowerLightControl() throws jmri.JmriException
Assert.assertEquals("Correct Hour OFF Time ", "23", new JTextFieldOperator(jfof5, 2).getText());
Assert.assertEquals("Correct Minute OFF Time ", "24", new JTextFieldOperator(jfof5, 3).getText());

new JTextFieldOperator(jfof5, 0).clearText();
new JTextFieldOperator(jfof5, 0).setText("07");
new JTextFieldOperator(jfof5, 1).clearText();
new JTextFieldOperator(jfof5, 1).setText("07");
new JTextFieldOperator(jfof5, 2).clearText();
new JTextFieldOperator(jfof5, 2).setText("07");
new JTextFieldOperator(jfof5, 3).clearText();
new JTextFieldOperator(jfof5, 3).setText("07");

JemmyUtil.pressButton(jfof5, Bundle.getMessage("ButtonUpdate"));
Expand Down Expand Up @@ -418,7 +406,7 @@ public void testAddEditTurnoutLightControl() throws jmri.JmriException {

new JComboBoxOperator(jfoc, 0).selectItem(Bundle.getMessage("LightTurnoutStatusControl"));

new JComboBoxOperator(jfoc, 1).selectItem(("ITT2")); // select Turnout T2
new JComboBoxOperator(jfoc, 1).setSelectedItem(tTwo); // select Turnout T2
new JComboBoxOperator(jfoc, 2).selectItem(
InstanceManager.getDefault(jmri.TurnoutManager.class).getThrownText());

Expand Down Expand Up @@ -460,7 +448,7 @@ public void testAddEditTurnoutLightControl() throws jmri.JmriException {
Assert.assertEquals("Turnout thrown ", InstanceManager.getDefault(jmri.TurnoutManager.class).getThrownText(),
new JComboBoxOperator(jfof3, 2).getSelectedItem());

new JComboBoxOperator(jfof3, 1).selectItem(("ITT1")); // select Turnout T1
new JComboBoxOperator(jfof3, 1).setSelectedItem(tOne); // select Turnout T1
new JComboBoxOperator(jfof3, 2).selectItem(
InstanceManager.getDefault(jmri.TurnoutManager.class).getClosedText());

Expand Down Expand Up @@ -509,8 +497,7 @@ public void testAddEditTimedOnLightControl() throws jmri.JmriException {

// create a new Light Control
new JComboBoxOperator(jfoc, 0).selectItem(Bundle.getMessage("LightTimedOnControl"));
new JComboBoxOperator(jfoc, 1).selectItem(("ISS2")); // select Sensor S2
new JTextFieldOperator(jfoc, 0).clearText();
new JComboBoxOperator(jfoc, 1).setSelectedItem(sTwo); // select Sensor S2
new JTextFieldOperator(jfoc, 0).setText("20");

JemmyUtil.pressButton(jfoc, Bundle.getMessage("ButtonCreate"));
Expand Down Expand Up @@ -601,8 +588,8 @@ public void testAddEditTwoSensorLightControl() throws jmri.JmriException {

// create a new LightControl
new JComboBoxOperator(jfoc, 0).selectItem(Bundle.getMessage("LightTwoSensorControl"));
new JComboBoxOperator(jfoc, 1).selectItem(("ISS3")); // select Sensor S3
new JComboBoxOperator(jfoc, 2).selectItem(("ISS1")); // select Sensor S1
new JComboBoxOperator(jfoc, 1).setSelectedItem(sThree); // select Sensor S3
new JComboBoxOperator(jfoc, 2).setSelectedItem(sOne); // select Sensor S1
new JComboBoxOperator(jfoc, 3).selectItem(Bundle.getMessage("SensorStateActive"));

JemmyUtil.pressButton(jfoc, Bundle.getMessage("ButtonCreate"));
Expand Down

0 comments on commit 1ac6e23

Please sign in to comment.