Alex Cap
Alex Cap

Reputation: 113

Protractor parallel running leads tests to fail

I'm using protractor for automation testing, at this time all tests work properly. But if I set test running parallel

add to config file:

shardTestFiles: true,
maxInstances: 4,

tests will start randomly fail throwing 'no element found' and/or 'failed expectation' exceptions.

Could someone suggest what can be cause of this problem or how to fix it?

Could be a cause that test fails at the moment when start running new browser instance and Protractor focusing on it? (At this moment i have about 20 spec files and each spec file running starts new browser instance)

environment:

Windows 7 x64
Protractor v2.1.0
Browser Chrome v46

Upvotes: 3

Views: 789

Answers (1)

Alex Cap
Alex Cap

Reputation: 113

to solve my issue I've created a wrapper of elementFinder and ElementArrayFinder objects with overridden methods and some additional waiting for visibility and/or for presence.

Example for elementFinder.getText() and elementFinder.click()

function ElementFinderWrapper() {
    var conditions = protractor.ExpectedConditions;

    /**
    * Returns a wrapper for ElementFinder element.
    * @param {webdriver.Locator} locator
    */
    this.get = function(locator){
        return new Control(element(locator));
    };

    /**
    * Creates a wrapper for ElementFinder element.
    * @param {ElementFinder} element_finder
    * @constructor
    */
    function Control(element_finder) {

        /**
        * Returns the visible innerText of this element.
        * @returns {!webdriver.promise.Promise.<string>}
        */
        this.getText = function () {
            return browser.wait(conditions.presenceOf(element_finder), 3000);
               .then(function () {
                   return browser.wait(conditions.visibilityOf(element_finder), 3000);
               })
               .then(function () {
                   return element_finder.getText();
               });
        };

        /**
        * Clicks on visible element.
        * @returns {!webdriver.promise.Promise.<void>}
        */
        this.click = function () {
            return browser.wait(conditions.presenceOf(element_finder), 3000);
               .then(function () {
                   return browser.wait(conditions.visibilityOf(element_finder), 3000);
               })
               .then(function () {
                   return element_finder.click();
               });
        };
    };
};

then use something like:

contol = ElementFinderWrapper.get(by.xpath('some path'));
control.getText();
control.click();

Upvotes: 1

Related Questions