Image by TonyƧ via FlickrSometimes its good to be reminded that there are things out there that simply just don't want to work. These always present a challenge. The most recent example is a simple case of a Java application with a spin button for selecting the time with the obvious requirement of being able to set a value. Hmmm...
Spin fields are created as a combination of a couple of buttons inside of an edit field. Rules are then applied to the buttons in terms of their effect on the value. Rules also apply to the value itself. Simply though, there are 4 objects within this one field. The container which is the spin control. An edit field for the value. A button for increasing the value and another button for decreasing the value.
QTP was not happy. There is a Set function that works on the spin object and should set the value of the control. Now while GetROProperty("value") works, the Set function does not. It actually would have been nice for it to have failed with an error rather than doing nothing.
Another simple option also exists... set the edit field to the value. This would have been great except that the Set function for the edit was reported as being invalid - the joys of a composite Java field.
Well ultimately setting a value simply requires that the object be activated and then a Type should work. Now QTP does not provide activate functions for all the Java objects. Not a big deal as an activate is the same as a click on the object.
Ha! Not this time. The click function, which is nothing more than a simulation of a mouse click would not activate the spin field. This was a weird one. Seriously surreal.
OK. Going back to the spin control. QTP provides functions for Next and Prev values. I know already that running these functions does not change the spin field - probably just as well as I would probably have been able to set the hour but would have been unlikely to have accessed the minute field. This exploration did however show a flicker in the field.
Regardless of testing you work in, noting any effect/flicker/change in the application is essential. This flicker lead to the solution... as weird as it turned otu to be.
The solution involved the following:
- Run the spin object's next function
- Send a home keypress to the window by typing micHome to the Java window object
- Type the value to be captured to the Java window
The implication was to obviously run the type portions twice against the spin field. So the final solution turned out to be:
- Run the spin object's next function
- Send a home keypress to the window by typing micHome to the Java window object
- Type the value to be captured to the Java window
- Send a home keypress to the window by typing micHome to the Java window object
- Type the value to be captured to the Java window