10
votes

The Story:

We have a rather huge end-to-end protractor test codebase. We have two configs - one is "local" - to run the tests in Chrome and Firefox using directConnect, and the other one is "remote" - to run tests on a remote selenium server - BrowserStack in our case.

Our "local" config is configured to run some tests in Chrome and some in Firefox - because we really cannot run some tests in Chrome - for instance, keyboard shortcuts don't work in Chrome+Mac. Running the tests that require using keyboard shortcuts in Firefox is a workaround until the linked chromedriver issue is resolved.

Here is the relevant part of the configuration:

var firefox_only_specs = [
    "../specs/some_spec1.js",
    "../specs/some_spec2.js",
    "../specs/some_spec3.js"
];

exports.config = {
    directConnect: true,

    multiCapabilities: [
        {
            browserName: "chrome",
            chromeOptions: {
                args: ["incognito", "disable-extensions", "start-maximized"]
            },
            specs: [
                "../specs/**/*.spec.js",
                "../specs/**/**/*.spec.js",
                "../specs/**/**/**/*.spec.js"
            ],
            exclude: firefox_only_specs
        },
        {
            browserName: "firefox",
            specs: firefox_only_specs
        }
    ],

    // ...
};

The problem:

Now, the problem is that, if I'm debugging a single test, or want to run a single test - I'm marking it is as focused (via fdescribe/fit) - but protractor starts two driver sessions - one for Chrome and the other one for Firefox, using both configured capabilities:

Running "protractor:local" (protractor) task
[launcher] Running 2 instances of WebDriver

...
------------------------------------
[chrome #1] PID: 2329
[chrome #1] Using ChromeDriver directly...
[chrome #1] Spec started

...

------------------------------------
[firefox #2] PID: 2330
[firefox #2] Using FirefoxDriver directly...
[firefox #2] Spec started

...

The question:

Is there a way to tell protractor to use the only one capability that has a focused spec configured?


Using currently latest protractor 3.0.0.

Hope the question is clear. Let me know if you need any additional information.

2
Don't have an answer to your question but to me it seems...you can't. The config is read before tests start getting executed so all the browsers in multiCapabilities will get started. A painful workaround would be to change the "runner" or executing script to have a different config or to dynamically setup the config based on command line parameters. ie. It's not using the built-in feature of the tools/frameworks but you can then execute with a diff config which doesn't have Chrome setup. - aneroid
@aneroid thank you for the point. Yeah, it's not that clear how to approach the problem..may be we would have to have a separate custom command-line parameter that would, depending on the value, run one of the capabilities or all of them.. - alecxe
Keep in mind that you can dynamically generate capabilities with a getMultiCapabilities function in your protractor.conf.js if needed - martin770
Got the same issue. Finaly came to a way of overwriting capabilities in case I have any focus tests enabled (with a bit more complex logic choosing a browser, as most of my tests are located in the proper folder, named after a browser to run). - Stan E
@aneroid I agree, looks like a timing problem. When jasmine actually runs, capabilities are already formed. Cannot find a single point where I can have everything I need and don't run specific capabilities not having focused tests and run only capabilities that have focused tests among the specs. Thanks, good point. - alecxe

2 Answers

1
votes

I wonder if you can do something to wrap the it statements like:

onPrepare: function() {
    browser.getCapabilities().then(function(caps) {
        global.browserName = caps.caps_.browserName;
    });

    global.firefoxOnly = function(name, testFunction) {
        if (browserName === 'firefox') {
            return it(name, testFunction);
        } else {
            return xit(name, testFunction).pend('firefox only');
        }
    };
}

Then when you write a test, instead of it use something like:

describe('when I do something', function() {
    firefoxOnly('it should do the right thing', function() {
        doSomething();
        expect(thing).toBe(right);
    )};
});

I have no idea if this actually works, just throwing it out there. In fact, when I get back to my testing computer and try it out, I would be interested in adding a function like wip to use instead of xit to automatically pend my ATDD tests!

0
votes

Is there a way to tell protractor to use the only one capability that has a focused spec configured?

According to the relevant github issue, it is not possible.