即使我在文件中找不到ID + 保存文件名,测试也已通过

问题描述 投票:0回答:1

我正在创建自动化来验证目录中包含的文件。 我的目录有N个文件。我需要在我的文件中找到一个 ID。 当您找到此 ID 时,保存文件名并停止搜索其余文件。 如果在文件中没有找到ID,则返回ERROR,即破坏我的测试。

我目前使用 Cypress!

下面是我的代码。在此代码中,我可以查找该文件,但无法保存文件名,如果找不到它,测试将中断(失败)。

cy.task('getFiles', 'batch/22896431000382/uds/processed')
        .then(result => {

          const x = result

          let continue_loop = true
          cy.wrap(continue_loop, { log: false }).as('continue')

          for (let i = 0; i < x.length; i++) {
            cy.get('@continue', { log: false }).then(continue_loop => {
              if (continue_loop) {
                cy.readFile(`batch/22896431000382/us/processed/${x[i]}`)
                  .then(txt => {

                    // checking for any failed status here
                    if (txt.includes('IdkBGxcJWaapecROrzNh')) {
                      return
                    }
                  })
              }
            })
          }
        });

有人可以帮忙吗?!

提前非常感谢您!

javascript testing automation cypress
1个回答
0
投票

重复问题所示,当您不再想...继续循环时,实际上需要更改

continue_loop
变量。

let continue_loop = true
cy.wrap(continue_loop, {log:false}).as('continue')   

for (let i = 0; i < result.length; i++) {
  cy.get('@continue', {log:false}).then(continue_loop => {
    if (continue_loop) {

      ...
      if (txt.includes(...)) {
        continue_loop = false
        cy.wrap(continue_loop, {log:false}).as('continue')
      }
    }
  })
}
© www.soinside.com 2019 - 2024. All rights reserved.