【问题标题】:TestCafe - How to run in non-Chrome browsers & display test executingTestCafe - 如何在非 Chrome 浏览器中运行并显示测试执行
【发布时间】:2020-11-24 21:57:33
【问题描述】:

我需要帮助设置 TestCafe 以在 Firefox 和 Edge 中运行。我也有兴趣学习如何模拟其他浏览器/设备(移动设备)。

我是 TestCafe 的一名 QA 测试员(不是开发人员),需要一些培训材料。我在本地安装了 Chrome (v 86.0.4240.75)、Edge (v 41.16299.1480.0) 和 Firefox (v 83.0)。我使用 Chrome 录制了一个测试,当运行配置设置为 Chrome 时它成功运行,我可以看到测试运行完成。

在运行配置设置为 Firefox 的情况下运行相同的测试时,浏览器窗口不会打开,但不久之后 TestCafe 会指示测试运行成功完成。就好像它在无头运行,但我不是这样设置的。

在运行配置设置为 Edge 的情况下运行相同的测试时,会出现一个 Edge 浏览器窗口并加载要测试的页面,但测试不会超过第一步,也不会失败。它只是坐在那里,就好像它在录制模式下运行一样,等待我告诉它继续,但它被设置为运行而不是录制。

我能否像在 Chrome 中运行时那样在非 Chrome 浏览器中运行测试?

【问题讨论】:

    标签: testing firefox mobile microsoft-edge testcafe


    【解决方案1】:

    据我了解,您使用的是 TestCafe Studio。要在 TestCafe Studio 中模拟移动设备,请查看这篇文章:https://docs.devexpress.com/TestCafeStudio/400189/user-interface/run-configurations-dialog

    至于非 Chrome 浏览器的问题,原因尚不清楚。请尝试在没有 TestCafe Studio 的情况下使用命令行运行测试。为此,请检查您的 TestCafe Studio 的安装目录。就我而言,它是 C:\Program Files\TestCafe Studio\。 然后请运行以下命令: node <your_path_to_testcafe_studio>/resources/app.asar.unpacked/node_modules/testcafe/bin/testcafe <your_browser> <path_to_your_test_file>.

    例如,在我的例子中,命令是: node "C:/Program Files/TestCafe Studio/resources/app.asar.unpacked/node_modules/testcafe/bin/testcafe" firefox D:\projects\testcafe\test\functional\fixtures\api\raw\selector\testcafe-fixtures\new-fixture.testcafe

    请尝试运行此命令并分享结果。

    还请检查您使用的是最新的 TestCafe Studio。

    【讨论】:

      【解决方案2】:

      是的,您可以查看有关浏览器的 TestCafe docs

      简单地使用:testcafe "firefox:path/to/firefox:headless" tests/sample-fixture.js 您的测试将在 Firefox 中运行(需要安装浏览器)

      但是,还有另一个选项可以使用多个浏览器运行测试。另一种方式是使用runner 执行测试。

      按照文档(我的项目也是这样实现的),可以创建这样的文件:

      const createTestCafe = require('testcafe');
      let testcafe = null;
      createTestCafe()
          .then(tc => {
              testcafe = tc;
              // Start the runner
              const runner = testcafe.createRunner();
              // Start APP and wait 10s to ensure is up
              runner.startApp('npm run dev', 10000);
              return runner
                  // test folder
                  .src('./e2e/src/app.e2e-spec.js')
                  // Browsers where tests will be executed
                  .browsers([ /* List with your browsers */])
                  // Reporter to use if you want (optional)
                  .reporter('html', "./html-reporter/reports.html")
                  // Start tests
                  .run();
          })
          .then(_ => {
              testcafe.close();
          });
      

      内联解释,但想法很简单。使用TestCafe API,创建runner,设置选项并运行测试。

      我没有添加浏览器列表。这是个人选举,比如你想要 FireFox 和 Edge。
      您可以查看docs 的不同浏览器和选项。

      另外,我的清单是这样的:

      .browsers([
          'chrome:headless:emulation:device=iphone X',
          'firefox:headless:emulation:device=Samsung Galaxy S9',
          // And so on ... 
          ])
      

      第一个选项是浏览器本身。
      headless这是可选的,用于在不打开浏览器窗口的情况下运行(Safari 不支持它)。
      device 则是模拟设备。

      此外,在文档中,以更好的方式进行了解释。

      并使用简单的node runner.js 执行此文件,所有测试将在添加到列表中的每个浏览器中执行。

      【讨论】:

        猜你喜欢
        • 2019-08-25
        • 2014-12-27
        • 1970-01-01
        • 2018-09-30
        • 2019-02-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多