简体   繁体   English

使用 org.fest.swing.fixture.FrameFixture::panel() 查找 Swing 面板,它需要显示面板吗?

[英]FInding Swing panels with org.fest.swing.fixture.FrameFixture::panel(), it requires panel to be showing?

I want to use FEST to test that a Swing component is invisible.我想使用 FEST 来测试 Swing 组件是否不可见。

I try to use org.fest.swing.fixture.FrameFixture method panel(“foo”) but that fails since it requires requireShowing=true.我尝试使用org.fest.swing.fixture.FrameFixture方法panel(“foo”)但失败了,因为它需要requireShowing=true.

What is idiomatic approach using FEST to find a panel irregardless if it's visible right now?无论现在是否可见,使用 FEST 查找面板的惯用方法是什么?

Assert.assertFalse(panel.getFooPanel().isVisible()); // works ok
myFrameFixture.panel(“foo”).requireNotVisible(); // fails 

The second line gives this...第二行给出了这个......

     javax.swing.JPanel[name='foo']

org.fest.swing.exception.ComponentLookupException: Unable to find component
using matcher 
org.fest.swing.core.NameMatcher[name='foo, type=javax.swing.JPanel, requireShowing=true].

EDIT :编辑 :

I tied a similar test with a JComboBox, using the pattern suggested by Jay Fichadia, but it still seems to require the item to be visible before I invoke .requireNotVisible() eg trying new JComboBoxFixture(frame.robot,"grid_combo");我使用 Jay Fichadia 建议的模式将类似的测试与 JComboBox 捆绑在一起,但它似乎仍然要求在我调用.requireNotVisible()之前该项目是可见的,例如尝试new JComboBoxFixture(frame.robot,"grid_combo"); alone (without the actual requireNotVisible() check) gives ...单独(没有实际的 requireNotVisible() 检查)给出...

    Caused an ERROR
Unable to find component using matcher org.fest.swing.core.NameMatcher[name='grid_combo', type=javax.swing.JComboBox, requireShowing=true].

despite the fact we have in the Component hierarchy:尽管我们在组件层次结构中有:

javax.swing.JComboBox[name='grid_combo', selectedItem='A', contents=['A', 'B'], editable=false, enabled=false, visible=false, showing=false]

I just encountered same problem and after seeing no answer here, I found a solution myself.我刚刚遇到了同样的问题,在这里看到没有答案后,我自己找到了解决方案。

The problem is that frameFixture by default look only for components that are visible.问题是 frameFixture 默认只查找可见的组件。 So if you want to search for not visible components, you have to change this setting.因此,如果您要搜索不可见的组件,则必须更改此设置。 You can do this by using:您可以使用以下方法执行此操作:

myFrameFixture.robot.settings().componentLookupScope(ComponentLookupScope.ALL);

您是否尝试使用new JPanelFixture(robot,"foo").requireNotVisible()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM