Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/445.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript “内部超时”;“在每个之前”;不受考试的尊重_Javascript_Selenium_Selenium Webdriver_Automated Tests_Mocha.js - Fatal编程技术网

Javascript “内部超时”;“在每个之前”;不受考试的尊重

Javascript “内部超时”;“在每个之前”;不受考试的尊重,javascript,selenium,selenium-webdriver,automated-tests,mocha.js,Javascript,Selenium,Selenium Webdriver,Automated Tests,Mocha.js,我知道为了测试API端点,应该模拟xhtml请求,但现在我想用真正的API来测试它 我想做什么: 打开一个页面,单击“连接”按钮,然后等待最长10秒钟,以使某个元素的内部文本更改为“已连接” 下面是我的简单测试代码: const assert = require('assert'); const webdriver = require('selenium-webdriver'); const By = webdriver.By; const until = web

我知道为了测试API端点,应该模拟xhtml请求,但现在我想用真正的API来测试它

我想做什么:

打开一个页面,单击“连接”按钮,然后等待最长10秒钟,以使某个元素的
内部文本更改为“已连接”

下面是我的简单测试代码:

    const assert = require('assert');
    const webdriver = require('selenium-webdriver');
    const By = webdriver.By;
    const until = webdriver.until;
    const chrome = require('selenium-webdriver/chrome');
    const test = require('selenium-webdriver/testing');
    const mochaTimeOut = 25000;


    test.beforeEach(function() {
      this.timeout(mochaTimeOut);
      driver = new webdriver.Builder()
        .forBrowser('chrome')
        .setChromeOptions(options)
        .build();
      driver.get('http://127.0.0.1/dist/popup.html');
    });

    test.afterEach(function() {
      driver.quit();
    });

    test.describe('Connect functionality', function() {
      test.it('Try to connect', function(done) {
        // this.timeout(22222); // only works if I uncomment this line
        driver.findElement(By.id('connect')).click().then(function (el) {
            driver.findElement(By.id('state')).then(function (stateEl) {
              driver.wait(until.elementTextContains(stateEl, 'Connected'), 10000);
            })
          }).then(done);
      });
    });
如果按原样运行此测试,则会出现以下错误:

错误:超过2000毫秒的超时时间。对于异步测试和挂钩,确保调用“done()”;如果返回承诺,请确保它已解决

但如果我取消注释这一行,它会起作用:

// this.timeout(22222);

我真的不喜欢使用超时,但我看不到其他解决方法。

timeout
的调用是分层的。问题是您的
之前每个
都没有子项。您需要全局设置超时,或者可以在
测试中复制超时。请描述
调用:

test.describe('Connect functionality', function() {
  this.timeout(mochaTimeout);
这样,它将应用于
测试中的所有测试。描述