0

I have a project plan setup which contains some automated tests. The entire environment seems to be setup correctly, that is the controller is registered to the team project collection, and the agent is running interactively on the desktop of a client setup in labs.

Here is the problem I am facing. I have 100's of automated tests. If I run them 1 at a time they work just fine.

If I run 2 or more of them, they fail with the following exception on the 2nd test.

The control is not available or not valid.

Again if I run either test independently, they will both pass every time.

I'm guessing this has something to do with the state between the runs.

My test initialize looks like this:

[TestInitialize]
        public void Init()
        {
            Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.AllThreads;
            Playback.Wait(5000);
            AppManager.EnsureMyAppIsRunning();
            AppManager.SetTestEssentials(); 
        }
JL.
  • 78,954
  • 126
  • 311
  • 459

1 Answers1

0

I solved the problem.

I had a custom static class called AppManager which handles the connection to applicationUnderTest.

public static ApplicationUnderTest LaunchApplicationUnderTest(string applicationPath, bool closeOnPlaybackCleanup)
      {
         var processes = Process.GetProcessesByName("MyApplication");

         if (processes.Length > 0)
         {
            _application = ApplicationUnderTest.FromProcess(processes[0]);
         }
         else
         {
            _application = ApplicationUnderTest.Launch(applicationPath);
            _application.CloseOnPlaybackCleanup = closeOnPlaybackCleanup;
         }

         return _application;
      }

Inside this class, I also had a static UIMap. This means that UIMap was being created once at the start of the test run, and not updated between test runs.

So I implemented a new method in my ApplicationManager :

public static void ResetUIMap()
       {
           _map = new UIMap();
       }

Then I call it from test initialize:

[TestInitialize]
        public void Init()
        {
            AppManager.EnsureApplicationUnderTestIsRunning();
            AppManager.SetTestEssentials();
            AppManager.ResetUIMap(); 
        }
JL.
  • 78,954
  • 126
  • 311
  • 459