【问题标题】:Testcafe: Native dialog window handelingTestcafe:本机对话窗口处理
【发布时间】:2020-04-05 06:42:49
【问题描述】:

我正在尝试使用 Testcafe 将文件上传到我正在测试的站点(使用 Chrome)。以下是我目前的代码,

    await t
        .setFilesToUpload(Selector('input.btn.btn-link.d-none'), file_path)

    await t
          .setNativeDialogHandler(() => true)
                  .click('#Ok');

一旦我尝试上传文件,浏览器会弹出一个原生对话窗口,我的选项是“打开”/“取消”。如何点击“打开”?另外我不知道如何获取 Selector for Open 按钮。

我在 Linux 上运行它,Java Script。以下是错误,

   1) The specified selector does not match any element in the DOM tree.

       > | Selector('#Open')

      Browser: HeadlessChrome 78.0.3904 / Linux 0.0.0
      Screenshot: /app/code/screenshots/2019-12-11_22-28-52/test-2/HeadlessChrome_78.0.3904_Linux_0.0.0/errors/1.png

         71 |            //.handleAlert().click()
         72 |            //.click('#Open');
         73 |
         74 |        await t
         75 |              .setNativeDialogHandler(() => true)
       > 76 |                      .click('#Open');
         77 |
         78 |        const history = await t.getNativeDialogHistory();
         79 |        await console.log(history);
         80 |    }
         81 |}

         at <anonymous> (/app/code/gen_lib/gen_lib.js:76:24)

【问题讨论】:

  • TestCafe 无法使用本机浏览器“打开文件”对话框进行操作。通常使用 .setFilesToUpload 操作将文件放入 元素并引发上传过程(如果它没有自动启动)就足够了。如果这种情况不适用于您的网站,请提供示例页面或公共 url 以重现该问题。
  • 您可以查看详细的description,了解如何在TestCafe 中测试文件上传并检查可运行的示例here

标签: google-chrome testing automated-tests e2e-testing testcafe


【解决方案1】:
async uploadFile() {
    await this.t
        .setFilesToUpload(<Your input selector>, [
            'path to file/Image.jpg'
        ])
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-06
    • 2022-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-24
    • 1970-01-01
    相关资源
    最近更新 更多