量角器中的多个Firefox配置文件 [英] Multiple firefox profiles in protractor

查看:136
本文介绍了量角器中的多个Firefox配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遵循使用承诺配置多个功能主题。



用例:我有两个单独的测试需要Firefox禁用 javascript禁用本地存储禁用。这意味着我需要两个firefox配置文件 javascript.enabled = false dom.storage.enabled = false 所需的功能/ preferences。set

我使用量角器1.6中引入的 getMultiCapabilities()直到现在,我只需要一个自定义的firefox配置文件,它的工作,这里是配置:
$ b $ $ pre $ getMultiCapabilities:function(){
var deferred = q.defer();

var multiCapabilities = [
{
browserName:chrome,
specs:[
* .spec.js
] ,
exclude:[
footer.disabledJavascript.spec.js
]
}
];

//等待服务器准备就绪或异步获取能力。
setTimeout(function(){
var firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference(javascript.enabled,false);
firefoxProfile.encoded(function(encodedProfile ){
var capabilities = {
browserName:firefox,
firefox_profile:encodedProfile,
specs:[
footer.disabledJavascript。 spec.js

};
multiCapabilities.push(capabilities);
deferred.resolve(multiCapabilities);
});
}, 1000);

return deferred.promise;
},

问题:现在我需要第二个firefox配置文件实例 dom.storage.enabled = false ,但我坚持如何解决 deferred 中这种情况下,因为现在有两个 encoded()调用和两个添加到multiCapabilities的功能。

问题:如何使用 getMultiCapabilities





$ b来配置多个firefox配置文件$ b

我做它的唯一方法是将一个配置文件嵌套到另一个配置文件中,并在最深层次调用 resolve()(如果有两个配置文件, - 但是这个解决方案并没有真正缩放):

$ $ $ $ $ $ $ $ $ $ $ $ $ $ var multiCapabilities =
{
browserName: chrome,
specs:[
* .spec.js

exclude:[
footer.disabledJavascript.spec.js,
disabledLocalStorage.spec.js
]
}
];

//等待服务器准备就绪或异步获取能力。
setTimeout(function(){
//禁用javascript的配置文件
var firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference(javascript.enabled,false);
firefoxProfile.encoded(function(encodedProfile){
var capabilities = {
browserName:firefox,
directConnect:true,
firefox_profile:encodedProfile,
specs:[
footer.disabledJavascript.spec.js
]
};
multiCapabilities.push(功能);

// profile禁用本地存储
var newFirefoxProfile = new FirefoxProfile();
newFirefoxProfile.setPreference(dom.storage.enabled,false);
newFirefoxProfile.encoded(function(newEncodedProfile){
var newCapabilities = {
browserNa me:firefox,
directConnect:true,
firefox_profile:newEncodedProfile,
specs:[
disabledLocalStorage.spec.js
]
} ;
multiCapabilities.push(newCapabilities);
deferred.resolve(multiCapabilities);
});
});
},1000);

return deferred.promise;
},


解决方案

您可以使用q。所有这一切。基本上你想要做这样的事情:

pre $ return $ q $ all $ ,
...
]);

具体如何获得能力承诺取决于您。
这里有一个通用的方法:
$ b $ $ $ $ $ $ $ $ $ $变量$延迟= $变量makeFirefoxProfile =函数(偏好地图,能力地图) q.defer();
var firefoxProfile = new FirefoxProfile();
// TODO:迭代preferenceMap并为每个
设置首选项firefoxProfile.encoded(function(encodedProfile){
var capabilities = {
browserName:firefox,
firefox_profile:encodedProfile,
};
// TODO:迭代capabilityMap并为每个
设置键/值deferred.resolve(capabilities);
}) ;
return deferred.promise;
};

