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

标签 javascript iframe cypress e2e-testing

我正在测试一个网络应用程序,测试在有头模式下可靠地运行(cypress open)但在 headless 模式下有错误(cypress run),所以它可能是我无法解决的竞争条件。错误信息是:

[36819:0223/163815.745047:ERROR:system_services.cc(34)] SetApplicationIsDaemon: Error Domain=NSOSStatusErrorDomain Code=-50 "paramErr: 用户参数列表错误"(-50)

当 Cypress 创建事件视频时再次提到此错误:


-  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)
                            

我创建了一个演示存储库 here 。要重现,请克隆它,运行 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})
        })
      })
    })
})

最佳答案

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

关于javascript - 在 headless 模式下测试嵌套 iframe 时出现 Cypress 错误 - 竞争条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71240376/

相关文章:

javascript - GWT 和 JxBrowser - 有什么经验吗?

javascript - 从 View 中修改 ng-model

javascript - 用 JavaScript 计算单词

javascript - 如何使用 php 通过 AJAX 以及单击链接时从数据库中删除记录

html - 如何创建一个以 HTML 格式播放 youtube 视频的按钮?

cypress - 如何在 Cypress 中测试选择是否具有给定值?

html - 如何在具有灵活高度的html css中嵌入Google Form iframe(响应式)

javascript - 不安全的 JavaScript 尝试使用谷歌地图访问框架

drop-down-menu - Cypress:是否可以从仅包含部分单词的动态下拉列表中选择一个项目?

url - Cypress :是否有可能在失败后完成测试