locked
Pop up window handling RRS feed

  • Question

  • Hi All,

    I am running TFS2010 on VS2010 Ultimate on 2003 server SP-2 with IE 8.

    Problem: How to handle pops up window while in codedUI test run

    We have multiple codedUI test cases those are used to test browser functionality in a daily basis. During orderdtest test run we get multiple pop up window in one of those codedUI test case. How do we instruct the system to close those pop up windows and carry on the rest of the test cases? For each test case we have close browser script built in which closes any opened browser prior to start that respected test case. But unfortunately that close browser script does not close the pop up windows opened up therefore the rest of the test cases failed.

     

    How do we get rid of this problem? Can you please help us with that?

     

    Thank you,

     

    RASRAS

    Tuesday, November 2, 2010 8:10 PM

Answers

  • Hi,

    I'll recommend you to use the PlayBackError event to handle playback errors, the below exmaple shows how to catch an error and if this error related to PUPup windows you can close them and tell the coded ui to try again.

    And to avoid loops you can limit the retry to 3 times and that restart the entire test.

    int ErrorCount = 0;
            public CodedUITest1()
            {
                Playback.PlaybackError += new EventHandler<PlaybackErrorEventArgs>(Playback_PlaybackError);
            }

            void Playback_PlaybackError(object sender, PlaybackErrorEventArgs e)
            {
                if (e.Error.Message.Contains("Cannot Find Window....") && ErrorCount <= 3)
                {
                    Process[] pro_list = Process.GetProcessesByName("iexplore");
                    foreach (Process pro in pro_list)
                        if (pro.MainWindowTitle.Contains("POPUP Title"))
                            pro.Kill();

                    e.Result = PlaybackErrorOptions.Retry;
                    ErrorCount++;
                }
                else
                {
                    Playback.StopSession();

                    Process[] pro_list = Process.GetProcessesByName("iexplore");
                    foreach (Process pro in pro_list)
                            pro.Kill(); // Kill All Open IE's

                    ErrorCount = 0;
                    Playback.StartSession();
                }
            }


    Please mark the replies as answers if they help and unmark them if they provide no help.
    My blog: blogs.microsoft.co.il/blogs/shair

    Shai Raiten

    Wednesday, November 3, 2010 11:41 AM

All replies

  • Hi,

    I'll recommend you to use the PlayBackError event to handle playback errors, the below exmaple shows how to catch an error and if this error related to PUPup windows you can close them and tell the coded ui to try again.

    And to avoid loops you can limit the retry to 3 times and that restart the entire test.

    int ErrorCount = 0;
            public CodedUITest1()
            {
                Playback.PlaybackError += new EventHandler<PlaybackErrorEventArgs>(Playback_PlaybackError);
            }

            void Playback_PlaybackError(object sender, PlaybackErrorEventArgs e)
            {
                if (e.Error.Message.Contains("Cannot Find Window....") && ErrorCount <= 3)
                {
                    Process[] pro_list = Process.GetProcessesByName("iexplore");
                    foreach (Process pro in pro_list)
                        if (pro.MainWindowTitle.Contains("POPUP Title"))
                            pro.Kill();

                    e.Result = PlaybackErrorOptions.Retry;
                    ErrorCount++;
                }
                else
                {
                    Playback.StopSession();

                    Process[] pro_list = Process.GetProcessesByName("iexplore");
                    foreach (Process pro in pro_list)
                            pro.Kill(); // Kill All Open IE's

                    ErrorCount = 0;
                    Playback.StartSession();
                }
            }


    Please mark the replies as answers if they help and unmark them if they provide no help.
    My blog: blogs.microsoft.co.il/blogs/shair

    Shai Raiten

    Wednesday, November 3, 2010 11:41 AM
  • Hi Shai,

    Thank you so much for your a quick answer. We are looking into the solution you provided here. I will let you know the outcome soon.

    Thanks,

    RASRASA

    Wednesday, November 3, 2010 7:40 PM
  • Hi,

    Rasrasa,

     

    Have you find any solution for your issue?

     

    Thursday, May 26, 2011 8:56 PM