How to close browser when the browser is not responsing?

6 posts, 0 answers
  1. Feng
    Feng avatar
    10 posts
    Member since:
    Nov 2011

    Posted 05 Oct 2012 Link to this post

    HI

    There are a lot of tests in a testlist.When a test  fails due to a fact that the browser is not responsing or the browser can not be closed,the other tests after the test can not be executed.So i just want to know how to close the browser when the browser is not responsing,so that the other test can be executed.

    Thanks for your answer.
  2. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 10 Oct 2012 Link to this post

    Hi Feng,

    If you're dealing with a Test Studio test, you can try putting your tests into a Test List and then setting the "KillBrowserProcessOnClose" setting in the Test List settings as shown in the attached screen shot.

    If instead you're dealing with a 100% coded test, you'll need to do a Google search for how to find and kill processes. We, Test Studio technical support, don't have the expertise how to do this via code.

    Kind regards,
    Cody
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  3. Anton
    Anton avatar
    54 posts
    Member since:
    Sep 2011

    Posted 25 Oct 2012 Link to this post

    Hello Cody,

    I have a problem to open browser after killing browser process.

    test case:

    1 test: open page, then open HTML popup. 

    after test finished, browser processes succesfully killed, but in second test new browser instance doesn't start.

    Here code which run before each test.

    [Setup]
    if (Manager.Current.Browsers.Count > 1)
                {
                           Helpers.KillBrowserProcesses(_browserType);
                 }
    if (ActiveBrowser == null || !Process.GetProcessesByName(_processName).Any())
                {
                    var retries = 0;
                    bool browserOpened;
                    do
                    {
                        try
                        {
                            browserOpened = true;
                              
                            Manager.LaunchNewBrowser(_browserType, true, ProcessWindowStyle.Maximized);
                           retries = 0;
                        }
                        catch
                        {
                            retries++;
                            browserOpened = false;
                            Console.WriteLine("Restarting the browser. Retry {0} of {1}", retries,
                                              Configuration.Instance.BrowserOpeningRetries);
      
                            if (Manager.Browsers.Count <= 0) continue;
                            Helpers.KillBrowserProcesses(_browserType);
                            //foreach (var browser in Manager.Browsers)
                            //    browser.Close();
                            //if (ActiveBrowser != null)
                            //    ActiveBrowser.Close();
                        }
                    } while (retries < Configuration.Instance.BrowserOpeningRetries && browserOpened == false);
                }
      


    public static void KillBrowserProcesses(BrowserType browserType)
            {
                var browserProcesses = new Process[] {};
                switch (browserType)
                {
                    case BrowserType.FireFox:
                        browserProcesses = Process.GetProcessesByName("firefox");
                        break;
                    case BrowserType.InternetExplorer:
                        browserProcesses = Process.GetProcessesByName("iexplore");
                        break;
                }
                foreach (var browserProcess in browserProcesses)
                {
                    try
                    {
                        browserProcess.Kill();
                        browserProcess.WaitForExit();
                    }
                    catch
                    {}
                }
            }

  4. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 30 Oct 2012 Link to this post

    Hello Anton,

    I used the same implementation of the KillBrowserProcess method in a similar scenario, but I wasn't able to reproduce the problem you are experiencing. Would it be possible for you to send us a small executable demo project that replicates the issue, so that we can try to determine what is causing the problem?

    All the best,
    Plamen
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  5. Anton
    Anton avatar
    54 posts
    Member since:
    Sep 2011

    Posted 31 Oct 2012 Link to this post

    Hello Plamen.

    I resolve my problem by added these strings

    var manager = new Manager(settings);
                    manager.Start();

  6. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 31 Oct 2012 Link to this post

    Hi Anton,

    I am glad to hear you got it working! Thanks for the update.

    Kind regards,
    Plamen
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top