【问题标题】:Coded UI Test - waiting for running application to finish during the test编码的 UI 测试 - 在测试期间等待正在运行的应用程序完成
【发布时间】:2014-08-14 12:40:50
【问题描述】:

我正在尝试使用 Visual Studio Ultimate 2012 的 coded ui test 为我的应用程序创建测试,在我的应用程序中我运行另一个应用程序(在“另一个应用程序”运行期间打开 cmd 窗口) . 我想等到这个“另一个应用程序”完成运行,然后检查一些结果。 我怎样才能做到这一点?

如果有人知道如何使用 coded ui test 来控制窗口,我认为这可能会有所帮助,直到现在我还没有找到这样的示例!

【问题讨论】:

  • stackoverflow.com/questions/21489500/… 的可能重复项。您可以检查应用程序窗口或命令窗口是否不存在。
  • 是的,你是对的,但我不知道如何让 UITestControl 对象等待特定窗口关闭!能举个简单的例子吗?

标签: visual-studio-2012 coded-ui-tests gui-testing window-handles


【解决方案1】:
  1. 就像@AdrianHHH 建议的那样尝试 UIMap.AnotherAppUIWindow.WaitForControlNotExist();只需使用适当的元素添加那行代码
  2. 在 try-catch 中抛出一个“while”,然后等待,捕获抛出的正确异常,例如找不到元素异常

    Try
    {
        while(UIMap.AnotherAppUIWindow.Exists)
        {
           //Do nothing
        }
    
    }catch(Exception)
    {
       //Window no longer exists
    }
    

【讨论】:

    【解决方案2】:

    我想办法。

    我的问题是控制和等待与“另一个应用程序”执行相关的 cmd 窗口。

    我运行系统和VS记录器,当另一个应用程序的cmd窗口弹出时开始记录,然后我最大化窗口并停止记录,我这样做是为了获得自动生成的代码来控制这个窗口,代码我得到:

        public void WaitUntilAnotherappFinish()
        {
            #region Variable Declarations
            WinWindow uIAnotherppWindow = this.UIAnotherappWindow
            #endregion
    
            // Maximize window 
            uIAnotherppWindow.Maximized = this.WaitUntilAnotherappFinishParams.UIAnotherappWindowMaximized;
        }
    

    所以我将最大化窗口命令行替换为等待窗口不存在:

        public void WaitUntilAnotherappFinish()
        {
            #region Variable Declarations
            WinWindow uIAnotherppWindow = this.UIAnotherappWindow
            #endregion
    
            // wait for window to close 
            uIAnotherppWindow.WaitForControlNotExist();
        }
    

    这正是我想要的:)。

    重要提示:请注意此文件是自动生成的文件,因此您的更改可能会被撤消!通过在测试文件中实现自己的方法来解决这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多