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?

Regent
  • 5,142
  • 3
  • 21
  • 35
  • possible duplicate of [Intern Leadfoot WaitForAddedById functionality?](http://stackoverflow.com/questions/25630545/intern-leadfoot-waitforaddedbyid-functionality) – C Snover Sep 11 '14 at 20:47

2 Answers2

2

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))
Diggy.
  • 6,744
  • 3
  • 19
  • 38
kgstew
  • 472
  • 4
  • 12
  • Does the find method will only keep looking for the element for time defined in timeout if the element wasn't found, otherwise the method will return earlier? In my test if a set a findTimeout, every find call will take findTimeout to return, no matter if element was found earlier. Is it the same to you? Or am I doing something wrong? – Hugo Oshiro Sep 27 '16 at 21:34
0

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

denov
  • 11,180
  • 2
  • 27
  • 43