For some reason, when I check for the isEnabled condition of a Button in a Wizard Window, the Window gets close and the Unit Test fails every time.
I have an application where you need to enter some data into text fields and the "Finish" button is grayed out (inactive) until the data entered is valid. Now my GUI test enters false data and I want to make sure the button is correctly grayed out. My software may take some time to verify if the entered data is valid, so I needed to build in a simple timer to avoid WindowTester's WaitTimedOutException. I made this method to check if the button is active (clickable):
Here's the code:
- Code: Select all
protected boolean buttonIsClickable(String buttonString)
{
long waitTimeOutInMilliseconds = 1000; // wait for 1 second tops
int waitStepInMilliseconds = 10; // check state every 1/100 second
boolean isClickable = true;
try
{
// FIXME For some reason, the wizard window gets closed during this.
ui.wait(new ButtonLocator(buttonString).isEnabled(true), waitTimeOutInMilliseconds, waitStepInMilliseconds);
}
catch (WaitTimedOutException w) // happens if button is still grayed out
{
isClickable = false;
}
return isClickable;
}
What my test does (in order):
- enter false data into the text fields of the wizard window
- check if the button is enabled (clickable)
- if the "Finish" button can't be clicked, the test enters a random string (just letters and numbers) into one of the text fields to pass the software's name duplication checker.
- if the "Finish" button is enabled, it just clicks it.
Here's the code for that:
- Code: Select all
String B_FINISH = "&Finish";
[...]
/** Fills out the name field in a wizard and clicks the "Finish" button
*
* @param newObjectName What is entered in a "New" Wizard in the "Name" field
* If, for some reason, the given name can't be used (could be a duplicate),
* this method will try a few new random names instead.
*/
private void enterNewObjectNameAndFinishWizard(String newObjectName) throws Exception
{
enterNewPackeNameInNewPackageWizard(newObjectName);
for(int n = 0; n < 10; n++ )
{
if (buttonIsClickable(B_FINISH)) // i.e. not grayed out
{
System.out.println("Button is clickable. Clicking...");
clickOnFinishButtonInNewPackageWizard();
break;
}
else // button is grayed out
{
// FIXME the Wizard window gets closed, even when "Finish" could not be clicked
System.err.println("Button not clickable. Trying again with random name");
enterNewPackeNameInNewPackageWizard(getRandomConformantName());
}
}
//waitForJobsComplete();
}
The buttonIsClickable-method (code above) returns the right value when the button is grayed out and "Button not clickable. Trying again with random name" is correctly outputed to std.err. However the wizard window gets closed in the process and then WindowTester can't find the text fields when the test tries again with random name:
- Code: Select all
com.windowtester.runtime.WidgetNotFoundException: Widget NOT Found:
LabeledLocator(org.eclipse.swt.widgets.Text, "Name:")
at com.windowtester.runtime.swt.internal.UIContextSWT.find(UIContextSWT.java:608)
at com.windowtester.runtime.swt.internal.UIContextSWT.find(UIContextSWT.java:583)
at com.windowtester.runtime.swt.internal.UIContextSWT.find(UIContextSWT.java:583)
at com.windowtester.runtime.swt.internal.UIContextSWT.find(UIContextSWT.java:583)
at com.windowtester.runtime.swt.internal.UIContextSWT.find(UIContextSWT.java:583)
at com.windowtester.runtime.swt.internal.UIContextSWT.find(UIContextSWT.java:583)
at com.windowtester.runtime.swt.internal.UIContextSWT.find(UIContextSWT.java:583)
at com.windowtester.runtime.swt.internal.UIContextSWT.find(UIContextSWT.java:583)
at com.windowtester.runtime.swt.internal.UIContextSWT.find(UIContextSWT.java:583)
at com.windowtester.runtime.swt.internal.UIContextSWT.find(UIContextSWT.java:583)
at com.windowtester.runtime.swt.internal.UIContextSWT.find(UIContextSWT.java:583)
at com.windowtester.internal.runtime.selector.ClickHelper.doFind(ClickHelper.java:192)
at com.windowtester.internal.runtime.selector.ClickHelper.click(ClickHelper.java:58)
at com.windowtester.internal.runtime.UIContextCommon.click(UIContextCommon.java:82)
at com.windowtester.runtime.swt.internal.UIContextSWT.click(UIContextSWT.java:296)
at com.windowtester.internal.runtime.UIContextCommon.click(UIContextCommon.java:75)
at com.windowtester.runtime.swt.internal.UIContextSWT.click(UIContextSWT.java:304)
at [...].newWizards.TestNewPackageWizard.enterNewPackeNameInNewPackageWizard(TestNewPackageWizard.java:223)
at [...].newWizards.TestNewPackageWizard.enterNewObjectNameAndFinishWizard(TestNewPackageWizard.java:166)
at [...].newWizards.TestNewPackageWizard.createPackageByTypingParentPackage(TestNewPackageWizard.java:129)
at [...].newWizards.TestNewPackageWizard.testSimplePackageCreationByTypingParentPackage(TestNewPackageWizard.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at com.windowtester.runtime.common.UITestCaseCommon.access$001(UITestCaseCommon.java:25)
at com.windowtester.runtime.common.UITestCaseCommon$2.run(UITestCaseCommon.java:136)
at com.windowtester.runtime.common.UITestCaseCommon$3.run(UITestCaseCommon.java:157)
at com.windowtester.internal.runtime.junit.core.SequenceRunner$1.run(SequenceRunner.java:46)