0

I am trying to manipulate Windows' Calculator. If my program finds an instance (which it does), it needs to provide the process' startInfo to TestStack's White framework for UIAutomation. However, I keep getting the following exception:

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

at found[0].StartInfo from the following lines of code

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();
    }
 }
}

The Calculator Process is already running. (Accessories > Calculator)

SILENT
  • 3,916
  • 3
  • 38
  • 57
  • Huh. The exception specifically says `The path is not of a legal form`. And yet, for some reason the actual path isn't included in the question anywhere. There's also not enough user code here to understand the context of the problem; the call to `new FileInfo()` isn't even shown. See http://stackoverflow.com/help/how-to-ask and http://stackoverflow.com/help/mcve – Peter Duniho Nov 10 '14 at 00:26
  • @PeterDuniho I started calculator via Windows. New FileInfo was never used. I pretty much showing the entire amount of unique code. The rest is just a simple WPF app that executes the above code. I'm wondering why the path is not found issue is popping up from an application that is already running. Please undo the downvote. – SILENT Nov 10 '14 at 00:48
  • 1
    Seems like a bad sign that the stack frame above AttachOrLaunch is Launch. Getting an exception about a path in this case would seem to indicate that you have passed in an invalid parameter. I can't find the API docs for TestStack.White.Application.LaunchOrAttach, but does it have overloads? Seems like passing in a ProcessStartInfo expresses intent to launch instead of attach. – Dave Kidder Nov 10 '14 at 00:55
  • @DaveKidder There are no overloads and limited documentation but I believe your assumption is correct. I discovered an Attach method but it doesn't interact with the calc process as effectively as my program explicitly starting the calc process. However, no more exceptions. – SILENT Nov 10 '14 at 01:59

0 Answers0