Я знаю, что для тестирования конечных точек API запрос xhtml должен быть издевательствован, но пока я хочу протестировать его с помощью реального API.Тайм-аут внутри «beforeEach» не соблюдается по критерию
Что я хочу сделать:
открыть страницу, нажмите кнопку подключения, а затем ждать в течение максимум 10 секунд для определенного элемента innertext
изменить на «Connected».
Вот мой простой тестовый код:
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);
});
});
Если я запускаю этот тест, как это, я получаю эту ошибку:
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
Но если я раскомментировать эту строку, она работает:
// this.timeout(22222);
мне не очень нравится использовать тайм-ауты, но я не вижу другого пути вокруг него.