Why Robot framework in Selenium?

Why to use  Robot Class?

Because Selenium  is unable to Interact with operating system pop-ups or .exe Application So,Whenever there is a need to control keyboard or mouse to interact with OS windows like Download pop-up, Alerts, .exe applications like Notepad,Calculator, etc. Its required to use   “Robot  Class”.

It helps in downloading/uploading of file.

Robot  Class is preferred when it comes to automate the secure Application like Banking App,

Finance App etc.

Limitations/Precondition of Robot Class:

1.Methods like mouseMove is screen resolution dependent. So, keep the same resolution of display on production as well development environment.

2. Once mouse event occur , Screen should not change before the required action perform on mouse event.

3. You need to pay attention on the order of key release.

Some of the popular methods  are:
  • .keyPress();
  • .mousePress();
  • .mouseMove();
  • .keyRelease();
  • .mouseRelease();

a. .keyPress()

robot.keyPress(KeyEvent.VK_ESC);

It will press Escape key on keyboard.

b. .keyRelease()

robot.keyRelease(KeyEvent.VK_CAPS_LOCK);

It will release the CAPS_LOCK key.

c. .mousePress()

robot.mousePress(InputEvent.BUTTON1_MASK);

It will press Left mouse button.

d. .mouseRelease()

robot.mouseRelease(InputEvent.BUTTON1_MASK);

It will release Left mouse button.

e. .mouseMove()

robot.mouseMove(coordinates.getX(), coordinates.getY());

It will move the mouse pointer to X and Y co-ordinates.

Exception in Robot class
Since Robot Class comes under AWT package, it throws AWTException.

 Robot robot;
 try {
        robot = new Robot();

      // Press Enter
     r.keyPress(KeyEvent.VK_ENTER);
   
     // Release Enter
     r.keyRelease(KeyEvent.VK_ENTER); 
    
     robot.mouseMove(coordinatesX,coordinatesY);
    } catch (AWTException e1) {
        e1.printStackTrace();
    }

Shashank is an information technology graduate, keen observer and a perfection seeker. Passionate about browser as well as Robotic Process Automation