gpt4 book ai didi

Java Swing GUI 测试 Fest JPanel 夹具错误

转载 作者:行者123 更新时间:2023-12-01 11:25:33 26 4
gpt4 key购买 nike

尝试使用 FEST 来测试我的 GUI,但在尝试访问自定义 JPanel(TopPanel 扩展 JPanel)中包含的组件时遇到问题。因此,当尝试引用作为 MainJFrame 内的字段存在的“topPane”时,下面的代码会失败。我在这里做错了什么?

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();
}

}

这是堆栈跟踪,以防有帮助:

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)

最佳答案

查看堆栈跟踪,有一个 myapp.ui.TopPanel 类型的组件,但名称为 null (myapp.ui.TopPanel[name=null])。

window.panel("topPanel") 将搜索名称为“topPanel”的 JPanel,因此您需要使用 mTopPanel.setName("topPanel"设置组件的名称);,或者使用匹配器。

关于Java Swing GUI 测试 Fest JPanel 夹具错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30834336/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com