我如何采用此代碼來包含,當字串值為“5.10”時,正常運行測驗集合?目前它可以作業,但它只會通過測驗失敗,這在我的報告中看起來很糟糕。
我嘗試了各種解決方案,但都沒有奏效,比較 chai/postman 中的浮點數是一場噩夢。或者我創建的任何解決方案都有問題。我必須使用字串來匹配我的代碼版本中的值,5.10 高于 5.20...因此字串匹配。
我還將 5.6 = 保存到 tofixed(2); 因此 5.60
*代碼 *:
pm.test("Validate the following strings", function() {
let expectedStrings = ["4.60", "4.80", "4.70", "4.90", "4.10", "4.11",
"4.12", "4.13", "5.20", "5.30", "5.40", "5.50", "5.60", "5.70", "5.80",
"5.90"];
const hasAnyExpectedString = expectedStrings.some((s) =>
version2.includes(s));
pm.expect(hasAnyExpectedString).to.be.true;
postman.setNextRequest("stoptest1")
});
當預期的字串未包含在該字串陣列中時,例如“5.10”,我不希望此測驗失敗
如果你能幫忙,那就太好了。
干杯。
uj5u.com熱心網友回復:
實際上,我只是讓自己更難,只是寫了一堆 if 陳述句..:/
if (version == 'etc')
{
postman.setNextRequest("stoptest1")
}
uj5u.com熱心網友回復:
根據您的評論
如果是這些版本,我只希望它轉到 stoptest1。如果它的“5.10”那么測驗應該失敗,而不是去 stoptest1
我制作了一個示例代碼來滿足您的要求。
const version = ... //get from somewhere
pm.test("Validate the following strings", function() {
let expectedStrings = ["4.60", "4.80", "4.70", "4.90", "4.10", "4.11",
"4.12", "4.13", "5.20", "5.30", "5.40", "5.50", "5.60", "5.70", "5.80", "5.90"];
const hasAnyExpectedString = expectedStrings.includes(version);
if(hasAnyExpectedString){
postman.setNextRequest("stoptest1")
} else {
pm.expect(hasAnyExpectedString).to.be.true;
}
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/317692.html
