【发布时间】:2021-05-12 12:30:40
【问题描述】:
嗨, 我想改进这段代码以避免重复!有什么想法吗?
const captureEmailModal = email => {
When(`I type ${email.fullName}`, () => {
cy.wait(1000)
cy.get(email.dataCyModalFullName).should(exist)
.type(email.fullName)
.invoke('val')
.should('match', /^(?! )[A-Za-z\s]+$/)
cy.get(email.dataCyModalEmail).should(exist)
.type(email.email)
.invoke('val')
.should('match', /^(([^<>()\[\]\\.,;:\s@"]
cy.get(email.dataCyModalPhone).should(exist)
.type(email.phone)
.invoke('val')
.should('match', /^[0-9]+$/)
.should('have.length', 10)
})
只是更改的 email.dataCyFaqFullName / email.dataCyFaqEmail 和 email.dataCyFaqPhone
And(`I type ${email.fullName} in FAQ page`, () => {
cy.wait(1000)
cy.get(email.dataCyFaqFullName).should(exist)
.type(email.fullName)
.invoke('val')
.should('match', /^(?! )[A-Za-z\s]+$/)
cy.get(email.dataCyFaqEmail).should(exist)
.type(email.email)
.invoke('val')
.should('match', /^(([^<>()\[\]\\.,;:\s@"]
cy.get(email.dataCyFaqPhone).should(exist)
.type(email.phone)
.invoke('val')
.should('match', /^[0-9]+$/)
.should('have.length', 10)
})
}
【问题讨论】:
标签: javascript cypress