【问题标题】:Not able to save screenshot to report portal when executed using wdio使用 wdio 执行时无法将屏幕截图保存到报告门户
【发布时间】:2022-04-08 18:59:11
【问题描述】:

我有一个具有以下结构的 webdriverio 项目。 e2e/ 实用程序/pUtil.js 报告/截图 眼镜 wdio.config.js

我在 pUtil.js 中有以下内容

static takeScreenshot(name, failure = false, test) {
    const path = './e2e/report/screenshot/';
    let fileName = '';
    if (!fs.existsSync(path)) {
      fs.mkdirSync(path, { recursive: true });
    }
    if (failure) {
      fileName = name + '_fail';
    }
    fileName = fileName.replace(/ /g, '_') + '.png';
    browser.saveScreenshot(path + fileName);
    const data = fs.readFileSync(`${path}${fileName}`);
    reporter.sendFileToTest(test, 'INFO', fileName, data);
  }

我的项目配置为同时适用于魅力和报告门户报告。 当测试失败时,截图成功添加到诱惑报告而不是报告门户。

 ********* FILE NAME IN **********./e2e/report/screenshot/should_allow_us_fail.png
[2021-09-23T01:20:52.483Z] [0-0] ************ outputFile::./e2e/report/screenshot//should_allow_us_fail.png
[2021-09-23T01:20:52.483Z] [0-0] 2021-09-23T01:20:51.026Z ERROR @wdio/sync: Error: ENOENT: no such file or directory, open './e2e/report/screenshot/should_allow_us_fail.png'
[2021-09-23T01:20:52.483Z] [0-0]     at Object.openSync (fs.js:457:3)
[2021-09-23T01:20:52.483Z] [0-0]     at Object.readFileSync (fs.js:359:35)

有人可以指出我在这里缺少什么。

【问题讨论】:

    标签: javascript selenium jenkins webdriver-io


    【解决方案1】:

    试试这个!

    使用 wdio after: function (result, capabilities, specs) {} 钩子获取规范文件或使用 WDIO afterStep: async function (step, scenario, result, passed, error,duration) {}}, 钩子获取黄瓜以获取失败测试的屏幕截图。

    第 1 步:npm i wdio-reportportal-reporter
    WDIO 配置中的代码 sn-p

    const reportportal = require('wdio-reportportal-reporter');
    
    after: async function (result, capabilities, specs) {
      if (!result) {
         const screenShot = await global.browser.takeScreenshot();
         let attachment = await Buffer.from(screenShot, 'base64');
         await reportportal.sendFile('error', "screnshot.png", attachment);
     }
    },
    

    【讨论】:

      猜你喜欢
      • 2019-12-07
      • 1970-01-01
      • 2019-08-16
      • 1970-01-01
      • 1970-01-01
      • 2019-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多