SilkTest: working with own-drawn buttons

@ Mo, 26 January 2009, 13:29

PushButton is one of the simplest controls, but there could be problems even with it. In this blog post we will show several ways of how to perform a non-standard Click() action when standard Click can not be used.

For example, we are recording a script and getting this code:

wTestDialog.SetActive ()
wTestDialog.btnButton.Click ()


There could be problems when replaying this code. For example, dialog wTestDialog becomes inactive after button is pressed and hides behind other window. There can be even worse problem, when SilkTest freezes trying to click the button for a long time, but the button will not be pressed.

In most cases such problems can be solved using bRawEvent argument of the Click() method. By default, bRawEvent is FALSE and SilkTest uses the standard Windows messaging mechanism to perform actions. However, if we set this argument TRUE, SilkTest will use a low-level mechanism to perform the click. Here is a code example which works stable in most cases.

wTestDialog.SetActive ()
wTestDialog.btnButton.Click (null, null, null, true)


We do not change the first three parameters (mouse button and click coordinates), but set the fourth parameter TRUE.

Another way to solve this problem is using PressMouse() and ReleaseMouse() methods. These methods, as well as bRawEvent argument, are not used in most cases. But if Click() method fails even with bRawEvent, we can use these ones. Let's create a usage example.

wTestDialog.SetActive ()
wTestDialog.btnButton.PressMouse ()
wTestDialog.btnButton.ReleaseMouse ()


There is only one disadvantage. PressMouse() method presses the mouse button only when corresponding mouse button is not pressed yet. Which means, that there could be a situation, when mouse button is already pressed, therefore SilkTest will not perform a click, but only release the button. The best way in this case will be using DragMouse() method, which performs both pressing and releasing actions.

wTestDialog.btnButton.DragMouse (1, 10, 10, 10, 10)

The 1st argument is mouse button (1 for the left button), and last four parameters are X and Y FROM and TO coordinates. Since we don't need to move the button, all these parameters are equal.

And the last thing we need, is to create a winclass in order to override standard Click() method with the new one, which uses Drag'n'Drop technology. In order to avoid hardcoded coordinates, we will perform the click operation in the center of the button.

[+] winclass MyPushButton : PushButton
 [+] void Click (in INTEGER iButton NULL optional, in INTEGER iX NULL optional, in INTEGER iY NULL optional)
  [+] if(IsNull(iButton))
  [ ] iButton = 1
  [+] if(IsNull(iX))
   [ ] iX = this.Rect.xSize/2
  [+] if(IsNull(iY))
   [ ] iY = this.Rect.ySize/2
  [ ] this.DragMouse (iButton, iX, iY, iX, iY)


As you can see from the code example, all arguments are optional and may be skipped. In this case Click() action will be performed with the left mouse button in the center of the button.

You must be logged in to post comments