1

Using SilkTest, I am identifying a Putty window with the following technique: Window puttyWindow = desktop.<Window>find("//Window[@caption='*PuTTY*']");

Is there a better way to accomplish this? Perhaps get an ID number to identify the Window? Or is this the best way to do it?

Tom
  • 221
  • 4
  • 15

1 Answers1

1

For top level windows, usually the caption is the way to go. Depending on the technology of the application you are testing, there may also be better attributes available (for example the automation id in Windows Forms) but those are usually not available for the window, only the controls below.

On a side note, you can skip the type parameter if you are assigning the result to a variable of that type, like this

Window puttyWindow = desktop.find("/Window[@caption='*PuTTY*']");

Note: I work for Borland in the Silk Test team, so any opinions expressed in that regard are somewhat biased.

tehlexx
  • 2,821
  • 16
  • 29
  • Thanks for the response. Having some strange issues, where it seems like old Window objects aren't disposed of in time, so when I have consecutive calls to my `connectToServerViaPutty()` method (which returns the Window object after I've typed some keys into Putty), it doesn't always open a new Putty Configuration window. It tries to click buttons that aren't actually there, so either Putty isn't closing out properly, or the Window object isn't being disposed of. I'm just going to try to use Plink instead. – Tom Oct 03 '12 at 11:44
  • Make sure you use `closeSynchron()` to close the window. Unfortunately, the regular `close()` method is not sufficient in all cases and might return before the window is completely gone. – tehlexx Oct 03 '12 at 11:50
  • I was using `window.typeKeys("exit");`. Same situation? – Tom Oct 03 '12 at 11:53
  • Probably, yes. It might help to add a `window.waitForDisappearance()` after the `typeKeys` to make sure the window is gone. – tehlexx Oct 03 '12 at 11:55
  • I tried that, and no matter what I entered for a timeout value, I was getting some type of timeout exception. In place of that, I have `while (window.exists()) { /* wait one second */ }`. – Tom Oct 03 '12 at 11:57
  • If that works for you, that's cool. You could print the number of times it looped to get a feeling for the sort of timeout you'd need for the other method, but as long as looping works for you that's good. BTW: there's also a `Utils.sleep(...)` method, which wraps the checked exceptions, which is fine for most tests and makes the scripts a lot more readable. – tehlexx Oct 03 '12 at 12:06
  • Yeah our automation suite has some sleep methods and logging, so I've been throwing logs in different places and seeing what is happening. Thank you for your responses! – Tom Oct 03 '12 at 12:11
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/17503/discussion-between-tom-and-tehlexx) – Tom Oct 03 '12 at 12:13