{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","params":[],"results":{"codes":[]},"settings":""},"next":{"description":"","pages":[]},"title":"Multi-browser testing","type":"basic","slug":"multi-browser-testing","excerpt":"","body":"To test using multiple browsers you need to use environment variable like so:\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"export CUCUMBER_BROWSERS=2\",\n \"language\": \"shell\"\n }\n ]\n}\n[/block]\nThis will expose the browser instances in global browser.instances variable. There are different ways of using this, but here is some code example for inspiration:\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"var browsers;\\n\\nthis.Before(function() {\\n browsers = {\\n Alice: browser.instances[0],\\n Bob: browser.instances[1]\\n };\\n})\\n\\nthis.Given(/^([^ ]*) go(?:es)? to \\\"([^\\\"]*)\\\"$/, function (person, relativePath) {\\n getBrowserFor(person).url(url.resolve(process.env.ROOT_URL, relativePath));\\n});\\n\\nthis.Then(/^([^ ]*) sees? \\\"([^\\\"]*)\\\" label$/, function (person, label) {\\n var _labelSelector = \\\"//*//label[text()='\\\" + label + \\\"']\\\";\\n expect(getBrowserFor(person).isVisible(_labelSelector)).toBe(true);\\n});\\n\\n\\nfunction getBrowserFor(person) {\\n return (person === 'Both') ? browser : browsers[person];\\n}\",\n \"language\": \"javascript\"\n }\n ]\n}\n[/block]\nThen you can use Bob and Alice in your .feature files:\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \" Scenario: Login into the system\\n Given Both go to \\\"/\\\"\\n Then Alice sees \\\"Very nice\\\" label\\n And Bob sees \\\"Very nice\\\" label\",\n \"language\": \"text\"\n }\n ]\n}\n[/block]\nIn production code you'd probably want to make the browsers variable global and expose it to your step definitions.","updates":[],"order":5,"isReference":false,"hidden":true,"sync_unique":"","link_url":"","link_external":false,"_id":"573f26b8edc85919005a8856","__v":5,"createdAt":"2016-05-20T15:01:12.068Z","category":{"sync":{"isSync":false,"url":""},"pages":["56cf5ea2287eb20b009f9f2e"],"title":"Advanced","slug":"advanced","order":2,"from_sync":false,"reference":false,"_id":"56cf5c8d336aa60b0086a40d","__v":1,"createdAt":"2016-02-25T19:57:01.905Z","project":"559b65bd8b04e90d00702d54","version":"559b65bd8b04e90d00702d57"},"githubsync":"","project":"559b65bd8b04e90d00702d54","user":"573f23ce176bea2b000e96eb","version":{"version":"1.0","version_clean":"1.0.0","codename":"","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["559b65be8b04e90d00702d58","55a46e7468c7e20d0036d4d1","55a4971be6c2470d002a6483","55a4a690e10ba50d00b40bba","55a4bcf31a5f991700a94066","56cf5c8d336aa60b0086a40d"],"_id":"559b65bd8b04e90d00702d57","releaseDate":"2015-07-07T05:38:05.890Z","createdAt":"2015-07-07T05:38:05.890Z","project":"559b65bd8b04e90d00702d54","__v":6},"parentDoc":null}