[英]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.