Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Validation Cypress-如何同时声明多个错误_Validation_Automated Tests_Cypress - Fatal编程技术网

Validation Cypress-如何同时声明多个错误

Validation Cypress-如何同时声明多个错误,validation,automated-tests,cypress,Validation,Automated Tests,Cypress,我有一个表格,它有5个输入,需要填写。我想测试验证是否正确启动。 因此,在尝试发送空表单时,我应该能够找到5条错误消息 我想要一些像: cy.get('form') .should('包含5次','你应该把这个装满,伙计') 有没有可能,或者我不得不把无数的虚拟树浪费在无用的重复行上?这样不行。如果您需要它,请将其干净地包裹在外部帮助器上,并用于您的目的。 最短的方法是: cy.get('.error-text').each((item) => { expe

我有一个表格,它有5个输入,需要填写。我想测试验证是否正确启动。
因此,在尝试发送空表单时,我应该能够找到5条错误消息

我想要一些像:

cy.get('form')
.should('包含5次','你应该把这个装满,伙计')

有没有可能,或者我不得不把无数的虚拟树浪费在无用的重复行上?

这样不行。如果您需要它,请将其干净地包裹在外部帮助器上,并用于您的目的。 最短的方法是:

     cy.get('.error-text').each((item) => {
          expect(item).to.contain('You should fill this up, mate')
      })
我最终使用了

cy.get('form')
.should('contain','你应该把这个装满,伙计')
cy.get('.invalid input error msg')
.should('have.length',5)

它并不完美,但还可以通过,下面的代码可以满足您的要求。如果你喜欢下面的要求。 单击“注册”按钮而不填写表单,您应该会看到每个字段的错误消息。。。您只需更正以下代码中的定位器

cy.get('#sign-up-button').click(); // Click on sign-up button for example without filling form
cy.get('form').within(() => { // Basically you are asserting inside form for each individual fields
     cy.get('#username').should('have.text', 'you should fill username input')
     cy.get('#password').should('have.text', 'you should fill password input')
     cy.get('#email').should('have.text', 'you should fill email input')
     cy.get('#address').should('have.text', 'you should fill address input')
     cy.get('#gender').should('have.text', 'you should fill gender input')
})