1

I am using TestStack.White framework to automate opening new document in MS Word 2013.

I am opening Microsoft Word application with:

   Application application = Application.Launch("winword.exe");

After that, I am trying to get the window by partial title:

   Window window = application.GetWindow("Word", InitializeOption.NoCache);

But it throws an exception saying that there is no such window.

Window title is: Document1 - Word

The question is: How to get a window by partial title taking into consideration that the title is changing every time: "Document2 - Word", "Document3 - Word", etc.

Also tried *Word but looks like this func does not support wildcards

If I invoke: List windows = application.GetWindows(); after launching an application, windows list is empty.

Thanks in advance, Ostap

3 Answers3

0

It looks like opening window takes some noticeable time. GUI testing frameworks often have functions like Wait() to make sure the window is already created/visible/enabled. I'm not an expert in Teststack.White. Probably this document may help: http://teststackwhite.readthedocs.io/en/latest/AdvancedTopics/Waiting/

Songy
  • 851
  • 4
  • 17
Vasily Ryabov
  • 9,386
  • 6
  • 25
  • 78
  • Waits does not help, window was not found after 30 seconds. Tried to search by title which is 100% on the screen. Also tried sleep for 10 seconds before window search. – Ostap Elyashevskyy Nov 06 '14 at 16:22
  • OK, it's Microsoft. :) How about using COM interop interface and Word object model? http://msdn.microsoft.com/en-us/library/kw65a0we.aspx – Vasily Ryabov Nov 06 '14 at 19:21
  • Another more concrete example: http://msdn.microsoft.com/en-US/library/ms173188(v=vs.80).aspx – Vasily Ryabov Nov 06 '14 at 19:26
  • thanks for the answer. Microsoft COM works for native controls/workflows. In my case we have a MS Word plugin which hooks and replaces MS dialogs/controls, etc. Need to verify if it will handle such controls – Ostap Elyashevskyy Nov 07 '14 at 09:06
0

You can use EnumWindows to find all the open windows.

Within that callback you'll get a window handle which you can then us with GetWindowTextLength and GetWindowText

This will let you decide what window handle is to the window you want. From there you can use GetWindowThreadProcessId to retrieve the process ID for the word document.

And finally with that you can create a TestStack White application using the Application.Start()

MikeJ
  • 1,299
  • 7
  • 10
0
public static Window GetWindowBySubstring(this Application app, string titleSubString)
{
    return app.GetWindows().FirstOrDefault(w => w.Title.Contains(titleSubString));
}
wscourge
  • 10,657
  • 14
  • 59
  • 80
burton
  • 421
  • 4
  • 13