APIエンドポイントのテストでは、xhtmlリクエストを嘲笑すべきだが、今は実際のAPIでテストしたい。私が何をしたいか"beforeEach"内のタイムアウトがテストで尊重されていない
:
ページを開き、接続ボタンをクリックし、「接続」に変更するには、特定の要素のinnertext
のために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);
});
});
それがあるように私はこのテストを実行する場合、私はこのエラーを取得:
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
しかし、私は、この行のコメントを外した場合、それが動作します:
// this.timeout(22222);
タイムアウトを使用するのは本当に好きではありませんが、私はそれ以外の方法では表示されません。