【问题标题】:Cypress.io - timeout when typing from wrapCypress.io - 从 wrap 输入时超时
【发布时间】:2018-10-01 01:33:29
【问题描述】:

我是 Cypress 和 Javascript 的新手。

我有一个包装好的 JSON 对象,并在 beforeEach 函数中为它设置了一个别名。 我正在尝试使用 JSON 对象中的属性设置输入字段。

beforeEach(function () {
    cy.wrap({username:"richard@cypresstest.com"}).as('userLoginWrap');
  })

it.only('should log user in successfully', function () {

  cy.get('@userLoginWrap').its('username').should('eq', 'richard@cypresstest.com'); // Passed
  
  cy.get('#usernameField')
      .type(cy.get('@userLoginWrap').its('username')); // Error: Cypress command timeout of '4000ms' exceeded.
})

我该如何解决这个问题?

谢谢。

【问题讨论】:

  • 这里出了什么问题?是否有错误,如果有,您可以发布您收到的错误消息吗?
  • 嗨 Joshua,我实际上得到了错误:赛普拉斯命令超时 '4000ms' 超出。对于赛普拉斯 GUI 中的最后一行代码。欢呼

标签: cypress


【解决方案1】:

cy.type( text ) 接受字符串。您正在向它传递一个 cy 命令,它不是同步的。

你可以做这样疯狂的事情(未经测试):

beforeEach(function () {
  cy.wrap({username:"richard@cypresstest.com"}).as('userLoginWrap');
})

it.only('should log user in successfully', function () {
  let username;
  cy.get('@userLoginWrap').its('username').should('eq', 'richard@cypresstest.com')
    .then( obj => username = obj.username );

  cy.get('#usernameField')
      .type( username );
})

但我更喜欢将 "richard@cypresstest.com" 存储到一个常量 --- 这样您就不必像现在一样重复它,而且避免使用 .then() 命令存储到变量的恶作剧.

或者,使用fixtures

【讨论】:

    猜你喜欢
    • 2018-07-27
    • 1970-01-01
    • 1970-01-01
    • 2013-11-26
    • 2022-01-12
    相关资源
    最近更新 更多