@RobotKeyword("Selects an item from the menu of the currently selected window " + "and waits for action to finish.\n" + "This keyword will not work, for example, if the menu item opens a dialog.\n\n" + "Example:\n" + "| `Select Window` | My Application |\n" + "| `Select From Menu And Wait` | Tools|Testing|MyTestTool |\n") @ArgumentNames({"menuPath"}) public void selectFromMenuAndWait(String menuPath) { JMenuItemOperator operator = showMenuItem(menuPath); Assert.assertTrue("Menu item '" + menuPath + "' is disabled.", operator.isEnabled()); operator.push(); }
public JMenuItemOperator chooseMenuItem(JFrameOperator mainFrame, boolean pushLastLevel, Object... menuNames) throws Exception { int waitBetweenItems = 1000; JMenuItemOperator selectedItem = null; for (int index = 0; index < menuNames.length; index++) { String name = (String) menuNames[index]; selectedItem = new JMenuItemOperator(mainFrame, name); if (selectedItem == null) { throw new Exception("Failed to find Menu Item operator " + name); } // Push every level, and the last level only if asked if ((index != menuNames.length - 1) || pushLastLevel) { // Pushing "no block" since in some cases we just want to see // the // sub menu and not make an action selectedItem.pushNoBlock(); } Thread.sleep(waitBetweenItems); } return selectedItem; }
private static void closeToolbar(String menu){ MainWindowOperator mainWindow = MainWindowOperator.getDefault(); JMenuBarOperator menuBar = new JMenuBarOperator(mainWindow.getJMenuBar()); JMenuItemOperator menuItem = menuBar.showMenuItem(menu,"|"); if(menuItem.isSelected()) menuItem.push(); else { menuItem.pushKey(java.awt.event.KeyEvent.VK_ESCAPE); mainWindow.pushKey(java.awt.event.KeyEvent.VK_ESCAPE); } }
@RobotKeyword("Selects an item from the menu of the currently selected window.\n\n" + "Example:\n" + "| `Select Window` | My Application |\n" + "| `Select From Menu` | Tools|Testing|MyTestTool |\n") @ArgumentNames({"menuPath"}) public void selectFromMenu(String menuPath) { JMenuItemOperator operator = showMenuItem(menuPath); Assert.assertTrue("Menu item '" + menuPath + "' is disabled.", operator.isEnabled()); operator.pushNoBlock(); }
public Boolean doWithMenuItem() { return showMenuItem(menuPath).isEnabled(); } });
@RobotKeyword("Selects an item from a table cell popup.\n" + "Separator for items is ``|``.\n\n" + "Example:\n" + "| `Select From Table Cell Popup Menu` | myTable | 1 | 3 | Cell Actions|Clear Cell Value | ") @ArgumentNames({"identifier", "row", "columnIdentifier", "menuPath"}) public void selectFromTableCellPopupMenu(String identifier, String row, String columnIdentifier, String menuPath) { JMenuItemOperator menuItem = getPopupMenuItem(identifier, row, columnIdentifier, menuPath); menuItem.push(); }
protected List<JMenuItemOperator> getChildren(final String path) { List<JMenuItemOperator> returnable = new ArrayList<JMenuItemOperator>(); for (MenuElement e : getSubElements(path)) { if(JMenuItem.class.isAssignableFrom(e.getClass())) { returnable.add(new JMenuItemOperator((JMenuItem)e)); } } return returnable; }
private MenuElement[] getSubElements(String path) { MenuElement[] subElements = menubarOperator().showMenuItem(path).getSubElements(); if (subElements.length == 0) { return new MenuElement[0]; } return subElements[0].getSubElements(); } }
@Override protected JCheckBoxMenuItemOperator showMenuItem(String path) { JMenuItemOperator menuItemOperator = super.showMenuItem(path); return new JCheckBoxMenuItemOperator((JCheckBoxMenuItem) menuItemOperator.getSource()); } }
@RobotKeyword("Gets names of menu items.\n\n" + "Returns empty list if menu item has no children.\n\n" + "Examples:\n" + "| @{menus} | `Get Menu Item Names` | Tools|Testing |\n" + "| `Should Contain` | ${menus} | Test Tool |\n" + "| @{empty} | `Get Menu Item Names` | Tools|empty |\n" + "| `Should Be Empty` | ${empty} |\n") @ArgumentNames({"menuPath"}) public List<String> getMenuItemNames(String menuPath) { List<String> returnable = new ArrayList<String>(); menuItemShouldExist(menuPath); for (JMenuItemOperator mio : getChildren(menuPath)) { returnable.add(mio.getText()); } return returnable; }
@RobotKeyword("Fails if the given table cell popup menu is disabled.\n" + "Separator for items is ``|``.\n\n" + "Example:\n" + "| `Table Cell Popup Menu Should Be Enabled` | myTable | 1 | 3 | Cell Actions|Clear Cell Value |\n") @ArgumentNames({"identifier", "row", "columnIdentifier", "menuPath"}) public void tableCellPopupMenuShouldBeEnabled(String identifier, String row, String columnIdentifier, String menuPath) { JMenuItemOperator menuItem = getPopupMenuItem(identifier, row, columnIdentifier, menuPath); String errorMessage = "Menuitem '" + menuPath + "' at '" + row + ", " + columnIdentifier + "' is disabled."; Assert.assertTrue(errorMessage, menuItem.isEnabled()); }
public void callPopupMenuItemOnSelectedCells(String menuPath) { int selectedRow = jTableOperator.getSelectedRow(); int selectedColumn = jTableOperator.getSelectedColumn(); JPopupMenuOperator menuOperator = new JPopupMenuOperator( jTableOperator.callPopupOnCell(selectedRow, selectedColumn)); JMenuItemOperator item = menuOperator.showMenuItem(menuPath, new EqualsStringComparator()); item.push(); }
@RobotKeyword("Gets item names from the components context popup menu.\n" + "Does a right click on the component and retrieves the specified menu items from the popup menu.\n\n" + "Example:\n" + "| @{items}= | `Get Menu Items From Popup Menu` | myComponent | Actions |\n" + "| `Should Contain` | ${items} | Do something |") @ArgumentNames({ "identifier", "menuPath" }) public List<String> getMenuItemsFromPopupMenu(final String identifier, final String menuPath) { JPopupMenuOperator popup = operator(identifier).invokePopup(); if (menuPath == null || "".equals(menuPath)) { return ComponentUtils.getParsedElements(popup.getSubElements()); } JMenuItemOperator subItem = popup.showMenuItem(menuPath); return subItem.getSubElements().length < 1 ? new ArrayList<String>() : ComponentUtils.getParsedElements(subItem.getSubElements()[0].getSubElements()); }
private static void closeToolbar(String menu){ MainWindowOperator mainWindow = MainWindowOperator.getDefault(); JMenuBarOperator menuBar = new JMenuBarOperator(mainWindow.getJMenuBar()); JMenuItemOperator menuItem = menuBar.showMenuItem(menu,"|"); if(menuItem.isSelected()) menuItem.push(); else { menuItem.pushKey(java.awt.event.KeyEvent.VK_ESCAPE); mainWindow.pushKey(java.awt.event.KeyEvent.VK_ESCAPE); } }
@RobotKeyword("Fails if the given table cell popup menu is enabled.\n" + "Separator for items is ``|``.\n\n" + "Example:\n" + "| `Table Cell Popup Menu Should Be Disabled` | myTable | 1 | 3 | Cell Actions|Clear Cell Value |\n") @ArgumentNames({"identifier", "row", "columnIdentifier", "menuPath"}) public void tableCellPopupMenuShouldBeDisabled(String identifier, String row, String columnIdentifier, String menuPath) { JMenuItemOperator menuItem = getPopupMenuItem(identifier, row, columnIdentifier, menuPath); String errorMessage = "Menuitem '" + menuPath + "' at '" + row + ", " + columnIdentifier + "' is enabled."; Assert.assertFalse(errorMessage, menuItem.isEnabled()); }
@RobotKeyword("Gets item names from the node context popup menu.\n" + "Clears earlier selections.\n" + "If several nodes have the same path then *only the first* menu item names of those nodes are returned.\n\n" + "Example:\n" + "| @{items}= | `Get Node Items From Tree Popup Menu` | myTree | Root|Folder | Actions |\n" + "| `Should Contain` | ${items} | Do something |") @ArgumentNames({"identifier", "nodeIdentifier", "menuPath"}) public List<String> getNodeItemsFromTreePopupMenu(String identifier, String nodeIdentifier, String menuPath) { JPopupMenuOperator popupMenuOperator = treeOperator(identifier).createPopupOperator(nodeIdentifier); if (menuPath == null || menuPath.isEmpty()) { return ComponentUtils.getParsedElements(popupMenuOperator.getSubElements()); } else { JMenuItemOperator subItem = popupMenuOperator.showMenuItem(menuPath); return subItem.getSubElements().length < 1 ? new ArrayList<String>() : ComponentUtils.getParsedElements(subItem.getSubElements()[0].getSubElements()); } }
private static Node performTomcatServerAction(String action) { Node asNode = getTomcatServerNode(); asNode.select(); new EventTool().waitNoEvent(10000); String serverIDEName = asNode.getText(); log("ServerNode name = "+serverIDEName); JPopupMenuOperator popup = asNode.callPopup(); if (popup == null) { throw new Error("Cannot get context menu for Tomcat server node "); } boolean startEnabled = popup.showMenuItem(action).isEnabled(); if(startEnabled) { popup.pushMenuNoBlock(action); } return asNode; }
private static Node performTomcatServerAction(String action) { Node asNode = getTomcatServerNode(); asNode.select(); new EventTool().waitNoEvent(10000); String serverIDEName = asNode.getText(); log("ServerNode name = "+serverIDEName); JPopupMenuOperator popup = asNode.callPopup(); if (popup == null) { throw new Error("Cannot get context menu for Tomcat server node "); } boolean startEnabled = popup.showMenuItem(action).isEnabled(); if(startEnabled) { popup.pushMenuNoBlock(action); } return asNode; }