Until now I have used the Selenium Actions library in order to perform mouse/keyboard actions in our automation project.
Recently, I have discovered the Java AWT Robot class. How is it comparable to Selenium Actions library? Is there some corner-cases in one of them that the other solve? restrictions? stability? performance considerations?
What is a Robot class? As per the class description, this class is used to generate native system input events. This class uses native system events to control the mouse and keyboard. It differs from Selenium which uses the WebDriver API and invokes commands to a browser to perform actions.
The Robot class in the Java AWT package is used to generate native system input events for the purposes of test automation, self-running demos, and other applications where control of the mouse and keyboard is needed. The primary purpose of Robot is to facilitate automated testing of Java platform implementations.
A Robot class in Selenium is used to generate native system input events for test automation, self-running demos, and other applications where you need control over the mouse and keyboard. WebDriver cannot handle the OS popups, so in Java 1.3, Robot class was introduced.
There is a huge difference in terms of how do these tools work. Selenium
uses the WebDriver API and sends commands to a browser to perform actions (through the "JSON wire protocol").
Java AWT Robot uses native system events to control the mouse and keyboard.
If you are doing browser automation, ideally, you don't ever use things like Robot
since usually the functionality provided by selenium is more than enough. Though, there are cases when there is a browser or native OS popup opened, for example, to upload/download a file - this is something that can be also solved with Robot - though usually there are selenium-specific solutions/workarounds that can help avoiding using Robot
. The key idea of these workarounds is "since we cannot control the popups, just don't let them to be opened".
For example, when you download a file in Firefox, you are getting a file browser popup suggesting you to choose a location and filename. This is something you cannot manipulate with using selenium
. But, what you can do , is let Firefox know which file types and where do you want to save downloads automatically, without showing the popup. See Access to file download dialog in Firefox.
Related topics:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With