question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Actions in Cypress cause Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'

See original GitHub issue

Current behavior:

When using Cypress to click through the Norwegian BankID test page (the most commonly used electronic identification system in Norway) it’s not possible to type in the input fields within the iframes without using { force: true }. The iframe is cross-origin, so we have disabled chromeWebSecurity in cypress.json. It’s worth noting that the input field is inside an iframe which itself is inside an iframe, where the inner iframe is from the source csfe.bankid.no and the outer is from the source tools.bankid.no.

When using { force: true } it still does not emit all the events that a proper user keyboard action would, as the website behaves differently than when manually typing in the input field. When manually typing, the form validator is run which enables form submit, but this does not happen when typing using Cypress and cy.type. If trying to type without { force: true } we get an error saying Timed out retrying: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'..

image

Desired behavior:

Using cy.type (either with or without { force: true }) leads to the same result as when a user would type into the field. That is, the validator runs and the submit is enabled.

Test code to reproduce

  • I have forked the cypress-test-tiny repo to make a reproducible example: https://github.com/torkjels/cypress-test-tiny.
  • Run the tests non-headless in Chrome using npm run cypress:open.
  • There are 4 tests, and the only one that runs green is the one that pauses to allow for a user keyboard action. This suggests that there are some event(s)/information that cy.type doesn’t emit to the iframe which get dispatched on normal user interaction.

Versions

Cypress: 4.9.0 Operating system: RHEL 7.8 Browser: Chrome 83

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
BogdanCerovaccommented, Aug 4, 2021

@anish-vakharia & @swatidhanu1985 ;

Hi, I must say that I gave up on using Cypress to test this as my hacky solution was not very scalable and neither robust. Sadly abandoned went to Puppeteer as it supports “native” events and Cypress is still working on them as far as I know (ref. to https://github.com/cypress-io/cypress/issues/311).

Conceptually it went like this, hacky as I mentioned;

  1. Disabled security (same-origin policy) in browser - https://docs.cypress.io/guides/guides/web-security#Set-chromeWebSecurity-to-false
  2. Made a “shadow” form on parent page holding iframe, under our control that sends (native JS) events to iframe (with JQuery), so that we can manipulate “shadow” form from Cypress and it is then manipulating iframe form.

It was much easier to do it with Puppeteer and I guess one could use the session cookie from Puppeteer inside Cypress if you absolutely want to use Cypress. I liked it for assertions but for this project it was too early…

Hope Cypress will get native events - then we will be able to do this simple flow easily and with no hacks.

1reaction
jennifer-shehanecommented, Jul 7, 2020

Smaller repro example:

cypress.json

{
  "chromeWebSecurity": false,
  "defaultCommandTimeout": 10000
}

spec.js

it('breaks when not using force on click', function () {
  cy.visit('https://www.bankid.no/privat/los-mitt-bankid-problem/test-din-bankid---multidokumentsignering/')

  // Wait for the frame to load
  cy.wait(3000)

  // Click first button
  cy.get('iframe')
    .its('0.contentDocument')
    .its('body').as('outerIframe')
    .then(cy.wrap)
    .find('iframe')
    .its('0.contentDocument')
    .its('body').as('innerIframe').then(() => {
      cy.wrap(this.innerIframe)
        .find('.document-list')
        .find('button')
        .first()
        .click()

      // Wait for next frame to load
      cy.wait(3000)

      // Check checkbox
      cy.wrap(this.innerIframe).contains('Innholdet er forstått og jeg er klar til å signere.').click()

      // Click next button
      cy.wrap(this.innerIframe)
        .find('button[title=Neste]')
        .click()
    })
})
Timed out retrying: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'
Screen Shot 2020-07-07 at 3 53 18 PM

This error is throwing when we call scrollIntoView on the element we intend to perform the action on: https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/actionability.js#L316

We’re just calling the native JS function here, and it’s erroring…so this is a bit confusing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JS: Failed to execute 'getComputedStyle' on 'Window ...
You receive it because the parameter has an incorrect type. The most common case is that you try to pass an element that...
Read more >
cypress-io/cypress - Gitter
Getting this error "Timed out retrying: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'" on trying to enter...
Read more >
Failed to execute 'getComputedStyle' on 'Window': parameter ...
HTML : "Uncaught TypeError: Failed to execute ' getComputedStyle ' on ' Window ': parameter 1 is not of type ' Element '....
Read more >
SyntaxError: missing ) after argument list - JavaScript | MDN
The JavaScript exception "missing ) after argument list" occurs when there is an error with how a function is called. This might be...
Read more >
Search Results - CVE
This vulnerability allows remote attackers to execute arbitrary code on affected installations of Ansys SpaceClaim 2022 R1. User interaction is required to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found