Customize the format of the generated java code

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

Customize the format of the generated java code

Postby hyshyshys » Tue Apr 07, 2009 7:19 am

Hi,

Is it possible to customize the format of the generated java code using
1- code template,
2- formatter or
3- any other methods?

It is possible to generate code without hard-coded string in locator/condition/... Example:

Code: Select all
ui.click(new ButtonLocator("myHardCodedString"));


What I would prefer is to use a properties file with a Message class that hold all strings. This way, it will allow me to change the string in the user interface and updating tests rapidly instead of having to change all string elsewere in the tests.

Example:

Code: Select all

package org.eclipse.jdt.internal.corext;

import org.eclipse.osgi.util.NLS;

public final class Messages extends NLS {

   private static final String BUNDLE_NAME= "plugin.name.Messages";//$NON-NLS-1$

   private CorextMessages() {
      // Do not instantiate
   }

   public static String Application1_Dialog1_ButtonLabel1;

   static {
      NLS.initializeMessages(BUNDLE_NAME, Messages.class);
   }
}


and in the generated test

Code: Select all
ui.click(new ButtonLocator(Messages.Application1_Dialog1_ButtonLabel1));



Thanks

Vincent
hyshyshys
 
Posts: 37
Joined: Thu Jul 03, 2008 12:27 pm

Re: Customize the format of the generated java code

Postby Phil Quitslund » Wed Apr 08, 2009 10:20 am

Code generation customization is currently not supported but what you're proposing would make a really interesting feature request. Could you send a mail with the request to support?

wintest-support@instantiations.com

We'll track the request there.

Thanks!

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

Re: Customize the format of the generated java code

Postby hyshyshys » Wed Apr 08, 2009 6:01 pm

Done!
hyshyshys
 
Posts: 37
Joined: Thu Jul 03, 2008 12:27 pm

Re: Customize the format of the generated java code

Postby 3061 » Thu Apr 09, 2009 12:25 am

I ususally replace all the strings by constants manually (well, Eclipse refactoring tools help), having the Strings all extracted like

Code: Select all
public static final String BUTTON_TEXT_CANCEL = "Cancel";


Would be very comforable. "Cancel" might get randamed into "Abort" someday. It would be smart not to reference every String with "Cancel" into the same variable.
For example, let's say the "new File" Wizard has a "Cancel" Button and the "Generate lots of Data" Window also has a "Cancel button". Ideally, WindowTester would add the Window's Title into the variable name:

Code: Select all
public static final String NEW_FILE_WIZARD_CANCEL_BUTTON_TEXT = "Cancel";
public static final String GENERATE_LOTS_OF_DATA_CANCEL_BUTTON_TEXT = "Cancel";


This way, one could easily rename the "Cancel" Button in the "Generate lots of Data" Window without affecting the "new File" Wizard.
3061
 
Posts: 42
Joined: Mon Feb 23, 2009 12:43 am

Re: Customize the format of the generated java code

Postby Phil Quitslund » Tue Apr 14, 2009 7:52 am

Along the lines of this:

I ususally replace all the strings by constants manually (well, Eclipse refactoring tools help)


Do you tend to do this immediately after the test is generated? Is this something you would like folded into codegen? Moreover, is there anything the "Extract Constant" refactoring doesn't do but should for this purpose? On the surface, it seems like it should at least work in bulk so that you can extract all constants, but I'm curious if there's anything else you see.

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