Examples:
1) Wait until element will shown:
const until = selenium.until;
driver.wait(until.elementLocated(locators.detailsGenresDropDown), 5000);
2) implicitlyWait() in javascript selenium bindings accepts a single argument - a timeout in milliseconds:
driver.manage().timeouts().implicitlyWait(20000);
3) page is loaded:
java: driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
js: driver.manage().timeouts().pageLoadTimeout(10);
4) The code above makes browser wait for 5 seconds after clicking the button (+1).
driver.findElement(webdriver.By.name('btnCalculate')).click().then(function() {
driver.sleep(5000);
});
If using webdriverJs (node.js),
5) What's the equivalent of Java's Thread.sleep() in JavaScript? (+1)
The simple answer is that there is no such function.
The closest thing you have is:
Note that you especially don't want to busy-wait (e.g. in a
spin loop), since your browser is almost certainly executing your
JavaScript in a single-threaded environment.Here are a couple of other SO questions that deal with threads in JavaScript: And this question may also be helpful: |
6) Just sleep for several seconds:
// Page has been loaded, now go to sleep for a few seconds. driver.sleep(3000);
Assertion
Examples:
1) client.getTitle().then(function(title) {
assert.ok(title.indexOf('test — Яндекс: нашлось') > -1, 'Ничего не нашлось :(');
});
Links:
WebDriver: Advanced Usage - Explicit and Implicit Waits
Документация по Selenium.
Документация по WebDriver.js;
Черновик спецификации WebDriver API;
Webdriver selenium js docs
Комментариев нет:
Отправить комментарий