Tuesday 11 November 2014

Possible Exceptions and their cause in Coded UI


Here are some of the guidelines to troubleshoot the failure during recording/playback.

 

Recording Time Failures


Possible ExceptionCauseComment
TechnologyNotSupportedExceptionRecoding on a unsupported technology AppAs mentioned above Winforms/WPF/Web are three different kind of technologies supported by UITest so if user tries to record on some other technology we fail with the following exception.
ApplicationFromNetworkShareExceptionRecording on a Network share applicationThis occurs when the recording is being done on a network share App.


Playback time failures

Playback does two major things in order to perform action on the control search and action on the control. Following are the possible reasons and their exceptions.

Search Failure


Following are some of the suggested tips to debug the search failure during playback.

Possible ExceptionCauseComment
UITestControlNotFoundExceptionThe control does not exist or search properties are not enough to find the controlUser can use AccExplorer and see whether the search properties and the hierarchy are correct
UITestControlNotAvailableExceptionThe control does not exist in the app now.If the control has been invalidated or deleted during the playback, the window handle and other properties related to it would be invalid then.

Action Failure


Sometime though the search passes but the playback may not be able to do the action on the control. Following may be the possible reason/tips to debug the issue

Possible ExceptionCauseComment/Possible workarounds
ActionNotSupportedOnDisabled
ControlException
Playback is trying to perform action on a disabled controlThis is thrown when the playback try to do some action on the disabled control/read only controls. Following are some of the cases:
· SetValue on a read only combobox/text box
· Click/SetState on buttons/checkboxes
FailedToLaunchApplicationExceptionWhen the playback fails to launch the AuTVerify whether the LaunchApp was recorded on the original exes or on some other file e.g., sometime if a App launches SPLASH screen before the original AuT LaunchApp is recorded on splash screen, user can work around this in API playback by changing the path
FailedToPerformActionOnBlocked
ControlException
The control exists but not actionableThrown when a control is blocked in this case though the search passes but the required action will not be played back. Following might be some of the causes for this exception
· The control is not visible in the view port and not scrollable even
· Control is blocked due to some modal dialog on top of it
DecodingFailedExceptionMay come in password text boxWhen the decoding fails due to incorrect key value in password encryption.
PlaybackFailureExceptionDefault fall back exception for uncategorized issuesFor any other failure the playback engine would throw PlaybackFailureException. For example if Get/Set of some property fails for a control playback engine would throw PlaybackFailureException.

Monday 10 November 2014

Search Configurations for the control in CodedUI


Apart from the control specific properties, some other properties may be required to identify the control, e.g., if the control is nameless or the parent has to be expended before looking for a control e.g, tree item. Following are some of those.

Search configuration of the control


We have some predefined search configuration which helps to narrow down the search space (search only in visible controls) or to do perform some prerequisite before actually starting the search (expand parent tree node before searching for the child node). Following are the different search configs:

SearchConfig ParameterDescription
AlwaysSearchUITest uses a cache while doing actions on an Application by adding Always Search in the search config user can force UITest to not to use the cached value for the control.
DisambiguateSearchIf the parent and the controls properties are same there are chances that UITest would start doing action on the parent itself. This config can be used to ask the playback to act on its child rather than the parent itself.
ExpandWhileSearchingExpand the control before looking for the other control inside it. E.g., TreeView
NextSiblingSearch in the siblings inside the container. Sometime if the control is nameless we may iterate from the named control inside the same container to reach the control.
VisibleOnlySearch only in the visible control. It helps to reduce the search space.

Sunday 2 November 2014

Resizing browser window using CodedUI


How to test your websites responsive UI design with codedUI.
The main requirement here is that you would be able to check if you can enter values on a specific screen in different browsers in different window sizes.
So starting the browser in CodedUI is simple, you just use the BrowserWindow class and call the Launch method to start the browser in a reliable way. Starting different browsers (Chrome, firefox) is also possible by just setting theBrowserWindow.CurrentBrowser to a value of “chrome” or “firefox” so that is already solved.
The main issue is the size of the browser window. For the responsive UI to show, you need to run a test case in e.g. different screen sizes. Unfortunately there is no method on the BrowserWindow class to set the screen size of the browser.
But there is an easy fix for that.
The BrowserWIndow class has a property called WindowHandle. We can use this property to call a windows API to resize the window.
First an extension method if to be defined as below.
    public static class BrowserWindowExtensions
    {
        [DllImport("user32.dll", SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        internal static extern bool SetWindowPos(IntPtr hWnd, IntPtr hwndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
        public static void ResizeWindow(this BrowserWindow control, int width, int height)
        {
            SetWindowPos(control.WindowHandle, (IntPtr)(-1), 0, 0, width, height, 0x0002 | 0x0040);
        }
    }
then the TestMethod looks as shown below
        [TestMethod]
        public void BrowserResizing()
        {
            //define for Chrome
            BrowserWindow.CurrentBrowser = "Chrome";
            BrowserWindow myb = BrowserWindow.Launch();
            myb.NavigateToUrl(new System.Uri("http://bing.com/"));
            myb.Maximized = true;
            BrowserWindowExtensions.ResizeWindow(myb, 480, 800);
        }
the same is applicable for IE and Firefox.