This is a migrated thread and some comments may be shown as answers.

How to close browser when the browser is not responsing?

5 Answers 162 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Feng
Top achievements
Rank 1
Feng asked on 05 Oct 2012, 03:08 PM
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.

5 Answers, 1 is accepted

Sort by
0
Cody
Telerik team
answered on 10 Oct 2012, 03:18 PM
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
0
Anton
Top achievements
Rank 1
answered on 25 Oct 2012, 12:40 PM

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
                {}
            }
        }

0
Plamen
Telerik team
answered on 30 Oct 2012, 03:27 PM
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
0
Anton
Top achievements
Rank 1
answered on 31 Oct 2012, 11:48 AM

Hello Plamen.

I resolve my problem by added these strings

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

0
Plamen
Telerik team
answered on 31 Oct 2012, 12:26 PM
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
Tags
General Discussions
Asked by
Feng
Top achievements
Rank 1
Answers by
Cody
Telerik team
Anton
Top achievements
Rank 1
Plamen
Telerik team
Share this question
or