我们正在使用带有茉莉花框架的量角器。以下是我们的规格文件
describe('Projects CRUD', function () {
var projectsPage = require('../pages/Projects_Page.js');
var commonFunctions = require('../utils/CommonFunctions.js');
it('Rename Project - Duplicate name check', function () {
try{
projectsPage.clickProjectsTab();
projectsPage.selectProject('AutoProject1');
projectsPage.projectBreadcrumbChevron.click();
projectsPage.editProjectIcon.click();
projectsPage.editProjectUpdateButton.click();
expect(projectsPage.duplicateProjectError.getText()).toEqual('A Project with that name already exists');
projectsPage.editProjectCancelButton.click()
commonFunctions.updateResult(164378 , "Project duplicate name checked with same Org unit successfully", "p");
}catch(err){
console.log(err);
commonFunctions.updateResult(164378 , err, "f");
}
});
});
我们的要求是,如果任何一个步骤之间的失败或什至期望条件在“ it”块中失败,则应执行catch块。目前,对于任何异常,它都无法捕获。遵循错误跟踪
Failures:
1) Projects CRUD Rename Project - Duplicate name check
Message:
Failed: project not found
Stack:
Error: project not found
at E:\JavaScriptWorkSpace\UIAutomation\pages\Projects_Page.js:39:23
at ManagedPromise.invokeCallback_ (C:\Users\abc\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:1376:14)
at TaskQueue.execute_ (C:\Users\abc\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:3084:14)
at TaskQueue.executeNext_ (C:\Users\abc\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:3067:27)
at asyncRun (C:\Users\abc\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2927:27)
at C:\Users\abc\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:668:7
at process._tickCallback (internal/process/next_tick.js:68:7)
From: Task: Run it("Rename Project - Duplicate name check") in control flow
at UserContext.<anonymous> (C:\Users\abc\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:94:19)
at C:\Users\abc\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:64:48
at ControlFlow.emit (C:\Users\abc\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\events.js:62:21)
at ControlFlow.shutdown_ (C:\Users\abc\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2674:10)
at shutdownTask_.MicroTask (C:\Users\abc\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2599:53)
From asynchronous test:
Error
at Suite.<anonymous> (E:\JavaScriptWorkSpace\UIAutomation\specs\ProjectsCrud.js:6:5)
at Object.<anonymous> (E:\JavaScriptWorkSpace\UIAutomation\specs\ProjectsCrud.js:1:63)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
1个规格,1个故障 30.699秒完成
答案 0 :(得分:0)
尝试以下一个
it('Rename Project - Duplicate name check', async () => {
try{
await projectsPage.clickProjectsTab();
await projectsPage.selectProject('AutoProject1');
await projectsPage.projectBreadcrumbChevron.click();
await projectsPage.editProjectIcon.click();
await projectsPage.editProjectUpdateButton.click();
expect(await projectsPage.duplicateProjectError.getText()).toEqual('A Project with that name already exists');
await projectsPage.editProjectCancelButton.click();
await commonFunctions.updateResult(164378 , "Project duplicate name checked with same Org unit successfully", "p");
}catch(err){
await console.log(err);
await commonFunctions.updateResult(164378 , err, "f");
}
});
希望它对您有帮助
答案 1 :(得分:0)
如果我正确理解执行流程,则您的错误发生在此处describe
(甚至更早)的块之后的第一行
describe('Projects CRUD', function () {
error is here ----> var projectsPage = require('../pages/Projects_Page.js');
var commonFunctions = require('../utils/CommonFunctions.js');
在try / catch块之前,因此此错误无法达到catch块。
并且从错误消息中,Projects_Page.js
文件中存在某些错误,可能丢失了require/import
或错字。
作为旁注,请在Proctractor documentation中阅读有关异步/等待的信息,因为据我所知,Web驱动程序控制流默认情况下已被禁用。