Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_settings is undefined in global before hook #2245

Closed
cjmme opened this issue Nov 12, 2019 · 5 comments
Closed

test_settings is undefined in global before hook #2245

cjmme opened this issue Nov 12, 2019 · 5 comments
Assignees
Labels

Comments

@cjmme
Copy link

cjmme commented Nov 12, 2019

Describe the bug

I am upgrade the nightwatch version from 0.8.16 to 1.2.4, before I can use test_settings in global before() hook, but after upgrade to new version, it throw error

Cannot read property 'start_chromedriver' of undefined

hooks in globals

globals.js

// Please add the sample test here
var globals = {

    // this will overwrite the default polling interval (currently 500ms) for waitFor commands
    // and expect assertions that use retry
    waitForConditionPollInterval: 300,

    // default timeout value in milliseconds for waitFor commands and implicit waitFor value for
    // expect assertions
    waitForConditionTimeout: 25000,

    // default timeout value in milliseconds for global beforeEach and afterEach methods.
    asyncHookTimeout: 90000,

    before: function (callback) {
        console.log("Entering the global before function for nightwatch");
        if (this.test_settings.start_chromedriver) {
            console.log("need start chrome driver manually");
        }
        callback();
    },

        beforeEach: function (browser, callback) {
            callback();
    },

    afterEach: function (browser, callback) {
        if (browser.globals.test_settings.enablelog === "false") {
           callback();
        },
    };
        after: function (callback) {
            console.log("Ok! All tests execution done ");
        if (this.test_settings.shieldLogEnabled !== "false") {
            console.log("copying the selenium-debug.log to the test results directory");
            var destFilePath = process.env.runId ? seleniumAndBrowserLogPath : folderlogPath;
            copyFile("selenium-debug.log", destFilePath + "/selenium-debug.log");
        }
        callback();
    },

    updateDeviceInfo: function (browser) {
        const myCapabilities = this.test_settings.desiredCapabilities;
        const myBrowserName = myCapabilities.browserName || "";
        browser.device.isChrome = myBrowserName.toLowerCase().indexOf("chrome") >= 0;
        browser.device.isIEedge = myBrowserName.toLowerCase().indexOf("microsoftedge") >= 0;
        browser.device.isIE11 = myBrowserName.toLowerCase().indexOf("internet explorer") >= 0; 
        browser.device.isFirefox = myBrowserName.toLowerCase().indexOf("firefox") >= 0;
        browser.device.isSafari = myBrowserName.toLowerCase().indexOf("safari") >= 0;
    }
};
});

module.exports = globals;

Run with command

$ node.exe node_modules\nightwatch\bin\runner.js --test artifacts\build\tests\Authentication\LogInLogOut.js --env ofunk-localchrome

Verbose output

debug console log

<!-- 
 -->
Starting ChromeDriver on port 9515...
ChromeDriver up and running on port 9515 with pid: 3424 (1483ms).
Entering the global before function for nightwatch
TypeError: Cannot read property 'start_chromedriver' of undefined
at Object.before (C:\AZUREGIT\ReachClient\Shield\configs\globals.js:163:32)

Configuration

nightwatch.json

// Base Nightwatch configs
{
    src_folders: ["artifacts/build/tests"],
    output_folder: "artifacts/reports",
    globals_path: "configs/globals.js",
    custom_reporter_path: "artifacts/build/lib/custom-reporters/reporter.js",
    custom_commands_path: "artifacts/build/lib/custom-commands",
    custom_assertions_path: "artifacts/build/lib/custom-assertions",
    page_objects_path: "artifacts/build/lib/page-objects",
    "webdriver": {
        "server_path": "node_modules/chromedriver/lib/chromedriver/chromedriver.exe",
        "start_process": true,   
        "cli_args": [
        "--verbose"
        ],
        "port": 9515
    },
    test_settings: {
        default: {
            launch_url: "http://fakeurl/",         
            selenium_host: "",
            selenium_port: 80,
            selenium: {
                start_process: false                
            },
            start_chromedriver: false,
            silent: true,
            end_session_on_fail: false,
            desiredCapabilities: {
            browserName: "chrome",
            deviceType: "browser",
            loggingPrefs: {
                browser: "ALL",
                performance: "ALL",
                driver: "ALL"
            },
            chromeOptions: {
                "excludeSwitches": ["disable-component-update"],
                "prefs": {
                    "credentials_enable_service": false,
                    "profile.password_manager_enabled": false,
                    "profile.default_content_setting_values.plugins": 1,
                    "profile.content_settings.plugin_whitelist.adobe-flash-player": 1,
                    "profile.content_settings.exceptions.plugins.*,*.per_resource.adobe-flash-player": 1,
                    "profile.default_content_setting_values.notifications": 2
                },
                "args": [
                    "start-maximized",
                    "disable-webgl",
                    "blacklist-webgl",
                    "blacklist-accelerated-compositing",
                    "disable-accelerated-2d-canvas",
                    "disable-accelerated-compositing",
                    "disable-accelerated-layers",
                    "disable-accelerated-plugins",
                    "disable-accelerated-video",
                    "disable-accelerated-video-decode",
                    "disable-gpu",
                    "disable-infobars",
                    "test-type",
                    "disable-extensions"
                ]
            }
        }
    },
    },
}

Your Environment

Executable Version
nightwatch --version 1.2.4
npm --version 6.12.0
node --version 12.13.0
Browser driver Version
chromedriver 76
OS Version
Windows 10 VERSION
@ruben0626
Copy link

Is this something that will be fixed or is this expected since NW 1.x ?

I'm using a Proxy to pass the test_settings to the global hooks:

BaseHook.prototype.run = new Proxy(BaseHook.prototype.run, {
  apply: (target, thisArg, argumentsList) => {
    // eslint-disable-next-line camelcase
    thisArg.context.__module.test_settings = thisArg.context.settings;
    return target.apply(thisArg, argumentsList);
  },
});

@beatfactor
Copy link
Member

No it's not expected. This looks like a valid bug.

@beatfactor beatfactor added the bug label Nov 27, 2019
@beatfactor beatfactor added this to Needs triage in Nightwatch 1.3 via automation Nov 27, 2019
@beatfactor beatfactor moved this from Needs triage to High priority in Nightwatch 1.3 Nov 27, 2019
@beatfactor beatfactor moved this from High priority to Low priority in Nightwatch 1.3 Dec 4, 2019
@yarm
Copy link

yarm commented Jan 8, 2020

Any workaround on the issue? I need this to work.

@stale
Copy link

stale bot commented Apr 7, 2020

This issue has been automatically marked as stale because it has not had any recent activity.
If possible, please retry using the latest Nightwatch version and update the issue with any relevant details. If no further activity occurs, it will be closed. Thank you for your contribution.

@stale stale bot added the stale label Apr 7, 2020
@stale stale bot closed this as completed Apr 14, 2020
Nightwatch 1.3 automation moved this from Low priority to Closed Apr 14, 2020
@lukaszw82
Copy link

It is reproducible in the latest version, i.e. 1.4.3. Test_settings is undefined in global before hook.

@beatfactor beatfactor reopened this Sep 22, 2020
Nightwatch 1.3 automation moved this from Closed to Needs triage Sep 22, 2020
@stale stale bot removed the stale label Sep 22, 2020
@beatfactor beatfactor self-assigned this Oct 5, 2020
Nightwatch 1.3 automation moved this from Needs triage to Closed Oct 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Nightwatch 1.3
  
Closed
Development

No branches or pull requests

5 participants