无法选择JCheckBoxMenuItem,无法识别上下文中的组件

时间:2018-03-08 20:00:24

标签: robotframework jemmy

我开始在机器人框架的摇摆库中工作,gui测试java应用程序。

我必须选择jcheckboxmenuitem" waveMenu"来自jpopupmenu"菜单"在jtextarea" showText"。运行关键字:

Select From Popup Menu      showText        menu|waveMenu

导致一个非常无益的错误。

Fail: Popup menu

如果我尝试右键单击组件showText,它只是通过而不会显示与之关联的菜单。该菜单由常规的mouselistener附加。

showText.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                menu.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    });

在此

的顶部结果的上下文中列出组件
Level: 0 Component: ca.acme.myApplication
Index: 0 Name: the name I select when I run Select Window
    Level: 1 Component: javax.swing.JRootPane Index: 0 Name: null
       Level: 2 Component: javax.swing.JPanel Index: 0 Name: null.glassPane
       Level: 2 Component: javax.swing.JLayeredPane Index: 0 Name: null.layeredPane
          Level: 3 Component: javax.swing.JPanel Index: 1 Name: null.contentPane
             Level: 4 Component: javax.swing.JPanel Index: 2 Name: null
                Level: 5 Component: javax.swing.JButton Index: 0 Name: fileOpenButton
                Level: 5 Component: javax.swing.JTextField Index: 0 Name: fileText
                Level: 5 Component: javax.swing.JButton Index: 1 Name: fileSendButton
                Level: 5 Component: javax.swing.JLabel Index: 0 Name: null
                Level: 5 Component: javax.swing.JTextField Index: 1 Name: hostText
                Level: 5 Component: javax.swing.JComboBox Index: 0 Name: formatSelect
                   Level: 6 Component: javax.swing.plaf.metal.MetalComboBoxButton Index: 2 Name: null
                   Level: 6 Component: javax.swing.CellRendererPane Index: 0 Name: null
                      Level: 7 Component: javax.swing.plaf.basic.BasicComboBoxRenderer$UIResource Index: 1 Name: null
                Level: 5 Component: javax.swing.JComboBox Index: 1 Name: voiceSelect
                   Level: 6 Component: javax.swing.plaf.metal.MetalComboBoxButton Index: 3 Name: null
                   Level: 6 Component: javax.swing.CellRendererPane Index: 1 Name: null
                      Level: 7 Component: javax.swing.plaf.basic.BasicComboBoxRenderer$UIResource Index: 2 Name: null
                Level: 5 Component: javax.swing.JComboBox Index: 2 Name: delaySelect
                   Level: 6 Component: javax.swing.plaf.metal.MetalComboBoxButton Index: 4 Name: null
                   Level: 6 Component: javax.swing.CellRendererPane Index: 2 Name: null
                      Level: 7 Component: javax.swing.plaf.basic.BasicComboBoxRenderer$UIResource Index: 3 Name: null
                Level: 5 Component: javax.swing.JTextField Index: 2 Name: messageText
                Level: 5 Component: javax.swing.JButton Index: 5 Name: messageSendButton
                Level: 5 Component: javax.swing.JLabel Index: 4 Name: portLabel
                Level: 5 Component: javax.swing.JTextField Index: 3 Name: portText
                Level: 5 Component: javax.swing.JComboBox Index: 3 Name: requestSelect
                   Level: 6 Component: javax.swing.plaf.metal.MetalComboBoxButton Index: 6 Name: null
                   Level: 6 Component: javax.swing.CellRendererPane Index: 3 Name: null
                      Level: 7 Component: javax.swing.plaf.basic.BasicComboBoxRenderer$UIResource Index: 5 Name: null
                Level: 5 Component: javax.swing.JComboBox Index: 4 Name: speedSelect
                   Level: 6 Component: javax.swing.plaf.metal.MetalComboBoxButton Index: 7 Name: null
                   Level: 6 Component: javax.swing.CellRendererPane Index: 4 Name: null
                      Level: 7 Component: javax.swing.plaf.basic.BasicComboBoxRenderer$UIResource Index: 6 Name: null
                Level: 5 Component: javax.swing.JComboBox Index: 5 Name: siteSelect
                   Level: 6 Component: javax.swing.plaf.metal.MetalComboBoxButton Index: 8 Name: null
                   Level: 6 Component: javax.swing.CellRendererPane Index: 5 Name: null
                      Level: 7 Component: javax.swing.plaf.basic.BasicComboBoxRenderer$UIResource Index: 7 Name: null
                Level: 5 Component: javax.swing.JScrollPane Index: 0 Name: null
                   Level: 6 Component: javax.swing.JViewport Index: 0 Name: null
                      Level: 7 Component: javax.swing.JTextArea Index: 4 Name: showText
                   Level: 6 Component: javax.swing.JScrollPane$ScrollBar Index: 0 Name: null
                      Level: 7 Component: javax.swing.plaf.metal.MetalScrollButton Index: 9 Name: null
                      Level: 7 Component: javax.swing.plaf.metal.MetalScrollButton Index: 10 Name: null
                   Level: 6 Component: javax.swing.JScrollPane$ScrollBar Index: 1 Name: null
                      Level: 7 Component: javax.swing.plaf.metal.MetalScrollButton Index: 11 Name: null
                      Level: 7 Component: javax.swing.plaf.metal.MetalScrollButton Index: 12 Name: null

Going down a level and attempting even the most basic interactions with the application results in failure

如果需要,我不介意提供更多细节。多年来我一直坚持这个问题。

1 个答案:

答案 0 :(得分:0)

我发现了这个问题。

if (e.isPopupTrigger()) {
            menu.show(e.getComponent(), e.getX(), e.getY());
        }

的Javadoc:

Returns whether or not this mouse event is the popup menu trigger event for the platform. 

我认为Windows弹出菜单触发器与机器人框架swing库发送的触发器不同。右键单击组件传递并没有做任何事情,因为它确实传递了;它只是被if语句否定了。