【问题标题】:TestStack.White and CCleanerTestStack.White 和 CCleaner
【发布时间】:2016-06-27 06:03:39
【问题描述】:

我对 TestStack(白色)UI 自动化库非常陌生,并且在“挂钩”过程方面遇到了一些问题。我正在尝试连接 CCleaner,但我不断收到

“TestStack.White.AutomationException”类型的未处理异常 发生在TestStack.White.dll

附加信息:找不到标题为 Piriform 的窗口 进程 1156 中的 CCleaner,等待 30 秒后:

我当前的代码是:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using TestStack.White;
using TestStack.White.Factory;
using TestStack.White.UIItems.Finders;
using TestStack.White.InputDevices;
using TestStack.White.UIItems.WindowItems;

namespace NightWipe
{
    class Program
    {
        private const string ExeSourceFile = @"C:\Program Files\CCleaner\CCleaner.exe";
        private static TestStack.White.Application _application;
        private static TestStack.White.UIItems.WindowItems.Window _mainWindow;

        static void Main(string[] args)
        {
            clean();
        }

        public static string clean()
        {
            var psi = new ProcessStartInfo(ExeSourceFile);
            _application = TestStack.White.Application.AttachOrLaunch(psi);

            _mainWindow = _application.GetWindow("Piriform CCleaner");
            _mainWindow.WaitWhileBusy();


            return "";
        }
    }
}

我认为这可能是进程的名称,因为 CCleaner 启动了另一个进程(不是 CCleaner.exe),但 CCleaner64.exe 就像 here 所见,我可以假设它可能适用于 64 位操作系统?无论如何,我尝试过的名称包括:“CCleaner”、“CCleaner64”;但这引发了完全相同的异常。

我正在使用 Microsoft 的 Inspect,这就是它为我提供的功能(大图): Inspect's information。知道我在这里做错了什么吗?

【问题讨论】:

  • 可能与“CCleaner 启动另一个进程”有关,而 White 可能不会搜索子进程的窗口。尝试使用Process.Start 启动CCleaner,并检查创建进程的PID 是否等于拥有您实际看到的窗口的进程的PID。您也可以尝试使用 White 基于的 UIAutomation 方法。您可以尝试从msdn.microsoft.com/en-us/library/… 枚举所有根窗口,然后通过获得的句柄使用White。
  • 似乎不是由进程而是由其子进程生成的窗口可能会导致此类问题 - stackoverflow.com/questions/33532641/…

标签: c# white-framework


【解决方案1】:

问题是 CCleaner 作为 WIN32 应用程序可见。所以GetWindow() 不起作用。你可以试试这段代码:

public void CCleanerSample()
{        
    var application = Application.AttachOrLaunch(new ProcessStartInfo(@"C:\Program Files\CCleaner\CCleaner.exe"));
    AutomationElement ccleanerAutomationElement = null;
    Console.Write("Waiting till WIN32 app is launching");
    while (ccleanerAutomationElement == null)
    {
        ccleanerAutomationElement = AutomationElement.RootElement.FindFirst(TreeScope.Children,
            new PropertyCondition(AutomationElement.NameProperty, "Piriform CCleaner"));
        Thread.Sleep(1000);
        Console.Write(".");
    }
    Console.WriteLine(" Done");
    var mainWindow = new Win32Window(ccleanerAutomationElement, WindowFactory.Desktop, InitializeOption.NoCache,
        new WindowSession(application.ApplicationSession, InitializeOption.NoCache));
}

【讨论】:

    猜你喜欢
    • 2016-07-25
    • 1970-01-01
    • 2015-08-27
    • 1970-01-01
    • 1970-01-01
    • 2017-07-20
    • 2013-06-22
    • 1970-01-01
    • 2017-05-01
    相关资源
    最近更新 更多