我正在尝试操作 Windows 的计算器。如果我的程序找到了一个实例(它确实找到了),它需要将进程的 startInfo 提供给 TestStack 的用于 UIAutomation 的 White 框架。但是,我不断收到以下异常:
System.ArgumentException was unhandled
HResult=-0
Message=The path is not of a legal form.
Source=mscorlib
StackTrace:
at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
at System.IO.Path.GetFullPathInternal(String path)
at System.IO.FileInfo.Init(String fileName, Boolean checkHost)
at System.IO.FileInfo..ctor(String fileName)
at TestStack.White.Application.Launch(ProcessStartInfo processStartInfo) in c:\TeamCity\buildAgent\work\89a20b30302799e\src\TestStack.White\Application.cs:line 60
at TestStack.White.Application.AttachOrLaunch(ProcessStartInfo processStartInfo) in c:\TeamCity\buildAgent\work\89a20b30302799e\src\TestStack.White\Application.cs:line 144
at Test_with_GUI.Tests.UIAutomation.Test() in c:\Users\BLAH\Test with GUI\test with gui\Tests\UIAutomation.cs:line 24
at Test_with_GUI.MainWindow.testing_component7() in c:\Users\BLAH\Test with GUI\test with gui\MainWindow.xaml.cs:line 257
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException
来自found[0].StartInfo
以下代码行
Process[] found = Process.GetProcessesByName("calc");
if (found.Length > 0)
{
using (var app = TestStack.White.Application.AttachOrLaunch(found[0].StartInfo))
{
using (var win = app.GetWindow(SearchCriteria.ByText("Calculator"), InitializeOption.NoCache))
{
Manipulation();
}
}
}
计算器进程已在运行。(配件 > 计算器)