如何将失败测试用例的屏幕截图传递给报告门户。我正在使用 Nightwatch 进行 UI 自动化

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

nightwatch.conf.js下我有。

"screenshots": {
            "enabled": true,
            'on_failure': true,
            'on_errors': true,
            'path': 'tests_output/screenshots'
        },

尽管这会在“屏幕截图”文件夹下生成失败测试用例的屏幕截图,但不会在报告门户上共享它们。我怎样才能做到这一点?

ui-automation nightwatch.js nightwatch reportportal automation-testing
1个回答
0
投票

带指南的文档: https://reportportal.io/docs/dev-guides/AttachmentsGuide/#how-to-log-attachments-on-java-agents

例子:

npm install --save-dev nightwatch-reportportal-agent nightwatch-reportportal-commands
const ReportPortalAgent = require('nightwatch-reportportal-agent');

module.exports = {
  // ...
  test_settings: {
    default: {
      // ...
      globals: {
        report: new ReportPortalAgent({
          // Your ReportPortal config
          token: 'your_token',
          endpoint: 'your_reportportal_url',
          launch: 'your_launch_name',
          project: 'your_project_name',
          attributes: [
            {
              key: 'key',
              value: 'value',
            },
          ],
        }),
      },
      custom_commands_path: './node_modules/nightwatch-reportportal-commands/commands',
    },
  },
  // ...
};
module.exports = {
  'My Failed Test': function (browser) {
    browser
      .url('https://www.example.com')
      .waitForElementVisible('body')
      .assert.title('Wrong Title') // This assertion will fail
      .saveScreenshot('./screenshots/failed-test.png', function (response) {
        // Report a failed test with a screenshot
        if (response.status === 0) {
          browser.report().sendLog('ERROR', 'Test failed', {
            level: 'ERROR',
            file: {
              name: 'failed-test.png',
              type: 'image/png',
              content: response.value,
            },
          });
        }
      })
      .end();
  },
};
© www.soinside.com 2019 - 2024. All rights reserved.