type(selector, textValue)
This is a TDK feature
This is not supported in Testim's visual editor
This method is used to set an element's text content. If the element already has text content it overrides it.
selector
{string | TDKStepLocator} a CSS selector or smart locator for the elementtextValue
{string} the value we want to type into the control- returns: Promise that fulfills when the action is complete.
For example:
// ✅ type an email in an email type input
await type('input[type=email]', '[email protected]');
// ✅ set an element's text in a smart locator
await type(l('username'), 'benji');
// ✅ type into a rich text editor form
await type('.my-contenteditable', 'Lorem Ipsum Dolor');
// ❌ the text to type must be passed
await type('.my-contenteditable');
// ❌ The method takes two parameters and not an object
await type({selector: '.my-contenteditable', text: 'Lorem'});
Full example
'use strict';
const expect = require('chai').expect;
const { go, type, test, text } = require('testim');
test("type", async () => {
await go('http://jsbin.testim.io/zut/1');
const textToCheck = "Codim Self Test";
await type('input[type=text]', textToCheck);
const elementText = await text('#typedContent');
expect(elementText).to.equal(textToCheck);
});
Updated almost 3 years ago