代码之家  ›  专栏  ›  技术社区  ›  David J

mocha与selenium的错误:typeerror:wait条件必须是promise,如对象、函数或条件对象

  •  0
  • David J  · 技术社区  · 7 年前

    我刚接触过摩卡和硒,对快速应用程序进行测试。我有以下简单的代码,但我不知道出了什么问题。

    describe("authenticateWithGoogle", function() {
        it("return a valid access token for our tests", function() {
            return new Promise( function(resolve) {
    
               var driver = new Builder().forBrowser('chrome').build();
               driver.get('https://www.google.com');
    
               driver.wait("Google",5000).then( (quitDriver,handleFailure) => {
                   console.log("wait over");
                   assert.ok(true); 
               });
    
               resolve();
          }).then();
        });
    });
    

    我运行“mocha”时收到以下错误:

    TypeError: Wait condition must be a promise-like object, function, or a Condition object
    

    这发生在上面代码中的“driver.wait”行上。我真的不明白错误是什么意思。

    1 回复  |  直到 7 年前
        1
  •  1
  •   deerawan    7 年前

    我试过同样的SeleniumWebDriver4.0.0alpha.1,但效果很好。 基于它的例子,它使用 async await 所以我也用同样的方法。

    const {Builder, By, Key, until} = require('selenium-webdriver');
    const chai = require('chai');
    const assert = chai.assert;
    
    describe("authenticateWithGoogle", function() {
      it("return a valid access token for our tests", async function() {
        this.timeout(5000);
    
        let driver = await new Builder()
          .usingServer('http://localhost:4444/wd/hub')
          .forBrowser('chrome').build();
    
        try {
          await driver.get('http://www.google.com');
          await driver.wait(until.titleIs('Google'), 1000);
        } finally {
          assert.ok(true);
          await driver.quit();        
        }      
      });
    });
    

    我的设置:

    是的,用于测试 oauth 您可以为它创建集成/E2E测试。你已经走对了。

    希望它有帮助

    推荐文章