Dhruv Bhatnagar
Dhruv Bhatnagar

Reputation: 141

How to pass screenshot for the failed testcases to Report Portal. I am using Nightwatch for UI automation

Under the nightwatch.conf.js I have.

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

Although, this generates screenshots for failed testcases under the 'screenshots' folder but it doesn't share them on the Report portal. How can I achieve that?

Upvotes: 0

Views: 303

Answers (1)

Dmitriy Gumeniuk
Dmitriy Gumeniuk

Reputation: 420

Documentation with guides: https://reportportal.io/docs/dev-guides/AttachmentsGuide/#how-to-log-attachments-on-java-agents

Example:

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();
  },
};

Upvotes: 0

Related Questions