Test all links for validity on a page using Protractor

牧云@^-^@ 提交于 2019-12-06 05:29:10

Instead of going back and forth, which often leads to stale element reference errors cause of the DOM change/reload, I would collect all the links into an array using map() and then process them one by one. This would also have a positive impact on the performance of the test:

$$('a').map(function(link) {
    return link.getAttribute("href").then(function (href) {
        return href.replace(/https\:\/\/app\.perflectie\.nl\//g, localhost);
    });
}).then(function(links) {
    links.forEach(function(link) {
        browser.get(link);
        expect(browser.getCurrentUrl()).not.toContain('/Error/');
    });
});

Note that there is also no need to resolve the .getCurrentUrl() explicitly since expect() would do that implicitly for us before making the expectation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!