Working with global.js in nightwatch js
<p>I am writing some test in nightwatch and have a globals.js file which is literally exporting a js object below.</p>

<pre><code>var self = module.exports = {
    environment: undefined,
    beforeEach: function (browser, done) {
        browser.execute(function(data) {
            return window.navigator.userAgent;
        }, [], function(result) {
            self.environment = result.value;
            console.log("Run against: " + self.environment);
            done();
        });
        console.log('the new env is', self.environment);
    },
};
</code></pre>

<p>Note : <code>console.log("Run against: " + self.environment);</code> prints my env value which is not undefined in this case. However. When ever i try to access environ from another file/class . It returns the default undefined despite the fact that i updated it previously. Example is from the test below.</p>

<pre><code>module.exports = {
    tags: ['assetindex'],
    'visit': function(browser) {

        console.log('the environment is', browser.globals.environment);
        (/Chrome/.test(browser.globals.environment)) ?
            browser
                .page.assetindex().mobileVisit()
                .end()
        :
            browser
                .page.assetindex().desktopVisit()
                .end()
    }
};
</code></pre>

<p><code>browser.globals.environment</code> always returned undefined here despite the fact that i changed it in my beforeEach function. Please how do i achieve this? What am i doing wrong ?</p>