处理JavaScript Slice函数中的超时

时间:2017-08-24 22:53:56

标签: javascript protractor scheduling

我有一个像这样调用的递归函数:

return click(myArray.slice(1));

myArray包含URL对象,其中包含有关如何处理它们的一些信息。

这是整个函数,作为Protractor测试套件的一部分:

.then(function click(myArray) {
    var tryItButton, tosCheckboxElement, tosContinueButton;

    if (labServices.length < 1) {
        return;
    }

    tryItButton = ...
    tosCheckboxElement = ...
    tosContinueButton = ...

    var EC = protractor.ExpectedConditions;
    var tryItButtonClickable = EC.elementToBeClickable(tryItButton);
    var tryItButtonVisible = EC.visibilityOf(tryItButton);

    return browser.wait(EC.and(tryItButtonClickable, tryItButtonVisible), getWaitTime())
        .then(function() {
            var protocol = url.parse(myArray[0].url).protocol;
            if (protocol === null) {
                throw new Error('expected ' + protocol + ' not to be null');
            }
        })
        .then(function() {
            return tryItButton.click();
        })
        .then(function() {
            return browser.wait(automationcore.ExpectedConditions.responseCompleted(proxy, myArray[0].url));
        })
        .then(function() {
            return browser.get(browser.baseUrl);
        })
        .then(function() {
            return element(tosCheckboxElement).isPresent();
        })
        .then(function(tosCheckboxElementPresent) {
            if (tosCheckboxElementPresent) {
                return browser.wait(EC.elementToBeClickable(element(tosCheckboxElement)), getWaitTime())
                    .then(function() {
                        element(tosCheckboxElement).click();
                        return element(tosContinueButton).isPresent();
                    })
            } else {
                return click(myArray.slice(1));
            }
        })
        .then(function(tosContinueButtonPresent) {
            if(tosContinueButtonPresent) {
                return browser.wait(EC.elementToBeClickable(element(tosContinueButton)), getWaitTime())
                    .then(function() {
                        element(tosContinueButton).click();
                        return browser.get(browser.baseUrl);
                    })
            }
        });
}).catch(fail).then(done);

结果是间歇性的,有时候,函数被调用,有时,我在 x ms 之后得到超时(例如,在我上次运行时,它是5548ms)。 slice()通常会超时吗?如果是这样,有没有一种处理这种行为的好方法?换句话说,这个测试失败是因为函数与我的套件无关,而是JS函数调用。

由于

0 个答案:

没有答案