繁体   English   中英

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

[英]Cypress error when testing nested iframes in headless mode - race condition

我正在测试一个 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)
                            

我在这里创建了一个演示存储库。 要复制,克隆它,运行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})
        })
      })
    })
})

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM