gpt4 book ai didi

javascript - 如何检索 "it" block 状态并根据结果我需要在 ALM 中上传屏幕截图

转载 作者:行者123 更新时间:2023-12-02 23:00:59 25 4
gpt4 key购买 nike

在我的项目中,一个规范文件中会存在多个 it block 。因此,在执行规范时,我需要检索“it” block 的通过/失败状态,并根据结果我必须执行一些操作,例如在 ALM 中上传屏幕截图。

我已经尝试了 Spec did 来检索通过或失败状态。但是在 AfterEach() 中我需要根据通过或失败状态上传屏幕截图。我不确定如何获取并传递“it” block 执行状态,并在 afterEach() 中使用相同的状态来继续通过或失败验证。

暂时排除代码的 ALM 部分。所附代码现在多次打印 afterEach() 控制台语句。

>For first it block it is printing for one time.
>After second it block execution, it is printing twice
>After third it block execution, it is printing thrice.
Not sure why it printing multiple time ,as after Each is expected to run once after "it" block in spec file.

命令提示符的结果:.名称:TestSuite1 Testcase1-POM type1我通过了:it01
.名称:TestSuite1 步骤-输入凭据-步骤2我通过了:it01

名称:TestSuite1 步骤-输入凭据-步骤2我通过了:it01

.名称:TestSuite1 步骤3我通过了:it01名称:TestSuite1 步骤3我通过了:it01名称:TestSuite1 步骤3我通过了:it01

有人可以帮忙吗,为什么它在 Protractor 中打印多次。

下面是我的代码:

var exceldata=require("../CommonMethods/ExcelRead.js");
var homepage= require("../PageObjects/HomePage.js");
var Exeresults;
var fs= require('fs');
var LandingPage;
var BaristaNewWindowPage;

var Testitblock;
var Testitblockstatus;
var Testsuite;

var JasmineTestContainerSupport = window.JasmineTestContainerSupport || require('jasmine-test-container-support');

JasmineTestContainerSupport.extend(jasmine);


if(exceldata.Mytest.test1==="Yes"){
describe('TestSuite1',function()
{


beforeAll(function()
{
browser.get(exceldata.MyURL.testurl1);
console.log("Posse URL is launched successfully");
});

it('Testcase1-POM type1',function()
{
try{
homepage.clickingPosseLink();
}catch(err){
console.log("error occured in first step of it block")
}

});

it('Step-entering credentials-step2',function(){

homepage.entercredintal("test1@gmail.com", "Sudhar@12345");


});

it('step3',function()
{
try{
LandingPage=homepage.clickingSubmit();
}catch(err){
console.log("error occured in third step of it block")
}

});
xit('step4',function()
{
try{`enter code here`
BaristaNewWindowPage=LandingPage.navigateBaristaURL();
//expect(1).toequal(2);
}catch(err){
console.log("error occured in fourth step of it block")
}

});
xit('step5',function()
{
try{
BaristaNewWindowPage.BaristaOurStoryLnk();
}catch(err){
console.log("error occured in fifth step of it block")
}

});



afterEach(function(){

jasmine.getEnv().addReporter(new function() {
this.specDone = function(result) {
//status = result.failedExpectations.length > 0 ? "Fail" : "Pass";
console.log('Name: ' + result.fullName);
if (result.failedExpectations.length > 0) {
console.log('I am Failed: it01');
status = "Fail";
notes = result.failedExpectations;
}else{
console.log('I am Passed: it01');
status = "Pass";
notes = "";
}
};

});
});
});

}

最佳答案

  1. 您可以实现记录器 log4Js用于在日志中获取所有测试通过/失败状态的库
  2. 您可以使用外部报告图书馆here

我目前正在我的框架中使用

关于javascript - 如何检索 "it" block 状态并根据结果我需要在 ALM 中上传屏幕截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57787833/

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