Asif Nisar
Asif Nisar

Reputation: 15

Coded UI C# - Why I cannot access a ApplicationUnderTest class method using object app.Launch("app path here");

I would like to understand why #2 is not allowed. I cannot access class method using "app" object?

  1. ApplicationUnderTest app = ApplicationUnderTest.Launch("app exe path here");
  2. ApplicationUnderTest app = new ApplicationUnderTest();
    app.Launch("app exe path here");

Note: I have not touched C# or any other programming language since 6 years so my concepts are a bit shaky. Please correct me If I have used wrong terminology. Meanly I wanted to know if I want to call Launch() method why I cannot do it via object app.Launch();

Upvotes: 0

Views: 1058

Answers (2)

JL.
JL.

Reputation: 81262

Here's how I do it:

public static ApplicationUnderTest LaunchApplicationUnderTest(string applicationPath,string processName,
         bool closeOnPlaybackCleanup)
      {
         Process[] processes = Process.GetProcessesByName(processName);

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

         return _application;
      }

Upvotes: 0

Ryan Cox
Ryan Cox

Reputation: 958

The ApplicationUnderTest class is static, meaning it cannot be instantiated (what you're doing when you call = new ApplicationUnderTest()). Thus, the methods that you're trying to access can only be accessed in the static class. MSDN is a good resource for a more in depth explanation of class accessibility types.

Upvotes: 3

Related Questions