手动解决 getPromiseFinishAllItems 的承诺
Manually resolve promise for getPromiseFinishAllItems
我正在结合使用量角器、硒、茉莉花和报告门户进行自动化测试。测试全部 运行 都很好但是当涉及到最后一个测试时它总是挂起并且最终失败,调查它,它似乎归结为我的 protractor.conf.js 文件中的 afterAll 函数中使用的内容.
jasmineEnv.afterAll(async (done) => {
await agent.getPromiseFinishAllItems(agent.tempLaunchId);
done();
});
现在它调用的函数来自节点模块reportportal-agent.js :
getPromiseFinishAllItems(launchTempId){
return this.client.getPromiseFinishAllItems(launchTempId)
}
我注意到这个函数上面写的是注释
/*
* This method is used for frameworks as Jasmine and other. There is problems when
* it doesn't wait for promise resolve and stop the process. So it better to call
* this method at the spec's function as @afterAll() and manually resolve this promise.
*
* @return a promise
*/
请问有没有正确解决这个promise的办法?我尝试在网上查找但没有发现任何有意义的东西
编辑 -
protractor.conf.js
const ReportportalAgent = require('agent-js-jasmine');
const { SpecReporter } = require('jasmine-spec-reporter');
const suiteSettings = require('./suiteSettings');
const settings = require('./settings');
const logger = require('./tests/helpers/logger');
// This is a temporary solution because we have issues if instances=nodes. For now balance between nodes and instances that instances < 3
const nodeReduceCount = 5;
let isBrowserOpen = false;
exports.config = {
framework: 'jasmine',
seleniumAddress: settings.seleniumHubHost,
capabilities: {
'shardTestFiles': true,
'maxInstances': Math.max(settings.countOfStreams - nodeReduceCount, 1),
'browserName': settings.browser,
'loggingPrefs': {
performance: 'INFO',
},
'moz:firefoxOptions': getFirefoxOptions(),
'goog:chromeOptions': getChromeOptions(),
},
suites: [
suiteSettings.suite,
],
jasmineNodeOpts: {
defaultTimeoutInterval: settings.jasmineTimeout,
isVerbose: false,
includeStackTrace: true,
realtimeFailure: false,
},
onPrepare: async () => {
const jasmineEnv = jasmine.getEnv();
const capabilities = await browser.getCapabilities();
const config = await browser.getProcessedConfig();
global.consoleReporter = [];
console.log(capabilities);
if (!settings.useReportPortal) {
registerReporter(jasmineEnv);
} else {
registerConsoleReporter(jasmineEnv);
}
jasmineEnv.beforeEach(async () => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = settings.jasmineTimeout;
const criticalCheck = String(config.specs);
if (criticalCheck.includes('critical')) {
process.env.RUN_WITH_SERVICE_WORKER = 'true';
} else {
process.env.RUN_WITH_SERVICE_WORKER = '';
}
if (isBrowserOpen) {
browser.restart();
}
await browser.driver.manage().window().setSize(settings.viewPort.width, settings.viewPort.height);
isBrowserOpen = true;
await logger.logMessage(`Opening Link ${settings.newPlanUrl()}`);
await browser.waitForAngularEnabled(false);
await browser.get(settings.newPlanUrl());
});
},
};
function registerReporter(jasmineEnv) {
jasmineEnv.addReporter(new SpecReporter({
spec: {
displayStacktrace: true,
},
}));
const config = {
id: browser.params.id,
...settings.reportPortal,
};
const agent = new ReportportalAgent(config);
const reporter = agent.getJasmineReporter();
jasmineEnv.afterAll(async (done) => {
await agent.getPromiseFinishAllItems(agent.tempLaunchId);
done();
});
global.reporter = reporter;
jasmineEnv.addReporter(reporter);
return agent;
}
function registerConsoleReporter(jasmineEnv) {
jasmineEnv.afterEach(async () => {
await browser.takeScreenshot().then((png) => {
const testSuite = settings.currentSuite;
const date = new Date();
const currentDay = `(Time-${date.getHours()}-${date.getMinutes()}-${date.getSeconds()})`;
logger.writeScreenShot(png, `screenshots/${currentDay}_${testSuite}.png`);
});
});
jasmineEnv.afterAll(async () => {
await console.log('\n---------------------------------');
await console.log('Test Results');
await global.consoleReporter.forEach((testResult) => {
console.log(testResult);
});
await console.log('---------------------------------');
});
}
function getFirefoxOptions() {
const options = {};
if (settings.headless) {
options.args = ['--headless'];
}
return options;
}
function getChromeOptions() {
const options = {
args: [
'--disable-gpu',
'--no-sandbox',
'--disable-extensions',
'--disable-dev-shm-usage',
'--disable-infobars',
],
};
if (settings.headless) {
options.args.push('--headless');
options.perfLoggingPrefs = {
enableNetwork: true,
};
}
return options;
}
编辑:
所以我之前的错误是由于添加:
agent.getExitPromise.
但我注意到在删除它并再次 运行我的测试套件以查看 jenkins 是否会在测试中断时记录任何有用的信息,它说:
13:43:26 Cancelling nested steps due to timeout
13:43:26 ...Sending interrupt signal to process
13:43:31 npm ERR! path /app
13:43:31 npm ERR! command failed
13:43:31 npm ERR! signal SIGTERM
13:43:31 npm ERR! command sh -c node generateTests.js && node start.js
有人知道这是什么原因吗?
所以在与 Sergey 的评论之后,这对我有很大帮助。我意识到我看错了地方,并试图更多地思考正在发生的事情。查看测试运行,我注意到最后一个测试被切断了,所以我想我必须在最后一个测试有机会完成之前关闭某个地方的连接。
我所做的似乎有效的是:
jasmineEnv.afterAll(async (done) => {
await agent.getPromiseFinishAllItems(agent.tempLaunchId);
await agent.getExitPromise();
done();
});
获得退出承诺似乎已经解决了问题
好的,所以我终于找到了问题所在,我们的文件位于不正确的目录中。就是这样,一旦这些被移动到正确的位置,问题就停止了,最后的测试也不再挂起。所以对于遇到这个问题的任何其他人来说,这是需要检查的东西
我正在结合使用量角器、硒、茉莉花和报告门户进行自动化测试。测试全部 运行 都很好但是当涉及到最后一个测试时它总是挂起并且最终失败,调查它,它似乎归结为我的 protractor.conf.js 文件中的 afterAll 函数中使用的内容.
jasmineEnv.afterAll(async (done) => {
await agent.getPromiseFinishAllItems(agent.tempLaunchId);
done();
});
现在它调用的函数来自节点模块reportportal-agent.js :
getPromiseFinishAllItems(launchTempId){
return this.client.getPromiseFinishAllItems(launchTempId)
}
我注意到这个函数上面写的是注释
/*
* This method is used for frameworks as Jasmine and other. There is problems when
* it doesn't wait for promise resolve and stop the process. So it better to call
* this method at the spec's function as @afterAll() and manually resolve this promise.
*
* @return a promise
*/
请问有没有正确解决这个promise的办法?我尝试在网上查找但没有发现任何有意义的东西
编辑 -
protractor.conf.js
const ReportportalAgent = require('agent-js-jasmine');
const { SpecReporter } = require('jasmine-spec-reporter');
const suiteSettings = require('./suiteSettings');
const settings = require('./settings');
const logger = require('./tests/helpers/logger');
// This is a temporary solution because we have issues if instances=nodes. For now balance between nodes and instances that instances < 3
const nodeReduceCount = 5;
let isBrowserOpen = false;
exports.config = {
framework: 'jasmine',
seleniumAddress: settings.seleniumHubHost,
capabilities: {
'shardTestFiles': true,
'maxInstances': Math.max(settings.countOfStreams - nodeReduceCount, 1),
'browserName': settings.browser,
'loggingPrefs': {
performance: 'INFO',
},
'moz:firefoxOptions': getFirefoxOptions(),
'goog:chromeOptions': getChromeOptions(),
},
suites: [
suiteSettings.suite,
],
jasmineNodeOpts: {
defaultTimeoutInterval: settings.jasmineTimeout,
isVerbose: false,
includeStackTrace: true,
realtimeFailure: false,
},
onPrepare: async () => {
const jasmineEnv = jasmine.getEnv();
const capabilities = await browser.getCapabilities();
const config = await browser.getProcessedConfig();
global.consoleReporter = [];
console.log(capabilities);
if (!settings.useReportPortal) {
registerReporter(jasmineEnv);
} else {
registerConsoleReporter(jasmineEnv);
}
jasmineEnv.beforeEach(async () => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = settings.jasmineTimeout;
const criticalCheck = String(config.specs);
if (criticalCheck.includes('critical')) {
process.env.RUN_WITH_SERVICE_WORKER = 'true';
} else {
process.env.RUN_WITH_SERVICE_WORKER = '';
}
if (isBrowserOpen) {
browser.restart();
}
await browser.driver.manage().window().setSize(settings.viewPort.width, settings.viewPort.height);
isBrowserOpen = true;
await logger.logMessage(`Opening Link ${settings.newPlanUrl()}`);
await browser.waitForAngularEnabled(false);
await browser.get(settings.newPlanUrl());
});
},
};
function registerReporter(jasmineEnv) {
jasmineEnv.addReporter(new SpecReporter({
spec: {
displayStacktrace: true,
},
}));
const config = {
id: browser.params.id,
...settings.reportPortal,
};
const agent = new ReportportalAgent(config);
const reporter = agent.getJasmineReporter();
jasmineEnv.afterAll(async (done) => {
await agent.getPromiseFinishAllItems(agent.tempLaunchId);
done();
});
global.reporter = reporter;
jasmineEnv.addReporter(reporter);
return agent;
}
function registerConsoleReporter(jasmineEnv) {
jasmineEnv.afterEach(async () => {
await browser.takeScreenshot().then((png) => {
const testSuite = settings.currentSuite;
const date = new Date();
const currentDay = `(Time-${date.getHours()}-${date.getMinutes()}-${date.getSeconds()})`;
logger.writeScreenShot(png, `screenshots/${currentDay}_${testSuite}.png`);
});
});
jasmineEnv.afterAll(async () => {
await console.log('\n---------------------------------');
await console.log('Test Results');
await global.consoleReporter.forEach((testResult) => {
console.log(testResult);
});
await console.log('---------------------------------');
});
}
function getFirefoxOptions() {
const options = {};
if (settings.headless) {
options.args = ['--headless'];
}
return options;
}
function getChromeOptions() {
const options = {
args: [
'--disable-gpu',
'--no-sandbox',
'--disable-extensions',
'--disable-dev-shm-usage',
'--disable-infobars',
],
};
if (settings.headless) {
options.args.push('--headless');
options.perfLoggingPrefs = {
enableNetwork: true,
};
}
return options;
}
编辑:
所以我之前的错误是由于添加:
agent.getExitPromise.
但我注意到在删除它并再次 运行我的测试套件以查看 jenkins 是否会在测试中断时记录任何有用的信息,它说:
13:43:26 Cancelling nested steps due to timeout
13:43:26 ...Sending interrupt signal to process
13:43:31 npm ERR! path /app
13:43:31 npm ERR! command failed
13:43:31 npm ERR! signal SIGTERM
13:43:31 npm ERR! command sh -c node generateTests.js && node start.js
有人知道这是什么原因吗?
所以在与 Sergey 的评论之后,这对我有很大帮助。我意识到我看错了地方,并试图更多地思考正在发生的事情。查看测试运行,我注意到最后一个测试被切断了,所以我想我必须在最后一个测试有机会完成之前关闭某个地方的连接。
我所做的似乎有效的是:
jasmineEnv.afterAll(async (done) => {
await agent.getPromiseFinishAllItems(agent.tempLaunchId);
await agent.getExitPromise();
done();
});
获得退出承诺似乎已经解决了问题
好的,所以我终于找到了问题所在,我们的文件位于不正确的目录中。就是这样,一旦这些被移动到正确的位置,问题就停止了,最后的测试也不再挂起。所以对于遇到这个问题的任何其他人来说,这是需要检查的东西