[ITEM]
03.03.2020
25

The java.awt package provides classes for AWT api such as TextField, Label, TextArea, RadioButton, CheckBox, Choice, List etc. Java AWT Hierarchy. The hierarchy of Java AWT classes are given below. The Container is a component in AWT that can contain another components like buttons, textfields, labels etc. The classes that extends Container class are known as container such as Frame, Dialog and Panel.

Why Robot Class?

In certain Selenium Automation Tests, there is a need to control keyboard or mouse to interact with OS windows like Download pop-up, Alerts, Print Pop-ups, etc. or native Operation System applications like Notepad, Skype, Calculator, etc.

Selenium Webdriver cannot handle these OS pop-ups/applications.

In Java version 1.3 Robot Class was introduced. Robot Class can handle OS pop-ups/applications.

Is There A Python Equivalent To Java

In this tutorial, you will learn, D20 cyberscape pdf.

Benefits of Robot Class

  1. Robot Class can simulate Keyboard and Mouse Event
  2. Robot Class can help in upload/download of files when using selenium web driver
  3. Robot Class can easily be integrated with current automation framework (keyword,>

    How to execute Robot Class code using TestNG

    Since, now you aware of basic methods of Robot Class so let's understand few more complex methods -

    Suppose you do not want to use the click method for clicking at web element.

    In such cases, you can use mouseMove method of the Robot class.

    Step 1) mouseMove method takes x and y coordinates as parameters like robot.mouseMove(630, 420) where 630 indicates x-axis and 420 indicate y-axis. So, this method will move your mouse pointer from the current location to mentioned x and y intersection point.

    Step 2) Next, we need to press the mouse button. We can use the method mousePress like robot.mousePress(InputEvent.BUTTON1_DOWN_MASK) .

    Step 3) After press, the mouse needs to be released. We can use robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK) in order to release left click of a mouse.

    Running code using testNG:

    Running code using Testng requires maven dependency of testNG or referenced library of TestNG jar file.

    TestNG maven dependency:

    After adding maven dependency or jar file. You need to import Test annotation of testNG. Once it is all done, just Right click on the program code and click on Run As then click on TestNG… and you will find that code will start its execution using testNG API.

    Here is the code

    Check this video to see it in action

    Disadvantages of Robot Class

    Robot framwork has few disadvantages mentioned below:

    1. Keyword/mouse event will only works on current instance of Window. E.g. suppose a code is performing any robot class event, and during the code execution user has moved to some other screen then keyword/mouse event will occur on that screen.
    2. Most of the methods like mouseMove is screen resolution dependent so there might be a chance that code working on one machine might not work on other.

    Summary

    Robot class in AWT package is used to generate keyboard/mouse events to interact with OS windows and native apps.

    The primary purpose of Robot is to support selenium automated tests project build in Java platform

    This article is contributed by Ramandeep Singh, who is a test automation engineer at a leading MNC.

[/ITEM]
[/MAIN]
03.03.2020
80

The java.awt package provides classes for AWT api such as TextField, Label, TextArea, RadioButton, CheckBox, Choice, List etc. Java AWT Hierarchy. The hierarchy of Java AWT classes are given below. The Container is a component in AWT that can contain another components like buttons, textfields, labels etc. The classes that extends Container class are known as container such as Frame, Dialog and Panel.

Why Robot Class?

In certain Selenium Automation Tests, there is a need to control keyboard or mouse to interact with OS windows like Download pop-up, Alerts, Print Pop-ups, etc. or native Operation System applications like Notepad, Skype, Calculator, etc.

Selenium Webdriver cannot handle these OS pop-ups/applications.

In Java version 1.3 Robot Class was introduced. Robot Class can handle OS pop-ups/applications.

Is There A Python Equivalent To Java

In this tutorial, you will learn, D20 cyberscape pdf.

Benefits of Robot Class

  1. Robot Class can simulate Keyboard and Mouse Event
  2. Robot Class can help in upload/download of files when using selenium web driver
  3. Robot Class can easily be integrated with current automation framework (keyword,>

    How to execute Robot Class code using TestNG

    Since, now you aware of basic methods of Robot Class so let's understand few more complex methods -

    Suppose you do not want to use the click method for clicking at web element.

    In such cases, you can use mouseMove method of the Robot class.

    Step 1) mouseMove method takes x and y coordinates as parameters like robot.mouseMove(630, 420) where 630 indicates x-axis and 420 indicate y-axis. So, this method will move your mouse pointer from the current location to mentioned x and y intersection point.

    Step 2) Next, we need to press the mouse button. We can use the method mousePress like robot.mousePress(InputEvent.BUTTON1_DOWN_MASK) .

    Step 3) After press, the mouse needs to be released. We can use robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK) in order to release left click of a mouse.

    Running code using testNG:

    Running code using Testng requires maven dependency of testNG or referenced library of TestNG jar file.

    TestNG maven dependency:

    After adding maven dependency or jar file. You need to import Test annotation of testNG. Once it is all done, just Right click on the program code and click on Run As then click on TestNG… and you will find that code will start its execution using testNG API.

    Here is the code

    Check this video to see it in action

    Disadvantages of Robot Class

    Robot framwork has few disadvantages mentioned below:

    1. Keyword/mouse event will only works on current instance of Window. E.g. suppose a code is performing any robot class event, and during the code execution user has moved to some other screen then keyword/mouse event will occur on that screen.
    2. Most of the methods like mouseMove is screen resolution dependent so there might be a chance that code working on one machine might not work on other.

    Summary

    Robot class in AWT package is used to generate keyboard/mouse events to interact with OS windows and native apps.

    The primary purpose of Robot is to support selenium automated tests project build in Java platform

    This article is contributed by Ramandeep Singh, who is a test automation engineer at a leading MNC.