Context menu items

WindowTester allows you to easily create and run unit tests for every GUI they build. It can also be used to generate system level tests.

Moderators: gnebling, Eric Clayberg, Dan Rubel, keertip, Phil Quitslund

Context menu items

Postby nortega » Wed Sep 09, 2009 11:15 am

Is there a way to check if a context menu item is enabled or disabled? I am a new user and I'm still exploring. Thanks.
nortega
 
Posts: 6
Joined: Wed Sep 09, 2009 11:07 am

Re: Context menu items

Postby Phil Quitslund » Wed Sep 09, 2009 1:51 pm

There is currently no easy way to assert properties of context menu contents. That said, if you have a specific case, we can probably help you with a work-around. Just let us know!
--
Phil Quitslund
Software Engineer
Google, Inc.
Phil Quitslund
Moderator
 
Posts: 491
Joined: Fri Apr 28, 2006 6:26 am

Re: Context menu items

Postby nortega » Thu Sep 10, 2009 2:06 pm

I need to verify that a context menu item is disabled or enabled, depending on the situation. Is there a way to just open the context menu without actually clicking on something?
nortega
 
Posts: 6
Joined: Wed Sep 09, 2009 11:07 am

Re: Context menu items

Postby Phil Quitslund » Fri Sep 11, 2009 9:04 am

There is no API for this. If this is important to you, consider submitting a feature request and we will investigate. In the meantime, here's a sketch of a (non-API) approach.
Code: Select all
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.swt.widgets.Widget;

import com.windowtester.event.swt.UIDriver;
import com.windowtester.runtime.IUIContext;
import com.windowtester.runtime.WT;
import com.windowtester.runtime.WaitTimedOutException;
import com.windowtester.runtime.locator.IWidgetReference;
import com.windowtester.runtime.swt.UITestCaseSWT;
import com.windowtester.runtime.swt.locator.MenuItemLocator;
import com.windowtester.test.eclipse.BaseTest;

public class PopupStateTest extends UITestCaseSWT {

   public void testMenuItemStatus() throws Exception {
      IUIContext ui = getUI();
      TreeItem item = findItem(ui);
      verifyEnablement(ui, item);
   }

   private TreeItem findItem(IUIContext ui) {
        IWidgetReference itemRef = (IWidgetReference) ui.find(...); //some criteria to find the item
        return (TreeItem) itemRef.getWidget();
   }

   private void verifyEnablement(IUIContext ui, TreeItem item)
         throws WaitTimedOutException {
      contextClick(item);
      // give it a few seconds to pop up... (a condition would be better)
      ui.pause(3000);
      // assert that the delete menu item is enabled
      ui.assertThat(new MenuItemLocator("Delete").isEnabled());

      ui.keyClick(WT.ESC); // dismiss menu
   }

   // Notice these warnings: not really API for this...
   @SuppressWarnings( { "restriction", "deprecation" })
   private void contextClick(Widget widget) {
      new UIDriver().click(widget, WT.BUTTON3);
   }

}


If you find yourself depending on something like this, please send us a feature request so that you can do it using proper API.

Thanks!
--
Phil Quitslund
Software Engineer
Google, Inc.
Phil Quitslund
Moderator
 
Posts: 491
Joined: Fri Apr 28, 2006 6:26 am


Return to Window Tester

Who is online

Users browsing this forum: No registered users and 1 guest