[英]Cypress error when testing nested iframes in headless mode - race condition
I am testing a web app and the test runs reliably in headed mode ( cypress open
) but has errors in headless mode ( cypress run
), so it's likely a race condition that I cannot resolve.我正在测试一个 Web 应用程序,并且测试在有头模式 (
cypress open
) 下可靠地运行,但在无头模式 ( cypress run
) 下有错误,所以这可能是我无法解决的竞争条件。 The error message is:错误信息是:
[36819:0223/163815.745047:ERROR:system_services.cc(34)] SetApplicationIsDaemon: Error Domain=NSOSStatusErrorDomain Code=-50 "paramErr: error in user parameter list" (-50)
This error is mentioned again when Cypress creates a video of the incident:当赛普拉斯创建事件视频时,再次提到了这个错误:
- Started processing: Compressing to 32 CRF
2022-02-23 17:00:19.700 Cypress Helper[37571:416134] In -[NSApplication(NSQuietSafeQuit) _updateCanQuitQuietlyAndSafely], _LSSetApplicationInformationItem(NSCanQuitQuietlyAndSafely) returned error -50
- Finished processing: /Users/malte.wirz/Documents/iframes-cypress-issue/cypress/videos/iframe-github.js.mp4 (3 seconds)
I created a demo repository here .我在这里创建了一个演示存储库。 To reproduce, clone it, run
yarn
to install, and yarn cypress:run
.要复制,克隆它,运行
yarn
安装,然后yarn cypress:run
。 The test does pass, but with the error mentioned above.测试确实通过了,但出现了上述错误。
I assume that the error stems from accessing the nested iframes and I tested 5 different approaches so far, but to no avail.我假设错误源于访问嵌套的 iframe,到目前为止我测试了 5 种不同的方法,但无济于事。 I especially made sure that the function
getIframeBody
waits until each iframe and the requested element is ready.我特别确保函数
getIframeBody
等到每个 iframe 和请求的元素准备好。 The error also creates a video, but you can only see the successful run, the error message is not visible there.该错误还会创建一个视频,但您只能看到成功运行,错误消息在那里不可见。
Any help on how to debug this further is much appreciated.非常感谢任何有关如何进一步调试的帮助。
describe('Testing Iframe within Iframes', () => {
it('Visits the iframe website and accesses the iframe within the iframe', () => {
const getIframeBody = (iframeSelector, elementSelectorInIframe) => {
return cy
.get(iframeSelector)
.its('0.contentDocument.body', {timeout: 30000})
.should((body) => {
expect(Cypress.$(body).has(elementSelectorInIframe).length).gt(0)
})
.then(cy.wrap)
}
// Visiting the page index.html and getting iframe A
cy.visit('index.html').contains('XHR in iframe')
getIframeBody('iframe[data-cy="bankid"]', 'iframe[src="https://tools.bankid.no/bankid-test/auth"]').as('iframeA')
cy.get('@iframeA').within(() => {
getIframeBody('iframe[src="https://tools.bankid.no/bankid-test/auth"]', 'iframe[src^="https://csfe.bankid.no/CentralServerFEJS"]').as('iframeB')
cy.get('@iframeB').within(() => {
getIframeBody('iframe[src^="https://csfe.bankid.no/CentralServerFEJS"]', 'input[type="tel"]').as('iframeC')
// Now we are in the right place and it finds the correct input element.
// However, normal cypress command .type() fails and we have to use library cypress-real-events,
// which provides an event firing system that works literally like in puppeteer
cy.get('@iframeC').find('input[type="tel"]').should('be.visible').realType('12345678912')
// But for the button below, this library now doesn't help anymore:
// "Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'."
// This was solved by using {scrollBehavior:false}.
cy.get('@iframeC').find('button[type="submit"]').should('be.visible').first().realClick({scrollBehavior:false})
})
})
})
})
我收到一些反馈,上面的“错误:system_services.cc(34)”并不重要,不会导致测试不稳定或不成功,因此没有行动点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.