3

We observe differences using button.Click() versus button.Press() when we run automated tests for our Java application (Windows, desktop).

The documentation for Button does not tell so much:

Click():

Clicks on the adapter with the left mouse button.

and (not applicable for our application)

If this method is invoked on a mobile element, Touch() will be called internally.

Press():

Presses the button.

What is the difference between those two methods? Any guideline when to use which one?

1 Answer 1

4

I don't have an official answer, but the difference is mainly in 2 things:

  1. continuation of the Ranorex test script
  2. the number of events fired

Conclusion: Click() is closer to real user interaction, Press() is faster and more robust as long as it is sufficient for your automation.

Regarding 1., I have observed:

Click() immediately continues the Ranorex script execution as opposed to Press() which waits until the code of the event handler has completed.

This can e.g. have the following impact: if a message box is opened synchronously when the button is "clicked", and you use Press() in the Ranorex script, then you cannot answer the message box from the Ranorex script in the next step. Your test case will hang.

Regarding 2., I have observed:

Click():

  • Paint (may occur multiple times in different order)
  • MouseEnter
  • MouseMove (may occur multiple times)
  • MouseDown
  • MouseHover
  • Click
  • MouseClick
  • MouseUp
  • MouseMove (may occur multiple times)

Press():

  • Paint (may occur multiple times in different order)
  • Click

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.