最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Configuring multiple capabilities with promises - Stack Overflow

programmeradmin8浏览0评论

This is a follow-up to the Set firefox profile with protractor topic.

According to the setFirefoxProfile howto, it is possible to set a firefox profile with a special "helper" js code which uses firefox-profile and q libraries to make an encoded firefox profile on the fly.

This worked for me until I've tried to use multiple browsers and configuring multiCapabilities:

exports.config = {
    seleniumAddress: 'http://localhost:4444/wd/hub',

    multiCapabilities: [
        {
            browserName: 'chrome',
            specs: [
                'footer.disabledCookies.spec.js'
            ],
            chromeOptions: {
                prefs: {
                    'profile.default_content_settings.cookies': 2
                }
            }
        },

        ...
        // other capabilities here
        ...

        helper.getFirefoxProfile()    
     },

     ...
}

With this setup I'm getting an error (full traceback here):

Spec patterns did not match any files.

As I understand, this means that the setup with firefox profile is missing specs key. In other words, it cannot find any tests to run.

I've tried to include specs into the capabilities dictionary inside the helper itself, but the error persists.

How to fix the error and set firefox profile if using multiCapabilities?


As a workaround, I've created a separate protractor configuration file with only firefox configured (using capabilities) and set grunt to run protractor twice - one for this "firefox with a profile" config and the other one for all other browsers.

This is a follow-up to the Set firefox profile with protractor topic.

According to the setFirefoxProfile howto, it is possible to set a firefox profile with a special "helper" js code which uses firefox-profile and q libraries to make an encoded firefox profile on the fly.

This worked for me until I've tried to use multiple browsers and configuring multiCapabilities:

exports.config = {
    seleniumAddress: 'http://localhost:4444/wd/hub',

    multiCapabilities: [
        {
            browserName: 'chrome',
            specs: [
                'footer.disabledCookies.spec.js'
            ],
            chromeOptions: {
                prefs: {
                    'profile.default_content_settings.cookies': 2
                }
            }
        },

        ...
        // other capabilities here
        ...

        helper.getFirefoxProfile()    
     },

     ...
}

With this setup I'm getting an error (full traceback here):

Spec patterns did not match any files.

As I understand, this means that the setup with firefox profile is missing specs key. In other words, it cannot find any tests to run.

I've tried to include specs into the capabilities dictionary inside the helper itself, but the error persists.

How to fix the error and set firefox profile if using multiCapabilities?


As a workaround, I've created a separate protractor configuration file with only firefox configured (using capabilities) and set grunt to run protractor twice - one for this "firefox with a profile" config and the other one for all other browsers.

Share edited May 23, 2017 at 11:58 CommunityBot 11 silver badge asked Dec 3, 2014 at 5:15 alecxealecxe 475k127 gold badges1.1k silver badges1.2k bronze badges 2
  • 2 I opened an issue github./angular/protractor/issues/1594. I think it is what you want. Please ment on this issue and use it to track updates. – hankduan Commented Dec 4, 2014 at 19:31
  • 1 @hankduan thank you very much for elaborating this to a feature request. Please make an answer (with some technical details you've provided in the github issue) and I'll accept it. In case the feature would be implemented, we'll update the answer with appropriate instructions. – alecxe Commented Dec 11, 2014 at 15:10
Add a ment  | 

2 Answers 2

Reset to default 6 +100

Right now, protractor can only accept promise as capabilities if we are NOT using multicapabilities. The reason for this is because multiCapabilities runs each task in a new process, so the promise (function) cannot be passed (single capabilities work because we're not forking).

Alternatively we could resolve capabilities in the launcher, before passing the resolved capabilities into the new processes; however, this will break the ability to set up proxies (https://github./angular/protractor/pull/1040), which relies on capability promises to be resolved after driverProvider setup.

I can't think of an easy way of doing this (without large refactoring), but it is definitely doable. I created an issue for Protractor (https://github./angular/protractor/issues/1594). Please follow that and/or ment on it if this is something you need or you have other ideas to implement it.

For now you would need to use the workaround you mentioned in your original question.

UPDATE

https://github./angular/protractor/pull/1629 supports this. Starting in protractor 1.6 (or if you sync to master) you can pass in a function to config.getMultiCapabilities like onPrepare and onCleanup. This function can return a promise to multiCapabilties (i.e. array of capabilities).

See https://github./angular/protractor/blob/master/spec/getCapabilitiesConf.js for an example.

Following the pull request sent by @hankduan, here is how have I used getMultiCapabilities() to bine different capabilities where one of them is a promise (needed for firefox-profile to be set):

"use strict";

var FirefoxProfile = require("firefox-profile");
var q = require("q");

exports.config = {
    seleniumAddress: "http://127.0.0.1:4444/wd/hub",

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

        var multiCapabilities = [
            {
                browserName: "chrome",
                specs: [
                    "footer.disabledCookies.spec.js"
                ],
                chromeOptions: {
                    prefs: {
                        "profile.default_content_settings.cookies": 2
                    }
                }
            },
            {
                browserName: "chrome",
                specs: [
                    "*.spec.js"
                ],
                exclude: [
                    "footer.disabledCookies.spec.js",
                    "footer.disabledJavascript.spec.js",
                    "footer.disabledFlash.spec.js"
                ]
            },
            {
                browserName: "chrome",
                specs: [
                    "footer.disabledFlash.spec.js"
                ],
                chromeOptions: {
                    args: [
                        "--disable-internal-flash",
                        "--disable-bundled-ppapi-flash",
                        "--disable-plugins-discovery"
                    ]
                }
            }
        ];

        // 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;
    },

    ...

};

Hope this would help somebody in the future.

发布评论

评论列表(0)

  1. 暂无评论