jenkins - 詹金斯显示量角器测试是成功的,即使它们失败了
问题描述
当控制台清楚地显示失败时,Jenkins 将 Protractor 测试显示为成功。
我在我的代码中添加了一个 expect() 和一个 fail() ,但只是不能让脚本失败,以避免误报。
脚本代码
async fillCategories(): Promise<void> {
try {
await this.helper.compareText(this.projectNamePath, this.projectName);
await this.helper.compareText(this.projectStatus, 'Started');
await browser.wait(ExpectedConditions.presenceOf(this.verticalDots), 500);
await this.helper.compareText(this.commonElements.lCurrentStepName, 'Categories');
await this.helper.click(this.firstCheckbox);
await this.helper.click(this.btnSaveAndContinue);
} catch (error) {
console.log(`Something wrong while filling categories.`);
fail(`Something wrong while filling categories.`);
expect(`Test`).toBe('Fail');
}
}
这些似乎根本没有任何作用。
fail(`Something wrong while filling categories.`);
expect(`Test`).toBe('Fail');
詹金斯控制台:
**************************************************
* Failures *
**************************************************
1) abc Project Smoke Test should create a project in abc
[31m- [39m[31mExpected '' to be 'QA Automation'.[39m
[31m- [39m[31mFailed: Something wrong while filling categories.[39m
[31m- [39m[31mExpected '2' to be 'Purposes'.[39m
[31m- [39m[31mExpected '3' to be 'Ripts'.[39m
[31m- [39m[31mFailed: project creation failed TimeoutError: Wait timed out after 30031ms[39m
Executed 2 of 2 specs[31m (1 FAILED)[39m in 4 mins 17 secs.
[16:02:18] I/launcher - 0 instance(s) of WebDriver still running
[16:02:18] I/launcher - chromeANY #01 passed
No mail will be sent out, as 'Dev Hourly Smoke Test #461' does not have a result yet. Please make sure you set a proper result in case of pipeline/build scripts.
Finished: SUCCESS
看到上面最后一行的成功了吗?
团队输出
解决方案
所以我正在使用shell命令。对我有用的是像这样运行量角器
ERROR=0
protractor conf.js || ERROR=1
exit $ERROR
如果量角器通过,错误保持为零,并且当您exit 0
将构建标记为成功时
|| ERROR=1
仅在量角器失败时执行,覆盖值并以1
失败的代码退出
我希望你能从这里拿走它并为你的情况做一个平行线