Hi i want to get browser name in the onPrepare function,

I used the below code.

browser.getCapabilities().then((c) => {


the code writes the browser name properly on the console if i use:

browser.getCapabilities().then((c) => {


But i gets 'undefined' on, return , set to a variable or set to browser.browserName. Could someone help me here

I tried below three methods:

var a;

    browser.getCapabilities().then((c) => {

          a= c.get('browserName');

var a=  browser.getCapabilities().then((c) => {

              return c.get('browserName');


    browser.getCapabilities().then((c) => {

          global.a= c.get('browserName');

Maybe try browser.getProcessedConfig instead of getCapabilities, because I cant find that in the Protractor API documentation.

Get the processed configuration object that is currently being run. This will contain the specs and capabilities properties of the current runner instance.


Code example:

  onPrepare: function() {
    return browser.getProcessedConfig().then(data => {
      global.deviceName = data.capabilities.browserName;

Based on a code example from:

  • Hi this returns a managed promise, ManagedPromise::89 {[[PromiseStatus]]: "pending"} – PDHide Oct 22 at 14:25
  • I want to get the browser name and use it in next line – PDHide Oct 22 at 14:25
  • @PDHide I am not a protractor user, so i cannot make a working example. Updated my code example and added another link that might help. – Niels van Reijmersdal Oct 22 at 14:48
  • What happens if i don't use the return keyword? – PDHide Oct 22 at 15:38
  • Try? I think you should find a JavaScript developer close by, because the async nature of JavaScript is sometimes hard to initially grasp. The promise is a way to handle the async nature of JavaScript if you know how to work with them. Just randomly doing trail and error wont overcome this probably. – Niels van Reijmersdal Oct 23 at 7:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.