Protractor: How to get deviceName value from Multicapabilities definition at run time

Created on 28 Feb 2018  路  5Comments  路  Source: angular/protractor

Hi Team,

This might be repeated question for you guys but really I didn't answer yet.
Here is my multi-capabilities definition in protractor config file.
I want to access the deviceName parameter value. How can I do it?

exports.config = {
directConnect:true,
    multiCapabilities: [
        {
            browserName: 'chrome',
            'chromeOptions': {
                'mobileEmulation': {
                    'deviceName': 'iPad'
                }
            }
        }
],

Tried under onPrepare but not giving multi-capabilities values

browser.getCapabilities().then(function(c) {
            console.log(c.get('deviceName'));
        });

Most helpful comment

@kat0072, please take a look at get-config-capabilities for requested example.

All 5 comments

Hi, @kat0072 ! You can do it using browser.getProcessedConfig() function.

onPrepare: function() {
      return browser.getProcessedConfig().then(data => {
          console.log(data.capabilities.chromeOptions.mobileEmulation); //to print out all options
           console.log(data.capabilities.chromeOptions.mobileEmulation.deviceName); //to print out device name
      });
  }

@IgorSasovets it worked. Can you please tell me that how I can access the value outside the function...
I tried assigning it to a global variable defined in the config but didnt worked and cannot access its value outside the function.

@kat0072, please take a look at get-config-capabilities for requested example.

thanks, buddy got it.

Above mentioned works fine if my config is in .JS but if I create config file in TS format. it doesn't work.

Was this page helpful?
0 / 5 - 0 ratings