getMultiCapabilities:function(){
return q.all([
makeFirefoxProfile({javascript.enabled:false},{specs:['spec1.js']})
makeFirefoxProfile({dom.storage.enabled:false},{specs:['spec2.js']})
]);





$ b如果你不想创建一个辅助函数并且想要生成能力承诺1功能,这取决于你。从本质上讲,我认为这里的关键是使用 q.all ,其他的依赖于你的功能对象的复杂程度以及你想要如何构造你的代码


Following Configuring multiple capabilities with promises topic.

Use case: I have two separate tests that require Firefox to be fired with javascript disabled and local storage disabled. Which means that I need two firefox profiles with javascript.enabled = false and dom.storage.enabled = false desired capabilities/preferences set.

I'm using getMultiCapabilities() that was introduced in protractor 1.6. Till this moment, I needed only one custom firefox profile and it worked, here is the configuration:

getMultiCapabilities: function() {
    var deferred = q.defer();

    var multiCapabilities = [
        {
            browserName: "chrome",
            specs: [
                "*.spec.js"
            ],
            exclude: [
                "footer.disabledJavascript.spec.js"
            ]
        }
    ];

    // Wait for a server to be ready or get capabilities asynchronously.
    setTimeout(function() {
        var firefoxProfile = new FirefoxProfile();
        firefoxProfile.setPreference("javascript.enabled", false);
        firefoxProfile.encoded(function (encodedProfile) {
            var capabilities = {
                "browserName": "firefox",
                "firefox_profile": encodedProfile,
                "specs": [
                    "footer.disabledJavascript.spec.js"
                ]
            };
            multiCapabilities.push(capabilities);
            deferred.resolve(multiCapabilities);
        });
    }, 1000);

    return deferred.promise;
},

Problem: Now I need the second firefox profile instance with dom.storage.enabled = false, but I'm stuck at how should I resolve the deferred in this case, since there are now two encoded() calls and two capabilities added to multiCapabilities.

Question: How can I configure multiple firefox profiles using getMultiCapabilities?


The only way I made it work is nesting one profile into another and calling resolve() at the deepest level (in case of two profiles it might be okay - but this solution doesn't really scale):

var multiCapabilities = [
        {
            browserName: "chrome",
            specs: [
                "*.spec.js"
            ],
            exclude: [
                "footer.disabledJavascript.spec.js",
                "disabledLocalStorage.spec.js"
            ]
        }
    ];

    // Wait for a server to be ready or get capabilities asynchronously.
    setTimeout(function() {
        // profile with disabled javascript
        var firefoxProfile = new FirefoxProfile();
        firefoxProfile.setPreference("javascript.enabled", false);
        firefoxProfile.encoded(function (encodedProfile) {
            var capabilities = {
                browserName: "firefox",
                directConnect: true,
                firefox_profile: encodedProfile,
                specs: [
                    "footer.disabledJavascript.spec.js"
                ]
            };
            multiCapabilities.push(capabilities);

            // profile with disabled local storage
            var newFirefoxProfile = new FirefoxProfile();
            newFirefoxProfile.setPreference("dom.storage.enabled", false);
            newFirefoxProfile.encoded(function (newEncodedProfile) {
                var newCapabilities = {
                    browserName: "firefox",
                    directConnect: true,
                    firefox_profile: newEncodedProfile,
                    specs: [
                        "disabledLocalStorage.spec.js"
                    ]
                };
                multiCapabilities.push(newCapabilities);
                deferred.resolve(multiCapabilities);
            });
        });
    }, 1000);

    return deferred.promise;
},

解决方案

You can use q.all to do this. Essentially you want to do something like this:

return q.all([
    capabilityPromise1,
    capabilityPromise2,
    ...
]);

Exactly how you get the capability promises is up to you. Here's one generic way:

var makeFirefoxProfile = function(preferenceMap, capabilityMap) {
    var deferred = q.defer();
    var firefoxProfile = new FirefoxProfile();
    // TODO: iterate over preferenceMap and set preference for each
    firefoxProfile.encoded(function (encodedProfile) {
        var capabilities = {
            "browserName": "firefox",
            "firefox_profile": encodedProfile,
        };
        // TODO: iterate over capabilityMap and set key/value for each
        deferred.resolve(capabilities);
    });
    return deferred.promise;
};

getMultiCapabilities: function() {
    return q.all([
        makeFirefoxProfile({javascript.enabled: false}, {specs: ['spec1.js']})
        makeFirefoxProfile({dom.storage.enabled: false}, {specs: ['spec2.js']})
    ]);
}

If you don't want to create a helper function and want to generate the capability promises in 1 function, that's up to you. Essentially, I think the key here is to use q.all, the rest really depends on how complex your capabilities objects are and how you want to structure your code

这篇关于量角器中的多个Firefox配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