mejdev
mejdev

Reputation: 3758

Window disappears too fast for Coded UI Test

In a program that I'm testing with Coded UI Tests, I've got a window that opens for only a second or so, and I want to verify that this window is opening.

Is there a way to freeze the program, or make it run slow so that the test is able to find that window?

Upvotes: 3

Views: 1463

Answers (5)

VVP
VVP

Reputation: 836

Best possible method is to add polling mechanism. As soon as you perform the action which will open the window, call a function which will keep checking whether the window appeared for say, 1 min or so.

Be sure to call this function as soon as you perform action. So even if the window stays for 500 millisecond, the info will be captured.

We have done similar thing in our project.

Upvotes: 0

Babu A
Babu A

Reputation: 76

Use Playback.Wait(2000) instead of Thread.Sleep(2000);

Upvotes: 0

chaliasos
chaliasos

Reputation: 9793

As I already mentioned in my comment there isn't much (perhaps nothing) you can do by the CodedUi Test to catch the window, since this functionality is built into the application.

My suggestion is to make this property configurable. Some of the properties in the applications under test need to be configurable so it can be tested. Consider the following requirements:

  • The service is restarting every month.
  • The user is deleted after one year of inactivity.

How would you test them? Will you wait a month or a year to go by? Those kind of parameters have to be available for the Qa team, otherwise they cannot be tested. I know that with this approach you have to do changes to your app's code and build but I think is the only way to solve it.

Upvotes: 3

ledgeJumper
ledgeJumper

Reputation: 3630

From what I understand, the best approach is to break up your tasks as small as possible. So for a UI test I did that opens a shortcut on my toolbar, clicks login on a popup within, then clicks a tab in the application, the code looks like this:

namespace CodedUITestProject1
{
/// <summary>
/// Summary description for CodedUITest1
/// </summary>
[CodedUITest]
public class CodedUITest1
{
    public CodedUITest1()
    {
    }

    [TestMethod]
    public void CodedUITestMethod1()
    {
        // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
        // For more information on generated code, see http://go.microsoft.com/fwlink/?LinkId=179463
        this.UIMap.OpenWindow();
        this.UIMap.ClickLogin();
        this.UIMap.ClickDevelopment();
    }
//snip
}

So then in the ClickDevelopment() method, I know that the program should be visible, so rather than just dive right into the method actions, I can throw a Thread.Sleep() to make it visible for a little while longer.

public void ClickDevelopment()
    {
        Thread.Sleep(10000);
        #region Variable Declarations
        WinClient uIDevelopmentClient = this.UIQualityTrack30Window.UIItemWindow.UIQualityTrack30Client.UIDevelopmentClient;
        #endregion

        // Click 'Development' client
        Mouse.Click(uIDevelopmentClient, new Point(39, 52));
    }

Upvotes: 0

HatSoft
HatSoft

Reputation: 11201

How about adding a Thread.Sleep(100);

http://msdn.microsoft.com/en-us/library/d00bd51t

Upvotes: 1

Related Questions