thurston sandberg
thurston sandberg

Reputation: 33

How do you wait for element to load in functional tests with Intern 2?

I am trying to make an integration test with Intern 2, meaning I will need to navigate web pages or wait for ajax to test certain things. This means waiting for elements to appear, which Intern 1 supported.

I have looked at pollUntil in leadfoot, which almost does what I want, but will cause a chain of .thens for every click I need to make (example). Is there a better way of doing this?

Upvotes: 2

Views: 1365

Answers (2)

kgstew
kgstew

Reputation: 481

There is a method called sleep() from Leadfoot in Intern 2 that does the same thing as wait() in Intern 1.

Leadfoot also provides a setFindTimeout() method which should set the time that intern continues to look for a element on the page if it not found when a find() method is first called.

I ended up creating a function specifically for waiting for elements to appear on the page. And then using this inside of a pollUntil() to explicitly wait for an element to appear or disappear on the page.

element_visible_by_query_selector: function(query) {
        return function(query) {
            elem = document.querySelector(query);
            if (!elem) { return null; }
            return (elem.offsetWidth > 0 && elem.offsetHeight > 0) ? elem : null;
        }  
    },

.then(pollUntil(util.element_visible_by_query_selector(), ['<element>'], 22000))

Upvotes: 2

denov
denov

Reputation: 12696

the amount of time findBy* will wait is controlled by the set find timeout value - https://theintern.github.io/leadfoot/Command.html#setFindTimeout

Upvotes: 0

Related Questions