nightwatch icon indicating copy to clipboard operation
nightwatch copied to clipboard

No screenshot is captured when cucumber test failed.

Open SDETQATestAutomation opened this issue 3 years ago • 5 comments

Describe the bug

No screenshot is captured when cucumber test failed. With same configuration failed nightwatch test is capturing screenshot. Tested with Nightwatch-CucumberJS Boilerplate and getting same screenshot issue

Sample test

sampleTest.js

// Please add the sample test here

const {When, Before} = require('@cucumber/cucumber');
const assert = require('assert').strict;
When(/^I test my step for assert fail$/, function() {
        assert.strictEqual(true,false,new TypeError("Expected and Actual values are not matching"));
    });

Run with command

$ node nightwatch.js -c config/nightwatch.webdriver.cucumber.conf.js -e chrome

Verbose output

debug.log

<!-- Include the verbose output, if possible (run nightwatch with `--verbose` argument) -->

Configuration

nightwatch.json

module.exports = {
  live_output: true,
  disable_colors: false,
  output_folder: "reports/",
  custom_commands_path: "",
  page_objects_path: "",
  globals_path: "",
  src_folders: ["tests/stepdefs"],

  test_workers: false,
  webdriver: {
    start_process: true,
    server_path: require('selenium-webdriver').path,
    log_path: "./",
    host: "127.0.0.1",
    port: 4444,
    cli_args: [
      "--verbose"
    ]
  },
  test_runner: {
    type: 'cucumber',
    options: {
      feature_path: 'tests/features/*.feature',
      additional_config: '',
      parallel: 2
    }

  },
  test_settings: {
    default: {
      launch_url: "http://localhost",
      "selenium.host": "127.0.0.1",
      "selenium.port": 4444,
      silent: true,
      disable_colors: false,
      disable_error_log: true,
      report_network_errors: false,
      skip_testcases_on_fail: false,
      end_session_on_fail: false,
      screenshots: {
        enabled: true,
        on_failure: true,
        on_error: true,
        path: "./screenshots"
      },
      log_screenshot_data: false,
      desiredCapabilities: {
        browserName: "chrome",
        javascriptEnabled: true,
        acceptSslCerts: true
      }
    },
    chrome: {
      desiredCapabilities: {
        browserName: "chrome",
        javascriptEnabled: true,
        acceptSslCerts: true,
        elementScrollBehavior: 1,
        "goog:chromeOptions": {
          "w3c": true,
          "args": [
            "--allow-cross-origin-auth-prompt",
            "--allow-control-allow-origin",
            "-–allow-file-access-from-files",
            "--test-type",
            "disable-infobars",
            "--disable-extensions",
            "--start-maximized",
            "--lang=en",
            "--no-sandbox",
          ],
          excludeSwitches: ["enable-automation", "disable-popup-blocking", "enable-logging"],
          useAutomationExtension: false,
          prefs: {
            credentials_enable_service: false,
            profile: { password_manager_enabled: false },
            extentions: {},
            download: {
              'prompt_for_download': false,
              'directory_upgrade': true,
              'default_directory': '/downloads',
            }
          }
        },
        "loggingPrefs": { "driver": "INFO", "server": "OFF", "browser": "INFO" }
      }
    },
  }
};

Your Environment

Executable Version
nightwatch --version 2.0.5
npm --version 6.14.13
node --version v14.17.3
Browser driver Version
chromedriver 96
OS Version
Windows 10 20H2

SDETQATestAutomation avatar Feb 08 '22 03:02 SDETQATestAutomation

The sample case doesn't show that a url has been open so I don't know what we are taking a screenshot of.

beatfactor avatar Feb 09 '22 11:02 beatfactor

Tested with below step definition

const {When, Before} = require('@cucumber/cucumber');
const assert = require('assert').strict;
When(
    /^I test my step for assert fail$/, async function() {
        await browser.url("https://www.google.com");
        assert.strictEqual(true,false,new TypeError("Expected and Actual values are not matching"));
    });

console output is

$ node nightwatch.js -c config/nightwatch.webdriver.cucumber.conf.js --browser chrome
{
  _: [],
  c: 'config/nightwatch.webdriver.cucumber.conf.js',
  config: 'config/nightwatch.webdriver.cucumber.conf.js',
  browser: 'chrome',
  env: 'chrome',
  e: 'chrome',
  reporter: 'junit',
  r: 'junit',
  '$0': 'C:\\MyInstalledProgram\\nodejs\\node.exe C:\\GartnerWorkspace\\cpp_framework\\cppdocs_v2.0\\nightwatch.js',
  _source: []
}
Before All


ℹ Connected to ChromeDriver on port 4444 (3398ms).
  Using: chrome (97.0.4692.99) on WINDOWS.

  ℹ Loaded url https://www.google.com in 5798ms
F.

Failures:

1) Scenario: Searching DuckDuckGo # tests\features\MyTest.feature:7
   √ Before # node_modules\nightwatch\cucumber-js\_setup_cucumber_runner.js:6
   × And I test my step for assert fail # tests\stepdefs\MyTest.js:4
       TypeError: Expected and Actual values are not matching
           at World.<anonymous> (C:\GartnerWorkspace\cpp_framework\cppdocs_v2.0\tests\stepdefs\MyTest.js:7:39)
           at processTicksAndRejections (internal/process/task_queues.js:95:5)
   √ After # node_modules\nightwatch\cucumber-js\_setup_cucumber_runner.js:66

1 scenario (1 failed)
1 step (1 failed)
0m10.707s (executing steps: 0m10.603s)

no screenshot is captured.

SDETQATestAutomation avatar Feb 09 '22 14:02 SDETQATestAutomation

Also encountered this problem,any news?

Liubasara avatar Feb 28 '22 10:02 Liubasara

Also encountered this problem,any news?

hpavanatti avatar Apr 04 '22 00:04 hpavanatti

No screenshots on failure when cucumber used. nightwatch v2.3.4 cucumber v8.5.1 (cucumber v8.5.2 does not work at all)

veke avatar Sep 10 '22 08:09 veke

The same here with nightwatch 2.3.0 and @cucumber/cucumber 8.5.1

ymatviikiv avatar Dec 07 '22 13:12 ymatviikiv

Hello, maybe someone will need those... I've added a workaround, directly taking a screenshot in after hooks if the status of a test is failed:

if (options.result.status === "failed" || "FAILED") {
        browser.saveScreenshot(`./screenshots/${global.config.testRail_ID}.png`)

ymatviikiv avatar Dec 19 '22 14:12 ymatviikiv