Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium Actions or Java AWT Robot?

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?

like image 593
Johnny Avatar asked Jan 17 '15 22:01

Johnny


People also ask

What is the difference between Robot class and action class in Selenium?

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.

What is Java AWT Robot?

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.

Why do we use Robot class in Selenium?

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.


1 Answers

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:

  • Java AWT Robot | Selenium Uses
  • Selenium WebDriver and HTML Window location by using Java
  • One solution for File Upload using Java Robot API with Selenium WebDriver by Java
  • Use of Robot Class In Selenium WebDriver For Automation Purpose
like image 166
alecxe Avatar answered Oct 11 '22 10:10

alecxe