[英]TestStack.White and CCleaner
我对TestStack(白色)UI自动化库非常陌生,在“挂钩”过程方面存在一些问题。 我试图钩住CCleaner,但我不断
TestStack.White.dll中发生了类型为'TestStack.White.AutomationException'的未处理异常
附加信息:等待30秒后,在进程1156中找不到标题为Piriform CCleaner的窗口:
我当前的代码是:
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看到这里 ,我可以假设为64位操作系统可能? 无论如何,我尝试过的名称包括:“ CCleaner”,“ CCleaner64”; 但这引发了完全相同的例外。
我正在使用Microsoft的Inspect,这就是它为我带来的好处(大图): Inspect的信息 。 知道我在做什么错吗?
问题是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));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.