简体   繁体   English

在无头模式下测试嵌套 iframe 时出现赛普拉斯错误 - 竞争条件

[英]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.

相关问题 Cypress:如何获取 Cypress 开始以无头模式录制的时间戳? - Cypress: How can I get the timestamp of when Cypress start to record in headless mode? 通过赛普拉斯测试时出现混合内容错误 - Mixed Content Error when testing via Cypress 用Jest测试通用捕获代码-竞争条件 - Testing code with a universal catch with Jest - race condition 调用组件时的竞争条件 - Race condition when calling components 赛普拉斯不在无头模式下重复使用 cookie 或会话 - Cypress not re-using cookies or session in headless mode 赛普拉斯:由于超时,在浏览器中通过的相同测试在无头模式下失败 - Cypress: same tests that pass in browser fail in headless mode due to timeout 赛普拉斯模糊事件(当输入失去焦点时)不会由无头“cypress run --browser firefox”触发,而是与“cypress open”一起使用 - Cypress blur events (when input loses focus) are not triggered with headless "cypress run --browser firefox" but work with "cypress open" 使用$ .when时如何解决竞争条件 - How to resolve race condition when using $.when 将xml载入div时的AJAX竞争条件 - AJAX race condition when loading xml into div 保存到 supabase 数据库时的竞争条件 - Race condition when saving to the supabase database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM