Frage

I'm using a trial version of Teleriks Test Studio, and am running into a problem with it on my Silverlight application. My test is logging in, then attempting to add 100 new users from a data source. I have run the test multiple times and every time it fails, it seems to do the same thing: it gets stuck with an Unable to locate element error, but my understanding was that if it fails, it should restart the test. However, this is not the case. Instead it just sits there, unable to find any other element

I should say this is an inconsistent error; this is always in a different stage of the test. Sometimes it will run 10 tests perfectly, then the next one will fail.

Is there a way to cause a close current browser and open new browser on fail, or even add a step to close and open the browser as the first step? How can I close and reopen the browser when the browser is not responding?

War es hilfreich?

Lösung

From Telerik's help forums:

[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
      {}
   }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top