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

mal*_*874 5 javascript iframe e2e-testing cypress

我正在测试一个 Web 应用程序,测试在有头模式 ( cypress open) 下可靠运行,但在无头模式 ( cypress run) 下出现错误,因此这可能是我无法解决的竞争条件。错误信息是:

[36819:0223/163815.745047:ERROR:system_services.cc(34)] SetApplicationIsDaemon: Error Domain=NSOSStatusErrorDomain Code=-50 "paramErr: error in user parameter list" (-50)

当赛普拉斯创建该事件的视频时,再次提到此错误:


-  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)
                            
Run Code Online (Sandbox Code Playgroud)

我在这里创建了一个演示存储库。要重现,克隆它,运行yarn安装,然后yarn cypress:run. 测试确实通过了,但出现了上述错误。

我认为该错误源于访问嵌套的 iframe,到目前为止我测试了 5 种不同的方法,但没有效果。我特别确定了该功能getIframeBody等待每个 iframe 和请求的元素准备就绪。该错误还会创建一个视频,但您只能看到成功运行,那里看不到错误消息。

非常感谢有关如何进一步调试的任何帮助。

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})
        })
      })
    })
})
Run Code Online (Sandbox Code Playgroud)

mal*_*874 2

我得到一些反馈,上面的“ERROR:system_services.cc(34)”并不重要,不会导致不稳定或不成功的测试,因此没有行动点。