Jasmine 如何从量角器配置中的多容量定义中获取deviceName值

Jasmine 如何从量角器配置中的多容量定义中获取deviceName值,jasmine,protractor,Jasmine,Protractor,这可能是你们重复的问题,但实际上我还没有得到答案。 这是我在量角器配置文件中的多功能定义。 我想访问deviceName参数值。我怎么做 exports.config = { directConnect:true, multiCapabilities: [ { browserName: 'chrome', 'chromeOptions': { 'mobileEmulation': { 'deviceName': 'iPad'

这可能是你们重复的问题,但实际上我还没有得到答案。 这是我在量角器配置文件中的多功能定义。 我想访问deviceName参数值。我怎么做

exports.config = {
directConnect:true,
multiCapabilities: [
{
browserName: 'chrome',
        'chromeOptions': {
            'mobileEmulation': {
                'deviceName': 'iPad'
            }
        }
    }
],
在onPrepare下尝试,但未提供多功能值

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

您可以在
onPrepare
块中创建
console.log(process.env)
,然后找到所需内容。

不确定是否使用
getCapabilities()
解决此问题,但您应该能够使用解决此问题

getProcessedConfig
将返回整个配置设置的承诺(以及一些量角器默认值)。以你为例:

browser.getProcessedConfig().then((c) => {
    console.log(c.capabilities.chromeOptions.mobileEmulation.deviceName);
});

尝试
getProcessedConfig()

或者只是普通的老笨蛋:

let device_name = 'iPad' 
exports.config = {
   directConnect: true,
   multiCapabilities: [{
   browserName: 'chrome',
   chromeOptions: {
      mobileEmulation: {
           deviceName: device_name
        }
      }
   }],
   onPrepare: function () {
       console.log('Device name will be', device_name);
   }

获取设备名称按照Gunderson的建议工作,但现在我遇到了不同的问题,在onPrepare中,我无法访问代码块之外的变量值

onPrepare: function () {
    browser.getProcessedConfig().then(function (c) {
        return global.deviceName 
c.capabilities.chromeOptions.mobileEmulation.deviceName;
    }).then(function () {
            console.log("Device Name is:" + global.deviceName);
            customDevice = global.deviceName;
        }
    );
};
customDevice未打印任何值…,该值定义为配置文件顶部的全局变量


我知道在访问它时可能犯了愚蠢的错误…:)

他会发现环境变量中的
deviceName
对我来说就像是他在模拟一个不同的设备,而不是他正在运行的设备。我在Chrome浏览器上模拟iPhone 7的屏幕,这就是为什么我需要多种设备配置,比如Galaxy S5、iPad等。。。