gpt4 book ai didi

javascript - Protractor/Jasmine2 - 在指定超时内未调用异步回调

转载 作者:数据小太阳 更新时间:2023-10-29 05:12:05 27 4
gpt4 key购买 nike

我在 selenium 网格上运行的 e2e 测试遇到了问题。有时测试失败是因为

Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.

试图以某种方式解决它,将 defaultTimeoutInterval 更改为 protracotr.conf.js 中的更高值,但结果等待时间更长,但错误是相同的。

exports.config = {
chromeOnly: true,
chromeDriver: '../node_modules/.bin/chromedriver',
framework: 'jasmine2',
capabilities: {
'browserName': 'chrome',
shardTestFiles: true,
maxInstances: 3
},
specs: ['../e2e/protractor/spec/*.js'],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
isVerbose: true,
includeStackTrace: true,
},

我的测试失败示例规范:

var LoginPage = require('../pages/login_page.js');
var UsersPage = require('../pages/users_page.js');
var WelcomePage = require('../pages/welcome_page.js');

describe('Test -> my test', function () {
var loginPage;
var EC = protractor.ExpectedConditions;
var waitTimeout = 30000;

function logIn() {
loginPage.setUser('user');
loginPage.setPassword('password');
loginPage.login();
}

var clickOn = function (element) {
browser.wait(EC.visibilityOf(element), waitTimeout).then(function () {
element.click();
});
};

beforeEach(function () {
browser.ignoreSynchronization = true;
loginPage = new LoginPage();
browser.wait(EC.presenceOf(loginPage.userLogin), waitTimeout);
logIn();
var welcomePage = new WelcomePage;
clickOn(welcomePage.usersButton);
});

afterEach(function () {
var welcomePage = new WelcomePage();
welcomePage.loginButton.click();
welcomePage.logoutButton.click();
});

it('verifies counter on active tab', function () {
var usersPage = new UsersPage();
browser.wait(EC.visibilityOf(usersPage.firstRow), waitTimeout);
usersPage.rowsCount.count().then(function (count) {
expect(usersPage.activeTab.getText()).toContain('Active' + ' (' + count + ')');
});
});

谁能提供任何合理的解决方案来处理/避免它并解释为什么会发生?

最佳答案

我建议在 it block 中有一个回调函数,这将确保所有异步代码在此之前得到执行。例如:

it('verifies counter on active tab', function (done) {
var usersPage = new UsersPage();
browser.wait(EC.visibilityOf(usersPage.firstRow), waitTimeout);

usersPage.rowsCount.count()
.then(function (count) {
var text = usersPage.activeTab.getText();
expect(text).toContain('Active' + ' (' + count + ')');
done();
});
});

关于javascript - Protractor/Jasmine2 - 在指定超时内未调用异步回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33077093/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com