XAF - EasyTest Improvements (coming in v2011 vol 1)

XAF Team Blog
28 April 2011

As you know, XAF is shipped with EasyTest functional test framework. In the upcoming release, we made a number of changes in the EasyTest script commands. Several new commands were introduced, and the existing commands functionality was extended. The main aim of the improvements we made is to simplify testing of XAF applications that have both Windows Forms and ASP.NET versions.

Although XAF can produce Windows Form and ASP.NET applications with the same functionality, there are differences in their behavior. Previously, you had to use the IfDef EasyTest command to control test flow, depending on which application is testing. Commonly encountered issues are:

- To modify the current object in ASP.NET applications, you should switch the Detail View to edit mode via the Edit Action. There is no Edit Action in Windows Forms applications, as the Detail View is initially editable.

- The broken validation rules are displayed in a different manner. In Windows Forms applications, the ValidationWindowsFormsModule module handles broken rules and displays validation results in a separate View. In ASP.NET applications, the validation error messages are displayed as any other error messages in the current page via the ErrorInfoControl control (see Error Handling in ASP.NET Applications).

There are other differences in behavior, but the two above are most significant. The following improvements were introduced to a number of IfDef/EndIf commands in tests.

OptionalAction command introduced

The new OptionalAction command acts like the old Action command. The difference is that this command does not require the target control to be visible and active. If the Action is unavailable, this command simply does nothing. Let us consider the following script snippet:

    1 *ProcessRecord

    2  Last Name = Tellitson

    3 #IfDef MainDemoWin

    4 Action Edit

    5 #EndIf

    6 *FillForm

    7  Birthday = 11/28/1980

With the new OptionalAction command, it can be rewritten in the following manner:

    1 *ProcessRecord

    2  Last Name = Tellitson

    3 *OptionalAction Edit

    4 *FillForm

    5  Birthday = 11/28/1980

CheckValidationResult command introduced

The new CheckValidationResult command tests the validation results that are currently displayed. It supports both Windows Forms and ASP.NET representation of validation results (pop-up window and ErrorInfo control, respectively). The following secondary parameters can be specified:

· Message - optional. Checks the primary validation error message.

· Columns - optional. Considered for Windows Forms applications. It specifies captions of the DisplayableValidationResultItem List View columns to be tested. You can specify two Target and Description column captions, or a single 'Description' column. If the Columns parameter is omitted and the Info property specifies a target name and a description text, then columns with the "Target" and "Description" captions are tested. If the Columns parameter is omitted and the Info property specifies a description text only, then a column with the "Description" caption is tested.

· Info - optional. Checks validation results (rule target and description) of each broken rule. You can specify target name and description text separated by comma, or description text only.

· SkipUnexpectedErrors - optional. When set to True, disables checking the validation errors that are not specified by Info parameters. The default value is False, so the CheckValidationResult command execution fails when there are unexpected validation errors.

Let us consider the following script snippet that can be used to test validation results in previous version of XAF:

    1 #IfDef MainDemoWin

    2 *CheckFieldValues

    3  ValidationResultsText = Problems were detected during data validation. Please read the information below to understand what the issues are and how you can correct them.

    4 *CheckTable

    5  Columns = Description

    6  Row = "Title" must not be empty.

    7 *Action Close

    8 #EndIf

    9 #IfDef MainDemoWeb

   10 *FieldVisible ErrorInfo

   11 *CheckFieldValues

   12  ErrorInfo[0] = Problems were detected during data validation. Please read the information below to understand what the issues are and how you can correct them.

   13  ErrorInfo[1] = - "Title" must not be empty.

   14 #EndIf

With the new CheckValidationResult command, it can be rewritten in the following manner:

    1 *CheckValidationResult

    2  Message = Problems were detected during data validation. Please read the information below to understand what the issues are and how you can correct them.

    3  Info = "Title" must not be empty.

    4 *OptionalAction Close

Note a use of the OptionalAction command in this scenario. It closes the validation pop-up window in the Windows Forms application.

New capabilities of the HandleDialog command

Now, this command supports messages displayed via the ErrorInfoControl in ASP.NET applications. So, this script snippet:

    1 *Action Log On

    2 #IfDef MySolutionWeb

    3 *CheckFieldValues

    4  ErrorInfo = Login failed for 'UnExistingUser'. Make sure your user name is correct and retype the password in the correct case.

    5 #EndIf

    6 #IfDef MySolutionWin

    7 *HandleDialog

    8  Message = Login failed for 'UnExistingUser'. Make sure your user name is correct and retype the password in the correct case.

    9  Respond = OK

   10 #EndIf

…can be rewritten as:

    1 *Action Log On

    2 *HandleDialog

    3  Message = Login failed for 'UnExistingUser'. Make sure your user name is correct and retype the password in the correct case.

    4 *OptionalAction OK

Additionally, the HandleDialog command takes the optional Caption parameter now. You can check the active window caption in a Windows Forms application and the document title in an ASP.NET application with this parameter:

    1 *HandleDialog

    2  Caption = MainForm

Another significant improvement is that the HandleDialog command supports browser’s confirmation messages now (for instance, displayed when executing an Action that has the ActionBase.ConfirmationMessage property specified). To test confirmations in an XAF application that was updated from the previous XAF version, remove the following line from the Application_Start method in the Global.asax.cs file:

ConfirmationsHelper.IsConfirmationsEnabled = false;

The FillForm command improvements

Previously, to select a value in a lookup field, you had to write the following code:

    1 #IfDef MySolutionWin

    2 *FillForm

    3  Department = Sales Department

    4 #EndIf

    5 #IfDef MySolutionWeb

    6 *ExecuteEditorAction LookupField(Find)

    7 *Action Filter by Text(Sales Department)

    8 *SelectRecords

    9  Columns = Name

   10  Row = Sales Department

   11 *Action OK

   12 #EndIf

The FillForm command supports Lookup Property Editors in ASP.NET applications now, and this test can be much simplified:

    1 *FillForm

    2  Department = Sales Department

The ExecuteEditorAction command improvements

Previously, to execute an action displayed within a lookup, you had to write the following code:

    1 #IfDef MyAppWin

    2 *ExecuteEditorAction Status

    3 *Action New

    4 #EndIf

    5 #IfDef MyAppWeb

    6 *ExecuteEditorAction Status(New)

    7 #EndIf

Now you can pass an argument to the ExecuteEditorAction command when testing Windows Forms applications. So, the IfDef commands are not required:

    1 *ExecuteEditorAction Status(New)

Wildcard support

You can use the question mark (?) and asterisk character (*) as wildcards in parameter values EasyTest commands. The ? wildcard substitutes for any one character, and * - for any zero or more characters.

    1 *CheckValidationResult

    2  Message = Problems were detected during data validation.*

Preceded ? and * with a backslash (\), if you test a text that actually contains these characters.

    1 *HandleDialog

    2  Message = Do you want to cancel your changes\?

To test that an error message was not displayed, use the following code:

    1 !HandleDialog

    2  Message = ?*

What do you Xafers think of EasyTest? Do you see anything missing?

Happy EasyTesting!

Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.