nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.84k stars 1.33k forks source link

I can't use multiple environments with cucumber #3910

Open egarc12 opened 1 year ago

egarc12 commented 1 year ago

Description of the bug/issue

I am using cucumber. When I use a single environment value, the test works correctly but when I use two or more environment values to run tests in different browsers in parallel, the test fails.

Reviewing the source code of the library I found that it was disabled (In the PR https://github.com/nightwatchjs/nightwatch/pull/3755) to cucumber the following parameter "supportsConcurrency" but when I set it to true it works correctly, That's why my parallel tests work until version 2.6.21

As you can see, I do not use the "--parallel" flag and I do not use the workers mode, my strategy to execute in parallel is to use more than one environment in the "--env" flag

Is it possible that the value of "supportsConcurrency" can be changed through some parameter and not simply disabled for everyone?

Steps to reproduce

  1. Go to '...'
  2. Click on '...'
  3. Scroll down to '...'
  4. See error

Sample test

i'm using cucumber, any feature can be used

Command to run

npx nightwatch --format @cucumber/pretty-formatter --require cucumber.conf.js --require './src/features/support/config.js' --format json:reports/cucumber.json --format @serenity-js/cucumber --tags @leavePayInHome -e device.desktop.0,device.desktop.1

Verbose Output

✖ TypeError
   Cannot read properties of undefined (reading 'slice')
    Stack Trace :
    at CucumberRunnner.runTests (/Users/erneydavidgarciavergara/Documents/GitHub/bbog-pse-automated-testing/node_modules/nightwatch/dist/runner/test-runners/cucumber.js:187:36)
    at CucumberRunnner.run (/Users/erneydavidgarciavergara/Documents/GitHub/bbog-pse-automated-testing/node_modules/nightwatch/dist/runner/test-runners/default.js:143:33)
    at CliRunner.executeTestRunner (/Users/erneydavidgarciavergara/Documents/GitHub/bbog-pse-automated-testing/node_modules/nightwatch/dist/runner/cli/cli.js:369:32)
    at /Users/erneydavidgarciavergara/Documents/GitHub/bbog-pse-automated-testing/node_modules/nightwatch/dist/runner/cli/cli.js:437:29

Nightwatch Configuration

const percy = require('@percy/nightwatch');
const config = require('./pipeline/config.json');
require('dotenv').config();

const ignoreCertificateError = '--ignore-certificate-errors';
const proxyServer = `--proxy-server=http://127.0.0.1:${process.env.PORT_ZAP || '8080'}`;
const proxyBypass = '--proxy-bypass-list=*labdigbdbpse.com*,bs-local.com';
const resolutionScreen = '--window-size=1920,1080';
const noSandbox = '--no-sandbox';
const disableDevShmUsage = '--disable-dev-shm-usage';
const headless = '--headless';
const argsWithProxy = [
    proxyServer,
    ignoreCertificateError,
    noSandbox,
    disableDevShmUsage,
    proxyBypass
];
const argsWithoutProxy = [
    ignoreCertificateError,
    noSandbox,
    disableDevShmUsage,
];

const configuration = {
    custom_assertions_path: 'src/custom-assertions',
    custom_commands_path: [percy.path, 'src/custom-commands'],
    src_folders: ['src/step-definitions'],
    output_folder: 'reports',
    page_objects_path: 'src/pageObjects',
    globals_path: 'src/globals/myGlobals.js',
    detailed_output: false,
    live_output: false,
    webdriver: {},
    plugins: ['@nightwatch/browserstack'],
    '@nightwatch/browserstack': {
        test_observability: {
            enabled: true,
            user: process.env.BROWSERSTACK_USER,
            key: process.env.BROWSERSTACK_KEY,
            projectName: 'PSE',
            buildName: 'Automation',
            buildTag: ['Nightwatch','Browserstack']
        }
    },
    test_runner: {
        type: 'cucumber',
        options: {
            feature_path: 'src/features/*/*.feature',
            auto_start_session: true
        }
    },
    test_settings: {
        default: {
            log_screenshot_data: true,
            screenshots: {
                enabled: true,
                on_failure: true,
                on_error: true,
                path: './reports/screenshots'
            },
            end_session_on_fail: false,
            skip_testcases_on_fail: false,
            element_command_retries: 5,
            webdriver: {
                start_process: true,
                log_path: './reports/logs-webdriver'
            },
            globals: {
                waitForConditionTimeout : 10000,
                abortOnElementLocateError: true,
                retryAssertionTimeout: 10000
            }
        },
        'safari.default': {
            extends: 'default',
            desiredCapabilities: {
                browserName: 'safari',
                javascriptEnabled: true,
                acceptSslCerts: true,
                takesScreenshot: true
            },
            webdriver: {
                port: 4445,
                start_process: true,
                server_path: '/usr/bin/safaridriver',
            }
        },
        'chrome.default': {
            extends: 'default',
            desiredCapabilities: {
                browserName: 'chrome',
                javascriptEnabled: true,
                acceptSslCerts: true,
                acceptInsecureCerts: true,
                takesScreenshot: true,
                'goog:chromeOptions': {
                    args: process.env.GITHUB_ACTIONS ? argsWithoutProxy : argsWithProxy
                }
            },
            webdriver: {
                start_process: true,
                port: 4444,
                server_path: process.env.GITHUB_ACTIONS ?
                    '/usr/local/share/chrome_driver/chromedriver' :
                    './pipeline/drivers/chromedriver'
            }
        },
        'chrome.headless': {
            extends: 'chrome.default',
            desiredCapabilities: {
                'goog:chromeOptions': {
                    args: [
                        `${headless}=new`,
                        resolutionScreen
                    ]
                }
            }
        },
        'edge.default': {
            extends: 'default',
            desiredCapabilities: {
                browserName: 'MicrosoftEdge',
                acceptInsecureCerts: true,
                javascriptEnabled: true,
                takesScreenshot: true,
                acceptSslCerts: true,
                'ms:edgeOptions': {
                    args: process.env.GITHUB_ACTIONS ? argsWithoutProxy : argsWithProxy
                }
            },
            webdriver: {
                port: 4444,
                start_process: true,
                server_path: process.env.GITHUB_ACTIONS ?
                    '/usr/local/share/edge_driver/msedgedriver' :
                    './pipeline/drivers/msedgedriver'
            }
        },
        'edge.headless': {
            extends: 'edge.default',
            desiredCapabilities: {
                'ms:edgeOptions': {
                    args: [
                        resolutionScreen,
                        `${headless}=new`
                    ]
                }
            }
        },
        'firefox.default': {
            extends: 'default',
            desiredCapabilities: {
                browserName: 'firefox',
                javascriptEnabled: true,
                acceptSslCerts: true,
                acceptInsecureCerts: true,
                takesScreenshot: true,
                marionette: true,
                'moz:firefoxOptions': {
                    args: process.env.GITHUB_ACTIONS ? argsWithoutProxy : argsWithProxy
                },
                'moz:webdriverClick': false
            }
        },
        'firefox.headless': {
            extends: 'firefox.default',
            desiredCapabilities: {
                'moz:firefoxOptions': {
                    args: [
                        headless,
                        resolutionScreen
                    ]
                }
            }
        },
        bs: {
            extends: 'default',
            selenium: {
                host: 'hub-cloud.browserstack.com',
                port: 443,
                log_path: 'reports'
            },
            // More info on configuring capabilities can be found on:
            // https://www.browserstack.com/automate/capabilities?tag=selenium-4
            desiredCapabilities: {
                'bstack:options': {
                    'projectName': 'PSE',
                    'buildTag': 'PSE',
                    'buildName': 'PSE-ValDispositivos',
                    'debug': 'true',
                    'networkLogs': 'true',
                    'seleniumVersion': '3.141.59',
                    'consoleLogs': 'errors',
                    'userName': process.env.BROWSERSTACK_USER,
                    'accessKey': process.env.BROWSERSTACK_KEY,
                    'geoLocation': 'CO',
                    'idleTimeout': '120',
                    'local': process.env.GITHUB_ACTIONS ? 'false' : 'true'
                },
                'acceptSslCerts': true
            },
            disable_error_log: false,
            webdriver: {
                timeout_options: {
                    timeout: 120000,
                    retry_attempts: 3,
                },
                keep_alive: {
                    'enabled': true,
                    'keepAliveMsecs': 4000
                },
                start_process: false,
            },
        },
        'bs.desktop': {
            extends: 'bs',
            desiredCapabilities: {
                'bstack:options': {
                    'os': config.devices.desktop[1].device,
                    'osVersion': config.devices.desktop[1].osVersion,
                    'browserVersion': 'latest',
                    'resolution': '1920x1080',
                },
                'browserName': config.devices.desktop[1].browser,
                'goog:chromeOptions': {
                    args: process.env.GITHUB_ACTIONS ? argsWithoutProxy : argsWithProxy
                },
            },
        },
        'bs.mobile': {
            extends: 'bs',
            desiredCapabilities: {
                'bstack:options': {
                    'osVersion' : config.devices.mobile[0].osVersion,
                    'deviceName' : config.devices.mobile[0].device,
                },
                'browserName' : config.devices.mobile[0].browser,
                'goog:chromeOptions': {
                    args: process.env.GITHUB_ACTIONS ? argsWithoutProxy : argsWithProxy
                },
            },
        },
        'bs.tablet': {
            extends: 'bs',
            desiredCapabilities: {
                'bstack:options': {
                    'osVersion' : config.devices.tablet[0].osVersion,
                    'deviceName' : config.devices.tablet[0].device,
                },
                'browserName' : config.devices.tablet[0].browser,
                'goog:chromeOptions': {
                    args: process.env.GITHUB_ACTIONS ? argsWithoutProxy : argsWithProxy
                },
            },
        },
    }
};

if(process.env.EXECUTOR.startsWith('device.')){
    setMultipleDevices();
}

function setMobileDevices(){
    for (var mobile=0; mobile<config.devices.mobile.length; mobile++) {
        configuration.test_settings[`device.mobile.${mobile}`] = {
            extends: 'bs',
            desiredCapabilities: {
                'bstack:options': {
                    'osVersion' : config.devices.mobile[mobile].osVersion,
                    'deviceName' : config.devices.mobile[mobile].device,
                },
                'browserName' : config.devices.mobile[mobile].browser,
                'goog:chromeOptions': {
                    args: process.env.GITHUB_ACTIONS ? argsWithoutProxy : argsWithProxy
                },
            },
        };
    }
}

function setTabletDevices(){
    for (var tablet=0; tablet<config.devices.tablet.length; tablet++) {
        configuration.test_settings[`device.tablet.${tablet}`] = {
            extends: 'bs',
            desiredCapabilities: {
                'bstack:options': {
                    'osVersion' : config.devices.tablet[tablet].osVersion,
                    'deviceName' : config.devices.tablet[tablet].device,
                },
                'browserName' : config.devices.tablet[tablet].browser,
                'goog:chromeOptions': {
                    args: process.env.GITHUB_ACTIONS ? argsWithoutProxy : argsWithProxy
                },
            },
        };
    }
}

function setDesktopDevices(){
    for (var desktop=0; desktop<config.devices.desktop.length; desktop++) {
        configuration.test_settings[`device.desktop.${desktop}`] = {
            extends: 'bs',
            desiredCapabilities: {
                'bstack:options': {
                    'os': config.devices.desktop[desktop].device,
                    'osVersion': config.devices.desktop[desktop].osVersion,
                    'browserVersion': 'latest',
                    'resolution': '1920x1080',
                },
                'browserName': config.devices.desktop[desktop].browser,
                'goog:chromeOptions': {
                    args: process.env.GITHUB_ACTIONS ? argsWithoutProxy : argsWithProxy
                },
            },
        };
    }
}

function setMultipleDevices() {
    switch (process.env.EXECUTOR.slice(7)) {
    case 'mobile':
        setMobileDevices();
        break;
    case 'desktop':
        setDesktopDevices();
        break;
    case 'tablet':
        setTabletDevices();
        break;
    case 'default':
        setDesktopDevices();
        setMobileDevices();
        setTabletDevices();
        break;
    default:
        console.error('Opcion no valida');
        break;
    }
}

module.exports = configuration;

Nightwatch.js Version

3.1.2

Node Version

20.5.0

Browser

Any

Operating System

Any

Additional Information

Below I leave some access to the lines of code that I was able to review

supportsConcurrency in v2.6.21 https://github.com/nightwatchjs/nightwatch/blob/2b8a6041573d1e31e248ea1471fcee3dcb380057/lib/runner/test-runners/cucumber.js#L209

supportsConcurrency in v3.1.3 https://github.com/nightwatchjs/nightwatch/blob/2b7c29ef40e4c01d5d0246402b9525811432cdd5/lib/runner/test-runners/cucumber.js#L216

line of code where execution fails https://github.com/nightwatchjs/nightwatch/blob/2b7c29ef40e4c01d5d0246402b9525811432cdd5/lib/runner/test-runners/cucumber.js#L234

drubio4 commented 1 year ago

Hi there:

Same problem here, parallelism broken from Nightwatch v3 onwards.

Looking foward to your comments.

Venkata-Pravinya commented 9 months ago

Hi,

The issue exists for me too. I am also looking for the solution. Any solutions please.

Thanks, Venkata Pravinya