Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiCapabilities and jasmine focused tests

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.

like image 888
alecxe Avatar asked Dec 19 '15 01:12

alecxe


1 Answers

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!

like image 142
martin770 Avatar answered Nov 06 '22 03:11

martin770