Cypress - 我需要验证函数的结果是否与 slug 元素的值相同
Cypress - I need to verify that the result of the function is the same as the value of the slug element
it.only('Create new film', () => {
function randomStringFc() {
var a = "abcdefghijklmnopqrstuvwxyz";
var n = "1234567890";
var t = function(input, length) { return Array(length).fill(input).map(function(v) { return v[Math.floor(Math.random() * v.length)] }).join(''); }
var m = "testFilm-" + t(a+n, 8);
return m;
}
cy.contains('Create new', { timeout: 12000 }).click()
cy.get('#title', { timeout: 12000 }).then( input => {
let filmName = cy.wrap(input).type(randomStringFc())
cy.get('#slug').should('have.value', filmName)
})
})
10000 毫秒后重试超时:预期“”的值为 { Object (userInvocationStack, specWindow, ...) },但值为 'testfilm-fruh5tn5'
这不是您使用链条的方式。没有有意义的 return 值。
您需要使用另一个变量来执行您想要的操作:
cy
.get('#title', { timeout: 12000 })
.then(input => {
const randomString = randomStringFc();
cy
.wrap(input)
.type(randomString);
cy
.get('#slug')
.should('have.value', randomString);
});
it.only('Create new film', () => {
function randomStringFc() {
var a = "abcdefghijklmnopqrstuvwxyz";
var n = "1234567890";
var t = function(input, length) { return Array(length).fill(input).map(function(v) { return v[Math.floor(Math.random() * v.length)] }).join(''); }
var m = "testFilm-" + t(a+n, 8);
return m;
}
cy.contains('Create new', { timeout: 12000 }).click()
cy.get('#title', { timeout: 12000 }).then( input => {
let filmName = cy.wrap(input).type(randomStringFc())
cy.get('#slug').should('have.value', filmName)
})
})
10000 毫秒后重试超时:预期“”的值为 { Object (userInvocationStack, specWindow, ...) },但值为 'testfilm-fruh5tn5'
这不是您使用链条的方式。没有有意义的 return 值。
您需要使用另一个变量来执行您想要的操作:
cy
.get('#title', { timeout: 12000 })
.then(input => {
const randomString = randomStringFc();
cy
.wrap(input)
.type(randomString);
cy
.get('#slug')
.should('have.value', randomString);
});