我是添加一个随机的文本输入使用lorem-ipsum在柏树.有人知道怎么用柏树来处理这件事吗?
我正在使用以下方法,并将在测试中调用addComment()方法
import { loremIpsum } from "lorem-ipsum";
addcomment() {
loremIpsum({
count: 1, // Number of "words", "sentences", or "paragraphs"
format: "plain", // "plain" or "html"
paragraphLowerBound: 3, // Min. number of sentences per paragraph.
paragraphUpperBound: 7, // Max. number of sentences per paragarph.
random: Math.random, // A PRNG function
sentenceLowerBound: 5, // Min. number of words per sentence.
sentenceUpperBound: 15, // Max. number of words per sentence.
suffix: "\n", // Line ending, defaults to "\n" or "\r\n" (win32)
units: "sentences", // paragraph(s), "sentence(s)", or "word(s)"
})
cy.get('.input > textarea').loremIpsum()
}发布于 2022-09-06 02:54:23
安装插件
npm i lorem-ipsum然后使用上面由Alapan提到的代码。
我的代码
import {LoremIpsum} from 'lorem-ipsum'
addcomment2() {
const lorem = new LoremIpsum({
sentencesPerParagraph: {
max: 8,
min: 4
},
wordsPerSentence: {
max: 16,
min: 4
}
});
let txtComment = lorem.generateSentences(3);
cy.get(".input > textarea").type(txtComment);}
发布于 2022-09-05 19:14:13
假设你已经安装了插件。那么您的测试应该如下所示:
import {LoremIpsum} from 'lorem-ipsum'
const lorem = new LoremIpsum({
sentencesPerParagraph: {
max: 8,
min: 4,
},
wordsPerSentence: {
max: 16,
min: 4,
},
})
describe('test suite', () => {
it('Test case', () => {
//Types 5 Sentences
cy.get('.input > textarea').type(lorem.generateSentences(5))
//Types 7 Paragraphs
cy.get('.input > textarea').type(lorem.generateParagraphs(7))
})
})https://stackoverflow.com/questions/73611378
复制相似问题