【问题标题】:Cypress - I need to verify that the result of the function is the same as the value of the slug elementCypress - 我需要验证函数的结果是否与 slug 元素的值相同
【发布时间】:2021-06-30 15:21:47
【问题描述】:
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'

【问题讨论】:

    标签: automated-tests cypress


    【解决方案1】:

    这不是您使用链条的方式。没有有意义的返回值。

    你需要使用另一个变量来做你想做的事:

    cy
      .get('#title', { timeout: 12000 })
      .then(input => {
        const randomString = randomStringFc();
        cy
          .wrap(input)
          .type(randomString);
        cy
          .get('#slug')
          .should('have.value', randomString);
      });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-14
      • 1970-01-01
      • 1970-01-01
      • 2018-03-02
      • 2020-09-25
      • 1970-01-01
      相关资源
      最近更新 更多