尝试使用FEST来测试我的GUI,但是我在尝试访问自定义JPanel中包含的组件时遇到问题(TopPanel扩展了JPanel)。所以下面的代码在尝试引用" topPane"时失败了。它作为MainJFrame中的字段存在。我在这做错了什么?
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();
}
}
这是堆栈跟踪,以防万一:
无法使用匹配器查找组件 org.fest.swing.core.NameAndTypeMatcher [名称=' topPanel&#39 ;, type = javax.swing.JPanel,requireShowing = true]。
组件层次结构:myapp.ui.MainJFrame [name =' frame0',title =' myapp', enabled = true,visible = true,shows = true] javax.swing.JRootPane [] javax.swing.JPanel中[名称=' null.glassPane'] javax.swing.JLayeredPane中[] javax.swing.JPanel中[名称=' null.contentPane'] myapp.ui.TopPanel [名=空] javax.swing.JLabel [name = null,text ='输入网址:',enabled = true,visible = true,显示= true] javax.swing.JTextField [name = null,text ='',enabled = true,visible = true,shows = true] javax.swing.JButton [name = null,text ='提交',enabled = true,visible = true,显示= true] myapp.ui.ContentPanel [名=空] javax.swing.JScrollPane [name = null,enabled = true,visible = true,shows = true] javax.swing.JViewport中[,1,1,381x270,布局= javax.swing.ViewportLayout,alignmentX = 0.0,alignmentY = 0.0,边界=,旗帜= 25165832,MAXIMUMSIZE =,=的minimumSize,首选大小=,isViewSizeSet =真,lastPaintPosition = java.awt.Point中[X = 0,Y = 0],scrollUnderway =假] javax.swing.JList [name = null,selectedValues = [],contents = [],selectionMode = MULTIPLE_INTERVAL_SELECTION,enabled = true, visible = true,显示= true] javax.swing.CellRendererPane [,0,0,0x0,隐藏] javax.swing.JScrollPane $ ScrollBar [name = null,value = 0,blockIncrement = 10,minimum = 0,maximum = 270,enabled = true, visible = false,显示= 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,显示= 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 [名=空] javax.swing.JLabel [name = null,text ='状态:',enabled = true,visible = true,显示= true] javax.swing.JLabel [name = null,text ='',enabled = true,visible = true,shows = true]
org.fest.swing.exception.ComponentLookupException at org.fest.swing.core.BasicComponentFinder.componentNotFound(BasicComponentFinder.java:184) 在 org.fest.swing.core.BasicComponentFinder.find(BasicComponentFinder.java:169) 在 org.fest.swing.core.BasicComponentFinder.find(BasicComponentFinder.java:158) 在 org.fest.swing.core.BasicComponentFinder.findByName(BasicComponentFinder.java:136) 在 org.fest.swing.fixture.ContainerFixture.findByName(ContainerFixture.java:822) 在 org.fest.swing.fixture.ContainerFixture.panel(ContainerFixture.java:406) at myapp.ui.myappUITest.setUp(myappUITest.java:32)
答案 0 :(得分:1)
查看堆栈跟踪,有一个myapp.ui.TopPanel
类型的组件,但名称为null(myapp.ui.TopPanel [name = null])。
window.panel("topPanel")
将搜索名称为" topPanel"的JPanel,因此您需要使用mTopPanel.setName("topPanel");
设置组件的名称,或者使用匹配器。