Saturday, 13 May 2017

Webdriver IO run all commands sequentially

I cannot understand how to correctly handle execution flow in Webdriver.io.

Here is my function

checkOrderStatus(info, callback) {
    let browserClient = this._webDriverClient;
    // Make order flow
    browserClient.init()
        .url("http://localhost")
        .selectByVisibleText("products", "MacBook")
        .setValue("input[name='first_name']", info.name)
        .setValue("input[name='address']", info.address)
        .click("button[name='confirm']");
    let errorElements = browserClient.element('.error');
    if (errorElements.length > 0) {
        callback.onError("Error");
    }
    else {
        let successElements = browserClient.element(".success");
        if (successElements.length > 0) {
            callback.onSuccess("Success");
        }
    }
    browserClient.end();
}

However browserClient.element returns status : pending. I need something like promises chain that a whole chain won't finish until all then statements are executed if there were no exception.

The provided example is really simple, there could be more actions even after finding elements.

Could someone suggest how to handle this chain sequentially like a promise chain.

I would be grateful for any help.



via e109848

No comments:

Post a Comment