Search in sources :

Example 11 with AbstractButtonFinder

use of junit.extensions.jfcunit.finder.AbstractButtonFinder in project JMRI by JMRI.

the class SensorTableWindowTest method testShowAndClose.

public void testShowAndClose() throws Exception {
    if (GraphicsEnvironment.isHeadless()) {
        // can't Assume in TestCase
        return;
    }
    // ask for the window to open
    SensorTableAction a = new SensorTableAction();
    a.actionPerformed(new java.awt.event.ActionEvent(a, 1, ""));
    // Find new table window by name
    JmriJFrame ft = JmriJFrame.getFrame(Bundle.getMessage("TitleSensorTable"));
    flushAWT();
    // Find the add button
    AbstractButtonFinder abfinder = new AbstractButtonFinder("Add...");
    JButton button = (JButton) abfinder.find(ft, 0);
    Assert.assertNotNull(button);
    // Click button to open add window
    getHelper().enterClickAndLeave(new MouseEventData(this, button));
    // Find add window by name
    JmriJFrame fa = JmriJFrame.getFrame("Add New Sensor");
    Assert.assertNotNull("add window", fa);
    // Find system name field
    NamedComponentFinder ncfinder = new NamedComponentFinder(JComponent.class, "sysName");
    JTextField sysNameField = (JTextField) ncfinder.find(fa, 0);
    Assert.assertNotNull("sys name field", sysNameField);
    // set to "1"
    // The following line works on the CI servers, but not in some standalone cases
    //getHelper().sendString(new StringEventData(this, sysNameField, "1"));
    // workaround
    sysNameField.setText("1");
    flushAWT();
    Assert.assertEquals("name content", "1", sysNameField.getText());
    // Find system combobox
    ncfinder = new NamedComponentFinder(JComponent.class, "prefixBox");
    JComboBox<?> prefixBox = (JComboBox<?>) ncfinder.find(fa, 0);
    Assert.assertNotNull(prefixBox);
    // set to "Internal"
    prefixBox.setSelectedItem("Internal");
    Assert.assertEquals("Selected system item", "Internal", prefixBox.getSelectedItem());
    // Find the OK button
    abfinder = new AbstractButtonFinder("OK");
    button = (JButton) abfinder.find(fa, 0);
    Assert.assertNotNull(button);
    // Click button to add sensor
    getHelper().enterClickAndLeave(new MouseEventData(this, button));
    // Ask to close add window
    TestHelper.disposeWindow(fa, this);
    // Ask to close table window
    TestHelper.disposeWindow(ft, this);
    flushAWT();
    // check for existing sensor
    Assert.assertNotNull(jmri.InstanceManager.sensorManagerInstance().getSensor("IS1"));
}
Also used : NamedComponentFinder(junit.extensions.jfcunit.finder.NamedComponentFinder) JComboBox(javax.swing.JComboBox) JButton(javax.swing.JButton) JComponent(javax.swing.JComponent) MouseEventData(junit.extensions.jfcunit.eventdata.MouseEventData) JTextField(javax.swing.JTextField) AbstractButtonFinder(junit.extensions.jfcunit.finder.AbstractButtonFinder) JmriJFrame(jmri.util.JmriJFrame)

Example 12 with AbstractButtonFinder

use of junit.extensions.jfcunit.finder.AbstractButtonFinder in project JMRI by JMRI.

the class LearnWarrantTest method pressButton.

private javax.swing.AbstractButton pressButton(java.awt.Container frame, String text) {
    AbstractButtonFinder buttonFinder = new AbstractButtonFinder(text);
    javax.swing.AbstractButton button = (javax.swing.AbstractButton) buttonFinder.find(frame, 0);
    Assert.assertNotNull(text + " Button not found", button);
    getHelper().enterClickAndLeave(new MouseEventData(this, button));
    flushAWT();
    return button;
}
Also used : AbstractButtonFinder(junit.extensions.jfcunit.finder.AbstractButtonFinder) MouseEventData(junit.extensions.jfcunit.eventdata.MouseEventData)

Example 13 with AbstractButtonFinder

use of junit.extensions.jfcunit.finder.AbstractButtonFinder in project JMRI by JMRI.

the class LayoutEditorWindowTest method testShowAndClose.

@SuppressWarnings("unchecked")
public void testShowAndClose() throws Exception {
    if (GraphicsEnvironment.isHeadless()) {
        // Can't Assume in TestCase
        return;
    }
    jmri.configurexml.ConfigXmlManager cm = new jmri.configurexml.ConfigXmlManager() {
    };
    // load and display sample file
    java.io.File f = new java.io.File("java/test/jmri/jmrit/display/layoutEditor/valid/SimpleLayoutEditorTest.xml");
    cm.load(f);
    // time for internal listeners to calm down
    sleep(100);
    // Find new window by name (should be more distinctive, comes from sample file)
    LayoutEditor le = (LayoutEditor) jmri.util.JmriJFrame.getFrame("My Layout");
    // It's up at this point, and can be manipulated
    // Ask to close window
    TestHelper.disposeWindow(le, this);
    // Dialog has popped up, so handle that. First, locate it.
    List<JDialog> dialogList = new DialogFinder(null).findAll(le);
    JDialog d = dialogList.get(0);
    // Find the button that deletes the panel
    AbstractButtonFinder finder = new AbstractButtonFinder("Delete Panel");
    JButton button = (JButton) finder.find(d, 0);
    Assert.assertNotNull(button);
    // Click button to delete panel and close window
    getHelper().enterClickAndLeave(new MouseEventData(this, button));
    // another dialog has popped up, so handle that by finding the "Yes - Delete" button.
    dialogList = new DialogFinder(null).findAll(le);
    d = dialogList.get(0);
    finder = new AbstractButtonFinder("Yes - Delete");
    button = (JButton) finder.find(d, 0);
    Assert.assertNotNull(button);
    // Click to say yes, I really mean it.
    getHelper().enterClickAndLeave(new MouseEventData(this, button));
    le.dispose();
}
Also used : JButton(javax.swing.JButton) MouseEventData(junit.extensions.jfcunit.eventdata.MouseEventData) DialogFinder(junit.extensions.jfcunit.finder.DialogFinder) AbstractButtonFinder(junit.extensions.jfcunit.finder.AbstractButtonFinder) JDialog(javax.swing.JDialog)

