Table of contents
1.
Keyboard API
2.
Clipboard API
2.1.
copy()
2.2.
cut()
2.3.
paste()
3.
FAQs
4.
Key Takeaways
Last Updated: Mar 27, 2024
Easy

Keyboard And Clipboard Actions

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Keyboard API

Keyboard API is a very important API in the testing libraries. The Keyboard API is used to stimulate multiple interactions with the keyboard. It can accept a String as the argument to describe the actions to be performed. The syntax for the Keyboard API looks like this,

keyboard(input: stringInput): Promise<void> 

 

For example,

keyboard(‘ninja’)  // This will translate to : n, i, n, j, a 

 

The brackets can be used as special characters and must be referenced by doubling them, for instance,

keyboard(‘{Shift}{c}{o}{d}{e}’) //This will translate to: Shift, c, o,d, e

 

We can even keep the keys pressed by using the > symbol.

keyboard(‘a>’) // a will be pressed without releasing it.

 

We can lift the previously pressed key by adding / before the key.

keyboard(‘{/Shift}’)  // Any previously pressed Shift will be lifted.

 

Let us combine all of these symbols and look at a combination of them,

keyboard(‘{Shift>}CODE{/Shift}’) // This will translate to Shift(down) C, O, D, E, Shift(up)

Clipboard API

The Clipboard API is used to perform basic Clipboard-related functions such as cut, copy, paste. It is a really prominent API in the testing library.

copy()

The copy function is used to copy all the text from the current selection and store it in the clipboard. The syntax looks like this,

copy(): Promise<DataTransfer>

cut()

The cut function is used to cut all the text from the current selection and store it in the clipboard. The syntax looks like this,

cut(): Promise<DataTransfer>

paste()

The paste function is used to paste all the text from the clipboard to the selected document. The syntax looks like this,

paste(clipboardData?: Transfer|string): Promise<void>

FAQs

  1. Keyboard and Clipboard APIs are part of what libraries?
    The Keyboard and Clipboard APIs are part of the user-event testing library. User-event is a user companion library used for the simulation of user interactions.
  2. What are Keyboard APIs?
    Keyboard API is a very important API in testing libraries. The Keyboard API is used to stimulate multiple interactions with the keyboard. It can accept a String as the argument to describe the actions to be performed.
  3. What are Clipboard APIs?
    The Clipboard API is used to perform basic Clipboard-related functions such as cut, copy, paste. It is a really prominent API in the testing library.
  4. What is Dynamic Testing?
    A Dynamic Test is one of the most commonly used tests, and it is generated at the run time. We use the TestFactory method to generate Dynamic Tests in JUnit5. TestFactory method is a non-static and non-private method.
  5. What are testing libraries?
    The testing library is a collection of packages that helps the developer to test the UI components in a user-centric way.   

Key Takeaways

This Blog covered all the necessary points about the Keyboard API and Clipboard API. We further discussed the implementation of both Keyboard and Clipboard API.

Don’t stop here; check out Coding Ninjas for more unique courses and guided paths. Also, try Coding Ninjas Studio for more exciting articles, interview experiences, and fantastic Data Structures and Algorithms problems.

Live masterclass