2

How can I use explicit waits using intern's leadfoot API for functional testing in intern?

There are multiple scenarios where I want to explicitly poll until a condition is met. For example, I want to wait until two or more elements exist in the DOM. Using findAllByCssSelector locks the execution for the whole implicit wait time instead of returning immediately after the condition is true.

All I can see that will help me is the pollUntil helper function, but it looks like this does not have access to any of the module dependencies defined in the test module.

How can I use something like jQuery within pollUntil?

Michael
  • 5,994
  • 7
  • 44
  • 56

1 Answers1

2

findAllByCssSelector only waits for the implicit wait if no elements are found. If elements exist, the method finishes immediately with whatever it finds, so it's not ideal if you need to wait for a specific number of elements to appear.

pollUntil is the way to go for conditional waits. You are correct, though, that it doesn't have access to your module dependencies. Your dependencies are loaded in the context of Intern's test runner, while the pollUntil condition is going to run in the context of the browser. There are a couple ways to get the code you need into the browser. If you control the test page, you could just modify it to load whatever modules you need before the tests run. If you can't modify the test page, you could use an executeAsync call after loading the page in your test to inject whatever modules you need into the page context.

jason0x43
  • 3,363
  • 1
  • 16
  • 15
  • Are you 100% sure on the `findAllByCssSelector`? The equivalent selenium webdriver.js function implicitly waits. – Michael Sep 05 '14 at 03:24
  • see: https://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#findElements(org.openqa.selenium.By) – Michael Sep 05 '14 at 03:35
  • Actually upon re-reading the link, it seems like the behaviour is as you specified...although I don't know what "This method is affected by the 'implicit wait' times in force at the time of execution". – Michael Sep 05 '14 at 03:43
  • I believe the documentation is just saying that `findAll`, like `find`, will wait for the implicit wait time if no elements are found. Also like `find`, when an element _is_ found (at least 1 element), it returns immediately. – jason0x43 Sep 05 '14 at 11:47