Code to choose an item in auto-completion list doesn't work

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

Code to choose an item in auto-completion list doesn't work

Postby har_shan » Tue Mar 30, 2010 10:21 am

Issue #1:
WindowTester generated code to choose an item in auto-completion list doesn't work.
WindowTester tells WidgetNotFound even if it appears to be present.

Machine details:
>Product: WindowTester SWT Professional
>Version: 4.0.0.200910201517
>Expected: Eclipse 3.5
>Actual: Eclipse 3.5.0.v20090525
>Actual Eclipse Build Name:
>Actual Eclipse Build ID: M20090917-0800
>IDE Actual Name: Eclipse
>IDE Actual Version: 1.2.1.20090812-1036
>OS Name: Windows XP
>OS Architecture: x86
>OS Version: 5.1
>Priority: Standard
>Log Included: No

Code sample:

Code: Select all
public class WindowTesterDoubt extends UITestCaseSWT {

   @Override
   protected void setUp() throws Exception {
      super.setUp();
      IUIContext ui = getUI();
      ui.ensureThat(new WorkbenchLocator().hasFocus());
      ui.ensureThat(ViewLocator.forName("Welcome").isClosed());      
   }
   
   /** Issue 1: Auto-completion related */
   public void testAutoCompletion() throws Exception {
      IUIContext ui = getUI();

      // create a sample project
      ui.click(new MenuItemLocator("Window/Open Perspective/Java"));
      ui.contextClick(new SWTWidgetLocator(Tree.class, new ViewLocator(
            "org.eclipse.jdt.ui.PackageExplorer")), "Ne&w/Java Project");
      ui.wait(new ShellShowingCondition("New Java Project"));
      ui.enterText("Test");
      ui.click(new ButtonLocator("&Finish"));
      ui.wait(new ShellDisposedCondition("New Java Project"));

      // create a sample class with main()
      ui.contextClick(new TreeItemLocator("Test", new ViewLocator(
            "org.eclipse.jdt.ui.PackageExplorer")), "New/Class");
      ui.wait(new ShellShowingCondition("New Java Class"));
      ui.enterText("Sample");
      ui.click(new ButtonLocator("public static &void main(String[] args)"));
      ui.click(new ButtonLocator("&Finish"));
      ui.wait(new ShellDisposedCondition("New Java Class"));
      ui.click(new CTabItemLocator("Sample.java"));

      // XXX move the cursor inside main method via Find n Replace
      ui.click(new MenuItemLocator("Edit/Find\\\\/Replace..."));
      ui.wait(new ShellShowingCondition("Find/Replace"));
      ui.keyClick(WT.ALT, 'f');
      ui.enterText("// TODO Auto-generated method stub"); // enter find text
      ui.keyClick(WT.ALT, 'e');
      ui.enterText(""); // enter replacement text (empty)
      ui.click(new ButtonLocator("Fi&nd"));
      ui.click(new ButtonLocator("&Replace"));
      ui.click(new ButtonLocator("Close"));
      ui.wait(new ShellDisposedCondition("Find/Replace"));

      // Type 'Class c =' and auto-complete (Ctrl + Space bar) and choose
      // 'Sample', enter '.' and then choose 'class' from auto-completion proposal
      // again
      ui.enterText("Class c = ");
//      ui.keyClick(WT.CTRL, ' '); // FIXME doesn't work!
      autoComplete();
      ui.wait(new ShellShowingCondition(""));
      ui.click(2, new TableItemLocator("Sample")); // FIXME doesn't work!
      ui.enterText(".");
//      ui.keyClick(WT.CTRL, ' ');
      autoComplete();
      ui.wait(new ShellShowingCondition(""));
      ui.click(2, new TableItemLocator("class : Class<Sample>"));
      ui.enterText(";");

      // save the file
      ui.click(new MenuItemLocator("File/Save"));
   }
   
   protected void autoComplete() throws AWTException {
      Robot r = new Robot();
      r.keyPress(KeyEvent.VK_CONTROL);
      r.keyPress(KeyEvent.VK_SPACE);
      r.keyRelease(KeyEvent.VK_SPACE);
      r.keyRelease(KeyEvent.VK_CONTROL);            
   }

}


Have a look at the FIXME tags in the code, that represents this issue.

I know a workaround of using ARROW keys to choose a value, but i require a more generic solution.

Issue #2:

Am trying to hit Ctrl + Space bar (the key combination that we use for general auto-completion). Am using Java AWT's code as workaround (In attached code see autoComplete() method)

What is the WindowTester WT field to hit SPACE bar key?

Code: Select all
ui.keyClick(WT.CTRL, ???);


Thanks in advance.
har_shan
 
Posts: 5
Joined: Tue Mar 30, 2010 10:10 am

Re: Code to choose an item in auto-completion list doesn't work

Postby keertip » Wed Mar 31, 2010 1:54 pm

Issue #1 :
For the auto completion issue, we are sorry to say that as of now we do not have any other generic workaround, apart from using keystrokes to navigate the pop up. The problem here is that the shell that pops up is different and requires special handling, unlike the shells in wizards, dialog etc. This is not there in WindowTester right now and needs to be implemented.

We will add this to our feature request and work towards a solution. Sorry, we do not have an immediate solution.

Issue# 2 :
To press Ctrl + space bar in WindowTester you would use
Code: Select all
ui.keyClick(WT.CTRL, " ");


This code works fine on our end and we are able to see the auto completion dialog after execution of keyClick. Is there anything more you can tell us about your eclipse environment?
keertip
Moderator
 
Posts: 221
Joined: Thu Mar 15, 2007 10:26 am


Return to Window Tester

Who is online

Users browsing this forum: No registered users and 1 guest