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>