【问题标题】:Different results when using and not using commands.js or it blocks使用和不使用 commands.js 或阻塞时的不同结果
【发布时间】:2019-10-12 05:36:36
【问题描述】:

我正在使用 Cypress.io 进行前端自动化。

当我将所有命令直接输入到规范中时,所有命令都在一个 it 块中,测试通过。

但是,如果我将命令放入 commands.js 中,在几个 Cypress.Commands.add 块中,或者在规范中单独地块中,则测试失败。

我不知道为什么。下面是我的 commands.js 文件

Cypress.Commands.add ("modals", {prevSubject: false}, () => {
    cy.get('#continueInBrowserBtn').should('be.visible').click()
    cy.get('#cpp-agree-btn').should('be.visible').click()
})

Cypress.Commands.add ("loginGuest", {prevSubject: false}, () => {
    cy.get('#input_email-info').should('be.visible').type('eric+test@centraldesktop.com')
    cy.get('#email-continue-btn').should('be.visible').click()
    cy.get('pgi-label-input.guest-input.first-name.web-input-area.ng-untouched.ng-pristine').should('be.visible')
    cy.get('pgi-label-input.guest-input.first-name.web-input-area.ng-untouched.ng-pristine > div > input').type('Eric')
    cy.get('pgi-label-input.guest-input.last-name.web-input-area.ng-untouched.ng-pristine > div > input').type('Test')
    cy.get('div.guest-continue-button.continue-button > pgi-text-button > button').click()
    cy.get('pgi-text-button.ng-tns-c8-0.ng-star-inserted > button > span').should('be.visible').click()
    cy.wait(3000)
})

Cypress.Commands.add ("loginHost", {prevSubject: false}, () => {
    cy.log('Enter Email')
    cy.get('#input_email-info').should('be.visible').type('6597076')
    cy.get('.pgi-button-wrapper').should('be.visible').click()

    cy.log('Enter Password')
    cy.get('#input_password-info').should('be.visible').type('r44XkP33')

    cy.log('Click Sign in')
    cy.get('#password-signin-btn > button > span').should('be.visible').click()
})

Cypress.Commands.add ("logout", {prevSubject: false}, () => {
    cy.get('bottom-container-right > div > div > div').should('be.visible').click()
    cy.get('pgi-text-button.yes-button > button > span').should('be.visible').click()
    cy.wait(2000)
    cy.get('feedback-panel > pgi-panel > h2').should('be.visible')
})

【问题讨论】:

  • 失败是什么样子的?有任何错误信息吗?另外,您能否提供一个更窄的代码示例来演示该问题?

标签: automation cypress pageobjects


【解决方案1】:

在阅读了 Cypress Docs 的最佳实践部分后,我意识到我的方法是不正确的

【讨论】:

    猜你喜欢
    • 2014-05-25
    • 2018-07-18
    • 1970-01-01
    • 1970-01-01
    • 2021-03-26
    • 2014-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多