yahoo / protractor-retry

Use protractor features to automatically re-run failed tests with a specific configurable number of attempts.
MIT License
28 stars 32 forks source link

cannot find module "../lib/retry" #68

Open FreddieXue opened 4 years ago

FreddieXue commented 4 years ago

Hi

I followed the instructions and tried to install protractor-retry. I intergrated the codes regarding retry but it doesnt work.

Here is my config, (config.capabilities is in another file)

var retry = require('../lib/retry');

export const config: Config = { framework: 'jasmine', specs: applicationConfig[application].specs, jasmineNodeOpts: { defaultTimeoutInterval: 3000000 }, allScriptsTimeout: 1200000, directConnect: !seleniumAddress, seleniumAddress: seleniumAddress, chromeDriver: !seleniumAddress ? require('chromedriver').path : null,

SELENIUM_PROMISE_MANAGER: false,
onCleanUp: async (results) => {
    await retry.onCleanUp(results);
},
onPrepare: async () => {
    await retry.onPrepare();
    require('jasmine-expect');
    browser.ignoreSynchronization = true;
    jasmine.getEnv().addReporter(htmlReporter.getJasmine2Reporter());
    jasmine.getEnv().addReporter(junitReporter);
    jasmine.getEnv().addReporter(specReporter);

    await browser
        .manage()
        .window()
        .setSize(windowSizeX, windowSizeY);
    browser.ignoreSynchronization = false;

    await browser.waitForAngularEnabled(false);

    const loginPage = new LoginPage();
    const header = new Header();

    await browser.get(applicationUrl, 10000);

    //login
    var rd = Math.random()*10000;
    await browser.sleep(rd);
    if (applicationConfig[application].isGateKeeperProtected) {
        await loginPage.login(testUserEmail, testUserPassword);
        if (!(await header.isLoggedIn())) {
            log.error('Not logged in!');
        }
    }

    //await browser.waitForAngularEnabled(true);

    config.baseUrl = applicationUrl + '/';
    browser.baseUrl = applicationUrl;
    log.info(application.toUpperCase() + ' Url: ' + browser.baseUrl);
    /*
    add custom locators 'TestID'
    */
    by.addLocator('testid', function (value, parentElement) {
        parentElement = parentElement || document;
        var nodes = parentElement.querySelectorAll('[testid]');
        return Array.prototype.filter.call(nodes, function (node) {
            return (node.getAttribute('testid') === value);
        });
    });

    by.addLocator('formcontrolname', function (value, parentElement) {
        parentElement = parentElement || document;
        var nodes = parentElement.querySelectorAll('[formcontrolname]');
        return Array.prototype.filter.call(nodes, function (node) {
            return (node.getAttribute('formcontrolname') === value);
        });
    });

    by.addLocator('value', function (xvalue, parentElement) {
        parentElement = parentElement || document;
        var nodes = parentElement.querySelectorAll('[value]');
        return Array.prototype.filter.call(nodes, function (node) {
            return (node.getAttribute('value') === xvalue);
        });
    });

    by.addLocator('formgroupname', function (value, parentElement) {
        parentElement = parentElement || document;
        var nodes = parentElement.querySelectorAll('[formgroupname]');
        return Array.prototype.filter.call(nodes, function (node) {
            return (node.getAttribute('formgroupname') === value);
        });
    });

    by.addLocator('type', function (value, parentElement) {
        parentElement = parentElement || document;
        var nodes = parentElement.querySelectorAll('[type]');
        return Array.prototype.filter.call(nodes, function (node) {
            return (node.getAttribute('type') === value);
        });
    });

    by.addLocator('stationtype', function (value, parentElement) {
        parentElement = parentElement || document;
        var nodes = parentElement.querySelectorAll('[stationtype]');
        return Array.prototype.filter.call(nodes, function (node) {
            return (node.getAttribute('stationtype') === value);
        });
    });

    by.addLocator('routerlink', function (value, parentElement) {
        parentElement = parentElement || document;
        var nodes = parentElement.querySelectorAll('[routerlink]');
        return Array.prototype.filter.call(nodes, function (node) {
            return (node.getAttribute('routerlink') === value);
        });
    });

    by.addLocator('title', function (value, parentElement) {
        parentElement = parentElement || document;
        var nodes = parentElement.querySelectorAll('[title]');
        return Array.prototype.filter.call(nodes, function (node) {
            return (node.getAttribute('title') === value);
        });
    });

    by.addLocator('aria-label', function (value, parentElement) {
        parentElement = parentElement || document;
        var nodes = parentElement.querySelectorAll('[aria-label]');
        return Array.prototype.filter.call(nodes, function (node) {
            return (node.getAttribute('aria-label') === value);
        });
    });
},
afterLaunch : async () => {
    return await retry.afterLaunch(2); // number of retries ( default is 2 )
}

};

anilreddy commented 4 years ago

@FreddieXue

// remove this below line
var retry = require('../lib/retry'); 
// and add this instead
var retry = require('protractor-retry').retry;