【问题标题】:How to take screenShot in gherkin-cucumber using testace as a framework?如何使用 testace 作为框架在小黄瓜中截屏?
【发布时间】:2019-06-12 19:52:39
【问题描述】:

我正在尝试在某个步骤失败后截屏:

const { After } = require('cucumber');

After(function (scenario) {
    if (scenario.result.status ==='failed') {
        var world = this;
        return browser.takeScreenshot().then(function(screenShot, error) {
            if (!error) {
                world.attach(screenShot, "image/png");
            }
        });
    }
  });

它显示浏览器出现错误: ReferenceError: 浏览器未定义

【问题讨论】:

  • 您是否将网络驱动程序命名为driverbrowser

标签: javascript automated-tests cucumber gherkin testcafe


【解决方案1】:

试试下面的。确保根据您的使用情况匹配匹配的 webdriver var 名称。

var {After, Status} = require('cucumber');

After(function (testCase) {
  var world = this;
  if (testCase.result.status === Status.FAILED) {
    // driver- update this with the correct webDriver variable
    return driver.takeScreenshot().then(function(screenShot) {
      // screenShot is a base-64 encoded PNG
      world.attach(screenShot, 'image/png');
    });
  }
});

【讨论】:

  • 没错,但我关心的是驱动程序变量的获取位置。我需要安装一些东西,比如网络驱动程序吗?
  • 您在运行测试时看到浏览器打开了吗?如果是,那么您必须使用该步骤中的 WebDriver 实例名称。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-07
  • 1970-01-01
  • 2016-10-14
  • 1970-01-01
  • 2021-09-27
相关资源
最近更新 更多