vendredi 9 mars 2018

webdriver.io custom commands (addCommand)

My goal is to create a custom command in webdriver.io called waitForImage but when I move my code into addCommand() my test starts throwing errors. The idea is to wait for the image to be loaded, not just visible.

This works as expected:

browser.waitUntil(() => {
    return browser.element('img:nth-child(1)').getAttribute('naturalWidth') > 0;
});
browser.waitUntil(() => {
    return browser.element('img:nth-child(2)').getAttribute('naturalWidth') > 0;
});
browser.waitUntil(() => {
    return browser.element('img:nth-child(3)').getAttribute('naturalWidth') > 0;
});

However when I move it into a custom command the test starts throwing errors:

//top of file
browser.addCommand('waitForImage', (selector) => {
    browser.waitUntil(() => {
        return browser.element(selector).getAttribute('naturalWidth') > 0;
    });
});

//describe, it
browser.waitForImage('img:nth-child(1)');
browser.waitForImage('img:nth-child(2)');
browser.waitForImage('img:nth-child(3)');

Aucun commentaire:

Enregistrer un commentaire