I have a utility command in cypress:
Cypress.Commands.add('generateDummyText', (length: number, delay?: number) => {
const wordLength = 5;
const lorem = new LoremIpsum({
wordsPerSentence: {
max: wordLength,
min: wordLength,
},
words: ['word1', 'word2', 'word3', 'word4', 'word5'],
});
const words = lorem.generateWords(Math.ceil(length / wordLength));
cy.wrap(words).as('dummyText');
});
it('test', () => {
// Generate dummy text
cy.generateDummyText(280);
// I want to type the "dummyText variable here"
cy.get('myinput').type()
});
How can this be done? I don’t need to use a custom cypress command, but I’d prefer to use one. Looking forward to your reply!
>Solution :
You can access it just by using:
cy.type(this.dummyText)
Another option is just to use faker to generate the random words for you.
Add the faker module to you project, then you can just do:
const faker = require("faker");
.type(faker.random.words(5));
instead of using a custom command for it