我正在尝试通过重试实现类似于赛普拉斯请求的目标- 尽管该帖子的评论表明该解决方案不再有效/从未有效?!
无论如何,我需要向弹性服务器发送请求,如果没有返回记录,请稍等一下,然后重试(每隔几(10)秒重试一次,最多可以重试2分钟)...即类似:
cy.request({auth,method,body,url...}).then(reqresult => {
if (reqresult.body.hits.hits.length){
// results are in elastic, return them
}
else {
cy.wait(10000)
// repeat the request, if retry attempts not exceeded, or return the empty response if exceeded
}
})
Run Code Online (Sandbox Code Playgroud)
但我尝试过的所有操作(包括类似于上面的帖子)要么产生了“混合异步与同步”错误,要么只是循环而没有重新发送请求,或者最坏的情况是导致我的 Cypress (10.3.0) 窗口彻底挂了!
有人可以提供任何帮助吗?
我想我们都知道 cypress 和软断言已经被讨论得很厉害,并且有各种实现软解决方案的解决方案。一段时间以来,我一直在使用以下代码,基于旧的堆栈问题赛普拉斯是否支持软断言?:
\nlet isSoftAssertion = false;\nlet errors = [];\n\nchai.softExpect = function ( ...args ) {\n isSoftAssertion = true;\n return chai.expect(...args);\n},\nchai.softAssert = function ( ...args ) {\n isSoftAssertion = true;\n return chai.assert(...args);\n}\n\nconst origAssert = chai.Assertion.prototype.assert;\nchai.Assertion.prototype.assert = function (...args) {\n if ( isSoftAssertion ) {\n try {\n origAssert.call(this, ...args)\n } catch ( error ) {\n errors.push(error);\n }\n isSoftAssertion = false;\n } else {\n\n origAssert.call(this, ...args)\n }\n};\n\n// monkey-patch `Cypress.log` so that the last `cy.then()` isn\'t logged to command log\nconst …Run Code Online (Sandbox Code Playgroud) 我正在测试一个具有按钮的应用程序,该按钮会导致屏幕上另一个元素中的值发生更改,而无需重新加载页面。但是,该值的变化几乎是即时的,或者需要几秒钟。显然,我不想使用一些任意的等待,我不想使用(硬)断言 - 这可能会导致测试停止,但不是失败......所以我一直在看 cypress-wait-until ( https://www.npmjs.com/package/cypress-wait-until )。我已经按照以下方式编写了各种变体:
waitForElemToChange(elem) {
elem.invoke('attr', val').then((initialVal) => {
cy.waitUntil(() => elem.invoke('attr', 'value').then((val) => val != initialVal))
}
Run Code Online (Sandbox Code Playgroud)
但到目前为止没有任何效果 - 大多数尝试都导致“重试超时:cy.invoke() 出错,因为您的主题是:null。您不能对空值调用任何函数,例如 attr。”
然而它是在前一行中刚刚返回一个值的同一个主题??
我刚刚开始将 mochawesome 与 Cypress (9.7) 一起使用。我们的测试结构基本上是许多规范文件,每个文件都遵循以下格式:
\ndescribe(\'(A): description of this spec\', () => {\n describe (\'(B): description of test abc\', () => {\n before(() => {\n // do specific set up bits for this test\n })\n it(\'(C): runs test abc\', ()\xc2\xa0=> {\n // do actual test stuff\n })\n })\n})\nRun Code Online (Sandbox Code Playgroud)\n在每个规范文件中,将有一个“A”描述块,但可以有许多“B”级块(每个块都有一个“C”) - 这样做是因为之前的块每个“C”总是不同的 - 我不能使用 beforeEach。
\n当我运行各种规格文件时,每个规格文件的结构都与上面类似,mochaewsome 输出大部分是正确的 - 我在“A”级别为每个规格文件获得一个可折叠块,每个文件在 B 级都有多个可折叠块,每个块都有测试信息符合 C 级预期。
\n但是...圆形图表仅在 B 级显示。我所希望的是,可能有 A 级的聚合图表,以及所有 A 级块的进一步聚合图表。
\n不确定我是否已经很好地解释了这一点(!),但希望有人理解,并可以提供建议?!
\n