编码 UI C# - 为什么我无法使用对象 app.Launch("app path here") 访问 ApplicationUnderTest class 方法;

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

我想了解为什么不允许#2。我无法使用 "app" 对象访问 class 方法?

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

注意:我已经 6 年没有接触过 C# 或任何其他编程语言,所以我的概念有点不稳定。如果我使用了错误的术语,请纠正我。意思是我想知道我是否想调用 Launch() 方法为什么我不能通过对象 app.Launch();

ApplicationUnderTest class 是静态的,这意味着它不能被实例化(当你调用 = new ApplicationUnderTest() 时你在做什么)。因此,您尝试访问的方法只能在静态 class 中访问。 MSDN 是一个很好的资源,可以更深入地解释 class 辅助功能类型。

这是我的做法:

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