sendCharacter(selector, key)
This is a TDK feature
This is not supported in Testim's visual editor
Send a given key to the browser (for example tab):
selector
{string | TDKStepLocator} a CSS selector or smart locator for the input elementkeyCode
{number|string} the key code or character to send to the browser- returns: Promise that fulfills when the character has been entered
For example:
// ✅ send the first input on the page a tab key
await sendCharacter('input', '\t');
// ✅ send the first input on the page a newline
await sendCharacter('input', '\n');
// ✅ send the first input on the page a newline in ascii char code
await sendCharacter('input', 10);
// ✅ send the first input on the page a newline in ascii char code
await sendCharacter('input', 65);
// ❌ bad, use `type('input', 'hello')` instead
for(const item of [72, 101, 108, 108, 111]) {
await sendCharacter('input', item);
}
// ❌ bad, the second character is ignored
await sendCharacter('input', 'hi')
Full Example:
'use strict';
const expect = require('chai').expect;
const { go, test, click, sendCharacter, text } = require('testim');
test("send character", async () => {
await go('http://jsbin.testim.io/rum/');
await click('button');
await sendCharacter('button', '\r');
await sendCharacter('button', 9);
await sendCharacter('button', 9);
await sendCharacter('button', 13);
const allKeys = await text('div');
expect(allKeys).to.eq('139913');
});
Updated almost 3 years ago