0
votes

I have angular 5 Application developing, and writing test cases in Jasmin using the protractor. my test scenario is that I want to get all page links("a href") and open one by one, for that I am writing below test case, it is opening 5-6 links, but after opening(executing ) some links it is giving below error , all links not opening ,loop is terminating after some time

Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.

describe('home page test ', function() {
    let page: AppPage;
    let linksArray:string[]=[];

    beforeEach(() => {
        page = new AppPage();
    });

    it('home  page links test  ', () => {
        page.navigateTo();
        //find all links
        let linkCount = element.all(by.tagName('a'));
        //here you click each of the links:
        linkCount.each(function(elem,index){
            elem.getAttribute('href').then(function(link){
                if(link!=null && link !='http://localhost:4200/showcase')
                    linksArray.push(link);
            })
        });
    });


    it('all links navigate test  ', () => {
        linksArray.forEach(function (plink) {
            console.log('going to get link'+plink);
            browser.get(plink);
            browser.sleep(5000);
            });
    });

});
1
Please share your conf.js file, it looks like you should increase defaultTimeoutInterval there. - Sanja Paskova
Thats interesting.. i get the same error since today in a project since today. - Bernhard

1 Answers

0
votes

This error you will get if your test case is not completed in the time specified in a conf file. If you are sure your test case gonna take some more time then you can specify the timeout for this test case explicitly by below way:- Note- This will only apply for the specific test case.

describe('home page test ', function() {
    let page: AppPage;
    let linksArray:string[]=[];

    beforeEach(() => {
        page = new AppPage();
    });

    it('home  page links test  ', () => {
        page.navigateTo();
        //find all links
        let linkCount = element.all(by.tagName('a'));
        //here you click each of the links:
        linkCount.each(function(elem,index){
            elem.getAttribute('href').then(function(link){
                if(link!=null && link !='http://localhost:4200/showcase')
                    linksArray.push(link);
            })
        });
    }, 60000);


    it('all links navigate test  ', () => {
        linksArray.forEach(function (plink) {
            console.log('going to get link'+plink);
            browser.get(plink);
            browser.sleep(5000);
            });
    }, 60000);

});

or you can specify once for all test cases in a config file. the code you need to add to the config file is

// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 100000,
    isVerbose: true
 }

Let me know if issue is still there