Renu
Renu

Reputation: 91

How to maximize a desktop application using TestStack.White after it is minimized

I have a code to minimize a desktop application using a minimize button at the top right button of the application.

But once it is minimized i have to do some operations with the browser and again switch back to desktop application. I face code issue here, where i need to click the application button in the task bar to maximize it.

Can anyone please help me on this or any other way to maximize the minimized application? i shouldn't close or reopen it, as some uploading will be in-progress.

Upvotes: 1

Views: 2045

Answers (2)

montonero
montonero

Reputation: 1761

WinPattern is no longer public. Instead, you can use a DisplayState property. E. g.:

wnd.DisplayState= DisplayState.Maximized;

Upvotes: 2

Max Young
Max Young

Reputation: 1662

So after looking into how White exposes the WindowPattern I was able to find a public property on the Window class called WinPattern which returns a WindowPattern. After getting the window pattern you should be able to call WindowPattern.SetWindowVisualState.

The link to the WindowPattern.SetWindowVisualState has some good example code for how to use this pattern. I added the code that is most relevant with the use of White here since White handles getting the pattern for you.

///--------------------------------------------------------------------
/// <summary>
/// Calls the WindowPattern.SetVisualState() method for an associated 
/// automation element.
/// </summary>
/// <param name="windowPattern">
/// The WindowPattern control pattern obtained from
/// an automation element.
/// </param>
/// <param name="visualState">
/// The specified WindowVisualState enumeration value.
/// </param>
///--------------------------------------------------------------------
private void SetVisualState(WindowPattern windowPattern, 
    WindowVisualState visualState)
{
    try
    {
        if (windowPattern.Current.WindowInteractionState ==
            WindowInteractionState.ReadyForUserInteraction)
        {
            switch (visualState)
            {
                case WindowVisualState.Maximized:
                    // Confirm that the element can be maximized
                    if ((windowPattern.Current.CanMaximize) && 
                        !(windowPattern.Current.IsModal))
                    {
                        windowPattern.SetWindowVisualState(
                            WindowVisualState.Maximized);
                        // TODO: additional processing
                    }
                    break;
                case WindowVisualState.Minimized:
                    // Confirm that the element can be minimized
                    if ((windowPattern.Current.CanMinimize) &&
                        !(windowPattern.Current.IsModal))
                    {
                        windowPattern.SetWindowVisualState(
                        WindowVisualState.Minimized);
                        // TODO: additional processing
                    }
                    break;
                case WindowVisualState.Normal:
                    windowPattern.SetWindowVisualState(
                    WindowVisualState.Normal);
                    break;
                default:
                    windowPattern.SetWindowVisualState(
                    WindowVisualState.Normal);
                    // TODO: additional processing
                    break;
            }
        }
    }
    catch (InvalidOperationException)
    {
        // object is not able to perform the requested action
        return;
    }
}

Upvotes: 1

Related Questions