Skip to content

Commit

Permalink
Fix for Add Select From List Item Popup Menu keyword MarketSquare#118
Browse files Browse the repository at this point in the history
  • Loading branch information
John Doe committed Nov 7, 2018
1 parent 34feb6a commit aa5f06f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@

import org.apache.commons.collections.CollectionUtils;
import org.junit.Assert;
import org.netbeans.jemmy.operators.JMenuItemOperator;
import org.netbeans.jemmy.operators.JPopupMenuOperator;
import org.robotframework.javalib.annotation.ArgumentNames;
import org.robotframework.javalib.annotation.RobotKeyword;
import org.robotframework.javalib.annotation.RobotKeywordOverload;
import org.robotframework.javalib.annotation.RobotKeywords;
import org.robotframework.swing.common.IdentifierSupport;
import org.robotframework.swing.comparator.EqualsStringComparator;
import org.robotframework.swing.factory.OperatorFactory;
import org.robotframework.swing.list.ListOperator;
import org.robotframework.swing.list.ListOperatorFactory;
import org.robotframework.swing.table.TableOperator;
import org.robotframework.swing.util.SwingInvoker;

@RobotKeywords
Expand Down Expand Up @@ -143,7 +147,23 @@ public void listShouldNotContain(String identifier, String value) {
Assert.assertTrue("List " + identifier + " contains " + value,
!getListValues(identifier).contains(value));
}


@RobotKeyword("Selects an item from a list item popup.\n"
+ "Separator for items is ``|``.\n\n"
+ "Example:\n"
+ "| `Select From List Item Popup Menu` | myList | listItem | File|Exit | ")
@ArgumentNames({"identifier", "listItemIdentifier", "menuPath"})
public void selectFromListItemPopupMenu(String identifier, String listItemIdentifier, String menuPath) {
JMenuItemOperator menuItem = getPopupMenuItem(identifier, listItemIdentifier, menuPath);
menuItem.push();
}

private JMenuItemOperator getPopupMenuItem(String identifier, String listItemIdentifier, String menuPath) {
ListOperator listOperator = createOperator(identifier);

This comment has been minimized.

Copy link
@cristii006

cristii006 Nov 9, 2018

Please remove unnecessary spacing in this line ListOperator listOperator = createOperator(identifier);

JPopupMenuOperator popupMenuOperator = listOperator.callPopupOnListItem(listItemIdentifier);
return popupMenuOperator.showMenuItem(menuPath, new EqualsStringComparator());
}

private ListOperator createOperator(String identifier) {
return operatorFactory.createOperator(identifier);
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/robotframework/swing/list/ListOperator.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.robotframework.swing.list;

import java.awt.Component;
import java.awt.Point;
import java.awt.event.InputEvent;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -10,6 +12,7 @@
import org.netbeans.jemmy.Waiter;
import org.netbeans.jemmy.operators.ContainerOperator;
import org.netbeans.jemmy.operators.JListOperator;
import org.netbeans.jemmy.operators.JPopupMenuOperator;
import org.robotframework.swing.common.IdentifierSupport;
import org.robotframework.swing.common.TimeoutCopier;
import org.robotframework.swing.common.TimeoutName;
Expand Down Expand Up @@ -57,6 +60,14 @@ public int getSize() {
return jListOperator.getModel()
.getSize();
}

public JPopupMenuOperator callPopupOnListItem(String itemIdentifier) {
Point coordinates = jListOperator.indexToLocation(findIndex(itemIdentifier));
return new JPopupMenuOperator(JPopupMenuOperator.callPopup(getSource(),
(int)coordinates.getX(),
(int)coordinates.getY(),
InputEvent.BUTTON3_MASK));
}

public void selectAll() {
jListOperator.setSelectionInterval(0, getSize() - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public void hasSelectAllListItemsKeyword() {
public void hasClickOnListItemKeyword() {
specify(context, satisfies(new RobotKeywordContract("clickOnListItem")));
}

public void hasSelectFromListItemPopupMenuKeyword() {
specify(context, satisfies(new RobotKeywordContract("selectFromListItemPopupMenu")));
}
}

public class Operating {
Expand Down
6 changes: 6 additions & 0 deletions src/test/resources/robot-tests/list.robot
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ List Should Not Contain
List Should Not Contain ${listName} missing element
runKeywordAndExpectError List ${listName} contains one List Should Not Contain ${listName} one

Select From List Item Popup Menu
selectFromListItemPopupMenu ${listName} three Show name
dialogShouldBeOpen Message
selectDialog Message
pushButton OK

*** Keywords ***
listSelectionShouldBe
[Arguments] ${listIndex} ${expectedValue}
Expand Down

1 comment on commit aa5f06f

@cristii006
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@badari412 Thanks for your PR . There would be one change that should be done. Could you update the acceptance test to something like Select From Popup Menu https://github.com/robotframework/SwingLibrary/blob/master/src/test/resources/robot-tests/menu.robot .

Please sign in to comment.