Example 14 with AbstractButtonFinder

use of junit.extensions.jfcunit.finder.AbstractButtonFinder in project JMRI by JMRI.

the class MultiJfcUnitTest method testShow.

public void testShow() throws Exception {
    if (GraphicsEnvironment.isHeadless()) {
        // Can't assume in TestCase
        return;
    }
    // show the window
    JFrame f1 = new MultiPaneWindow("test", "java/test/jmri/util/swing/xml/Gui3LeftTree.xml", "java/test/jmri/util/swing/xml/Gui3Menus.xml", "java/test/jmri/util/swing/xml/Gui3MainToolBar.xml");
    f1.setSize(new java.awt.Dimension(500, 500));
    f1.setVisible(true);
    Assert.assertNotNull("found main frame", f1);
    // Find the button that loads the license
    AbstractButtonFinder finder = new AbstractButtonFinder("License");
    JButton button = (JButton) finder.find(f1, 0);
    Assert.assertNotNull("License button found", button);
    // Click it to load license
    getHelper().enterClickAndLeave(new MouseEventData(this, button));
    // Find the button that opens a sample panel
    AbstractButtonFinder samplefinder = new AbstractButtonFinder("Sample");
    JButton samplebutton = (JButton) samplefinder.find(f1, 0);
    Assert.assertNotNull("Sample button found", samplebutton);
    // Click it to load new pane over license
    getHelper().enterClickAndLeave(new MouseEventData(this, samplebutton));
    // Find the button on new panel
    finder = new AbstractButtonFinder("Next1");
    JButton next1button = (JButton) finder.find(f1, 0);
    Assert.assertNotNull("Next1 button found", next1button);
    // Click it to load new window with Next2
    getHelper().enterClickAndLeave(new MouseEventData(this, next1button));
    // nobody disposed yet
    Assert.assertEquals("no panes disposed", 0, SamplePane.disposed.size());
    // Find the Next2 button on new panel
    finder = new AbstractButtonFinder("Next2");
    JButton next2button = (JButton) finder.find(f1, 0);
    Assert.assertNotNull("Next2 button found", next2button);
    // Click sample to reload 0 pane over 1 pane
    getHelper().enterClickAndLeave(new MouseEventData(this, samplebutton));
    // Find the button on restored panel
    finder = new AbstractButtonFinder("Next1");
    button = (JButton) finder.find(f1, 0);
    Assert.assertEquals("found same pane", next1button, button);
    // Find the button to open a pane in lower window
    finder = new AbstractButtonFinder("Extend1");
    JButton extendButton = (JButton) finder.find(f1, 0);
    Assert.assertNotNull("Extend1 button found", extendButton);
    // Press it
    getHelper().enterClickAndLeave(new MouseEventData(this, extendButton));
    // Both Close1 and Close3 should be present
    finder = new AbstractButtonFinder("Close1");
    button = (JButton) finder.find(f1, 0);
    Assert.assertNotNull("Closee1 button found", button);
    finder = new AbstractButtonFinder("Close3");
    button = (JButton) finder.find(f1, 0);
    Assert.assertNotNull("Close3 button found", button);
    // nobody disposed yet
    Assert.assertEquals("no panes disposed", 0, SamplePane.disposed.size());
    // Close entire frame directly
    TestHelper.disposeWindow(f1, this);
    // Now they're disposed
    Assert.assertEquals("panes disposed", 3, SamplePane.disposed.size());
}
Also used : AbstractButtonFinder(junit.extensions.jfcunit.finder.AbstractButtonFinder) JFrame(javax.swing.JFrame) JButton(javax.swing.JButton) MouseEventData(junit.extensions.jfcunit.eventdata.MouseEventData)

Aggregations

MouseEventData (junit.extensions.jfcunit.eventdata.MouseEventData)14 AbstractButtonFinder (junit.extensions.jfcunit.finder.AbstractButtonFinder)14 JButton (javax.swing.JButton)11 JDialog (javax.swing.JDialog)7 DialogFinder (junit.extensions.jfcunit.finder.DialogFinder)7 JComponent (javax.swing.JComponent)6 NamedIcon (jmri.jmrit.catalog.NamedIcon)4 JTextField (javax.swing.JTextField)3 Turnout (jmri.Turnout)3 JComboBox (javax.swing.JComboBox)2 JFrame (javax.swing.JFrame)2 Sensor (jmri.Sensor)2 JmriJFrame (jmri.util.JmriJFrame)2 NamedComponentFinder (junit.extensions.jfcunit.finder.NamedComponentFinder)2 JCheckBox (javax.swing.JCheckBox)1 Block (jmri.Block)1 BlockManager (jmri.BlockManager)1 JmriNamedPaneAction (jmri.util.swing.JmriNamedPaneAction)1 SamplePane (jmri.util.swing.SamplePane)1 StringEventData (junit.extensions.jfcunit.eventdata.StringEventData)1