1

I am using System.Windows.Automatition.UiTesting assembly to start several processes and analyse their main window. How do i create a screenshot of the window shown?

Process process = new Process();
process.StartInfo.FileName = ExecutablePath;
if (!process.Start()){
    throw new Exception.Create("Could not start Process.");       
}    
Thread.Sleep(TimeSpan.FromSeconds(10));
process.Refresh();
AutomationElement mainWindow = AutomationElement.FromHandle(process.MainWindowHandle);
var imageFromWindow = ...?

The window may be (partially) hidden by other windows.

Udontknow
  • 1,472
  • 12
  • 32

1 Answers1

1

The element must be visible, then you can get the coordinates of it in BoundingRectangleProperty and get a screenshot as described here:

Is CopyFromScreen a right way to get screenShots?

Community
  • 1
  • 1
Rekshino
  • 6,954
  • 2
  • 19
  • 44
  • Sorry, i forgot to say that these windows could be partially hidden by other windows (i am starting multiple tests at once). I need a solution specific to this situation. – Udontknow Mar 26 '17 at 14:49
  • Hmm.. The problem is to get visual object from window handle(it is only possible in the same application domain), which you have in automation element, then you could use this one: http://stackoverflow.com/questions/5189139/how-to-render-a-wpf-usercontrol-to-a-bitmap-without-creating-a-window – Rekshino Mar 26 '17 at 16:23
  • Sorry, i cannot change the tests to start locally in the same application domain. – Udontknow Mar 26 '17 at 16:45