{"_id":"573f26b8edc85919005a8856","__v":4,"category":{"_id":"56cf5c8d336aa60b0086a40d","__v":1,"pages":["56cf5ea2287eb20b009f9f2e"],"project":"559b65bd8b04e90d00702d54","version":"559b65bd8b04e90d00702d57","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-02-25T19:57:01.905Z","from_sync":false,"order":2,"slug":"advanced","title":"Advanced"},"project":"559b65bd8b04e90d00702d54","user":"573f23ce176bea2b000e96eb","version":{"_id":"559b65bd8b04e90d00702d57","project":"559b65bd8b04e90d00702d54","__v":6,"createdAt":"2015-07-07T05:38:05.890Z","releaseDate":"2015-07-07T05:38:05.890Z","categories":["559b65be8b04e90d00702d58","55a46e7468c7e20d0036d4d1","55a4971be6c2470d002a6483","55a4a690e10ba50d00b40bba","55a4bcf31a5f991700a94066","56cf5c8d336aa60b0086a40d"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-05-20T15:01:12.068Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":999,"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.","excerpt":"","slug":"multi-browser-testing","type":"basic","title":"Multi-browser testing"}

Multi-browser testing


To test using multiple browsers you need to use environment variable like so: [block:code] { "codes": [ { "code": "export CUCUMBER_BROWSERS=2", "language": "shell" } ] } [/block] This 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: [block:code] { "codes": [ { "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}", "language": "javascript" } ] } [/block] Then you can use Bob and Alice in your .feature files: [block:code] { "codes": [ { "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", "language": "text" } ] } [/block] In production code you'd probably want to make the browsers variable global and expose it to your step definitions.