Java Swing GUI Test Fest JPanel Fixture Error

875 views Asked by At

Trying to use FEST to test my GUI, but I'm having a problem trying to access components that are contained inside a custom JPanel (TopPanel extends JPanel). So the code below is failing when trying to reference the "topPane" which exists as a field inside the MainJFrame. What am I doing wrong here?

public class StableAppsUITest {

    private FrameFixture window;
    private JPanelFixture contentFixture;

    @Before
    public void setUp() {
        //Assumes the main class is named "Anagrams" and extends JFrame:
        window = new FrameFixture(new MainJFrame("Title"));
        window.show();
        contentFixture = window.panel("topPanel");

    }

    @Test
    public void shouldEnterAnagramAndReturnTrue() {

        // contentFixture.textBox("mUrlInputTextField").enterText("www.google.com");
    }

    @After
    public void tearDown() {
        window.cleanUp();
    }

}

And here's the stacktrace, in case it's hepful:

Unable to find component using matcher org.fest.swing.core.NameAndTypeMatcher[name='topPanel', type=javax.swing.JPanel, requireShowing=true].

Component hierarchy: myapp.ui.MainJFrame[name='frame0', title='myapp', enabled=true, visible=true, showing=true] javax.swing.JRootPane[] javax.swing.JPanel[name='null.glassPane'] javax.swing.JLayeredPane[] javax.swing.JPanel[name='null.contentPane'] myapp.ui.TopPanel[name=null] javax.swing.JLabel[name=null, text='Enter Url: ', enabled=true, visible=true, showing=true] javax.swing.JTextField[name=null, text='', enabled=true, visible=true, showing=true] javax.swing.JButton[name=null, text='Submit', enabled=true, visible=true, showing=true] myapp.ui.ContentPanel[name=null] javax.swing.JScrollPane[name=null, enabled=true, visible=true, showing=true] javax.swing.JViewport[,1,1,381x270,layout=javax.swing.ViewportLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=25165832,maximumSize=,minimumSize=,preferredSize=,isViewSizeSet=true,lastPaintPosition=java.awt.Point[x=0,y=0],scrollUnderway=false] javax.swing.JList[name=null, selectedValues=[], contents=[], selectionMode=MULTIPLE_INTERVAL_SELECTION, enabled=true, visible=true, showing=true] javax.swing.CellRendererPane[,0,0,0x0,hidden] javax.swing.JScrollPane$ScrollBar[name=null, value=0, blockIncrement=10, minimum=0, maximum=270, enabled=true, visible=false, showing=false] javax.swing.plaf.metal.MetalScrollButton[name=null, text='', enabled=true, visible=true, showing=false] javax.swing.plaf.metal.MetalScrollButton[name=null, text='', enabled=true, visible=true, showing=false] javax.swing.JScrollPane$ScrollBar[name=null, value=0, blockIncrement=10, minimum=0, maximum=381, enabled=true, visible=false, showing=false] javax.swing.plaf.metal.MetalScrollButton[name=null, text='', enabled=true, visible=true, showing=false] javax.swing.plaf.metal.MetalScrollButton[name=null, text='', enabled=true, visible=true, showing=false] myapp.ui.StatusPanel[name=null] javax.swing.JLabel[name=null, text='Status: ', enabled=true, visible=true, showing=true] javax.swing.JLabel[name=null, text='', enabled=true, visible=true, showing=true]

org.fest.swing.exception.ComponentLookupException at org.fest.swing.core.BasicComponentFinder.componentNotFound(BasicComponentFinder.java:184) at org.fest.swing.core.BasicComponentFinder.find(BasicComponentFinder.java:169) at org.fest.swing.core.BasicComponentFinder.find(BasicComponentFinder.java:158) at org.fest.swing.core.BasicComponentFinder.findByName(BasicComponentFinder.java:136) at org.fest.swing.fixture.ContainerFixture.findByName(ContainerFixture.java:822) at org.fest.swing.fixture.ContainerFixture.panel(ContainerFixture.java:406) at myapp.ui.myappUITest.setUp(myappUITest.java:32)

1

There are 1 answers

1
Richard Neish On BEST ANSWER

Looking at your stacktrace, there is a component of type myapp.ui.TopPanel, but the name is null (myapp.ui.TopPanel[name=null]).

window.panel("topPanel") will search for a JPanel with name "topPanel", so you need to set the name of your component using mTopPanel.setName("topPanel");, or use a matcher instead.