Browser.wait 没有等待给定的毫秒数

Browser.wait doesn't wait by given milliseconds

所以我在 browser.wait 使用量角器、mocha 和 chai 时遇到问题。基本上我创建的一个简单脚本基本上是:

var EC = protractor.ExpectedConditions;
describe('Personal information', function () {
    var EC = protractor.ExpectedConditions;

    this.timeout(5000);

    it('test', function (done) {

        browser.driver
            .then(() => browser.wait(EC.presenceOf(element(by.xpath("//root"), 1000, "timed out TEST")
            .then(() => done());
    });

如您所见,我添加了一个函数 this.timeout(5000);,这意味着 5 秒后它会抛出错误,但是我在 browser.wait 中输入了 1000 毫秒后的超时,这意味着 1 秒后它应该在 1 秒后抛出超时错误。

但是它似乎并没有这样做,而是等待 5 秒并抛出 Error: Timeout of 5000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.,我很困惑我在这里做错了什么。所以我来了!

我怎样才能让它等待我给的金额?

GUY 更新 2:

describe('Personal information', function () {
    var EC = protractor.ExpectedConditions;

    this.timeout(0);

    browser.wait(EC.presenceOf(element(by.xpath("//root"))), 1000, "timed out TEST");
    });

我不完全确定 this.timeout() 是如何工作的,但我怀疑它的行为类似于隐式等待。 element(by.xpath("//root")) 尝试在定义的 5 秒内定位元素,仅在失败后 browser.wait 检查是否接受了 1 秒超时。

您可以在使用browser.wait之前设置this.timeout(0);