{"action":"closed","issue":{"url":"https://api.github.com/repos/cucumber/cucumber-js/issues/674","repository_url":"https://api.github.com/repos/cucumber/cucumber-js","labels_url":"https://api.github.com/repos/cucumber/cucumber-js/issues/674/labels{/name}","comments_url":"https://api.github.com/repos/cucumber/cucumber-js/issues/674/comments","events_url":"https://api.github.com/repos/cucumber/cucumber-js/issues/674/events","html_url":"https://github.com/cucumber/cucumber-js/issues/674","id":190846549,"number":674,"title":"Writing To A Global Variable When Tests Are Run In Parallel","user":{"login":"bhreinb","id":20628685,"avatar_url":"https://avatars.githubusercontent.com/u/20628685?v=3","gravatar_id":"","url":"https://api.github.com/users/bhreinb","html_url":"https://github.com/bhreinb","followers_url":"https://api.github.com/users/bhreinb/followers","following_url":"https://api.github.com/users/bhreinb/following{/other_user}","gists_url":"https://api.github.com/users/bhreinb/gists{/gist_id}","starred_url":"https://api.github.com/users/bhreinb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bhreinb/subscriptions","organizations_url":"https://api.github.com/users/bhreinb/orgs","repos_url":"https://api.github.com/users/bhreinb/repos","events_url":"https://api.github.com/users/bhreinb/events{/privacy}","received_events_url":"https://api.github.com/users/bhreinb/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-21T21:54:17Z","updated_at":"2016-11-23T16:55:35Z","closed_at":"2016-11-23T16:55:35Z","body":"Hi There\r\n\r\nI'm not sure whether this is the right thread to post this comment in but I was hoping somebody can help with this?\r\n\r\nI have the following configuration data snippet\r\n\r\n```\r\nvar _Global;\r\n\r\nbeforeLaunch: function()\r\n{\r\n\r\n    var Fsp = require('fs-promise'), mkdirp = require('mkdirp'), ResultsDirectory = './Results';\r\n\r\n    //Minimum MetaData That Will Get Wrote To Report...\r\n    global.MetaData =\r\n    {\r\n\r\n        OsPlatform: null,\r\n\r\n        AngularVersion: null\r\n\r\n    };\r\n\r\n    _Global = global;\r\n\r\n    return Fsp.exists(ResultsDirectory)\r\n    .then(function(exists) { if(exists) { return Fsp.remove(ResultsDirectory); } })\r\n    .then(function()\r\n    {\r\n\r\n        return mkdirp(ResultsDirectory, function (err)\r\n        {\r\n\r\n            if (err)\r\n\r\n                console.error(err);\r\n\r\n            else\r\n\r\n                console.log('Directory To Store Test Results Created As Expected!!!');\r\n\r\n        });\r\n\r\n    });\r\n\r\n},\r\n\r\nonPrepare: function()\r\n{\r\n\r\n    var _this = this;\r\n\r\n    browser.ignoreSynchronization = false;\r\n\r\n    browser.getProcessedConfig().then(function(currentConfig)\r\n    {\r\n\r\n        console.log('For This Test We Are Using Browser: ' + currentConfig.capabilities.browserName);\r\n\r\n        console.log('Full Details Listed Below:');\r\n\r\n        console.log(JSON.stringify(currentConfig.capabilities, null, 4));\r\n\r\n    });\r\n\r\n    return browser.get(browser.baseUrl)\r\n    .then(function() {return browser.executeScript(\"return window.angular.version.full;\")})\r\n    .then(function(AngularVersion)\r\n    {\r\n\r\n        _Global.MetaData.OsPlatform = require('os').platform().toUpperCase();\r\n\r\n        //BrowserName & Version...\r\n        browser.getCapabilities().then(function (Caps)\r\n        {\r\n\r\n            var BrowserObject = JSON.parse(\"{\\\"\" + Caps.get('browserName') + \"\\\": \\\"\" +Caps.get('version')+ \"\\\"}\");\r\n\r\n            return Object.assign(_Global.MetaData, BrowserObject);\r\n\r\n        });\r\n\r\n        return _Global.MetaData.AngularVersion = AngularVersion;\r\n\r\n    });\r\n\r\n\r\n},\r\n\r\nafterLaunch: function(ExitCode)\r\n{\r\n\r\n    console.log('Finished With Exit Code ' +ExitCode);\r\n\r\n    return Reports.GetAllJsonFilesInResultsDirectory()\r\n    .then(function() {return Reports.MergeJsonFilesToOneObject();})\r\n    .then(function() {return Reports.WriteJsonStringToFileSystem();})\r\n    .then(function() {return Reports.CreateJunitXmlReport();})\r\n    .then(function() {return Reports.CreateHtmlReports();})\r\n    .then(function(Results)\r\n    {\r\n\r\n        Results.forEach(function(Result)\r\n        {\r\n\r\n            console.log(Result);\r\n\r\n        });\r\n\r\n    });\r\n\r\n}\r\n\r\n```\r\nWhen I run the tests on a single browser instance this works every time but when I run in parallel this fails on function \"onPrepare\", namely it throws an exception. Does \"cucumber.js\" have a global space that test data could be wrote to or any similar equivalent?\r\n\r\nBasically the use here is to write the browser name & version to a global variable \"MetaData\" which will get wrote to the final report generated. So in parallel tests you would have browser information for ie, firefox & chrome wrote to object \"MetaData\". Many thanks in advance as to any guidance anyone provides."}}
{"actor":{"display_login":"bhreinb"}}