Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidCharacterError Failed to execute 'atob' on 'Window' #9442

Closed
xtroncode opened this issue Dec 3, 2020 · 26 comments
Closed

InvalidCharacterError Failed to execute 'atob' on 'Window' #9442

xtroncode opened this issue Dec 3, 2020 · 26 comments
Labels
stage: needs information Not enough info to reproduce the issue stale no activity on this issue for a long period

Comments

@xtroncode
Copy link

Current behavior

We are getting the following error trace. This is occurring randomly on random spec files in our CI environment. We are not able to reproduce it. All the retries also fail with the same error.

InvalidCharacterError: The following error originated from your test code, not from Cypress.

  > Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.

When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.
Error: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
    at Object.decodeBase64Unicode (https://example.com/__cypress/runner/cypress_runner.js:177637:31)
    at base64toJs (https://example.com/__cypress/runner/cypress_runner.js:176928:28)
    at Object.extractSourceMap (https://example.com/__cypress/runner/cypress_runner.js:176894:21)
    at extractSourceMap (https://example.com/__cypress/runner/cypress_runner.js:175985:37)
    at tryCatcher (https://example.com/__cypress/runner/cypress_runner.js:10325:23)
    at MappingPromiseArray._promiseFulfilled (https://example.com/__cypress/runner/cypress_runner.js:7445:38)
    at MappingPromiseArray.PromiseArray._iterate (https://example.com/__cypress/runner/cypress_runner.js:8647:31)
    at MappingPromiseArray.init (https://example.com/__cypress/runner/cypress_runner.js:8611:10)
    at Promise._settlePromise (https://example.com/__cypress/runner/cypress_runner.js:8314:21)
    at Promise._settlePromise0 (https://example.com/__cypress/runner/cypress_runner.js:8362:10)
    at Promise._settlePromises (https://example.com/__cypress/runner/cypress_runner.js:8442:18)
    at Promise._fulfill (https://example.com/__cypress/runner/cypress_runner.js:8386:18)
    at MappingPromiseArray.PromiseArray._resolve (https://example.com/__cypress/runner/cypress_runner.js:8659:19)
    at MappingPromiseArray._promiseFulfilled (https://example.com/__cypress/runner/cypress_runner.js:7485:18)
    at Promise._settlePromise (https://example.com/__cypress/runner/cypress_runner.js:8322:26)
    at Promise._settlePromise0 (https://example.com/__cypress/runner/cypress_runner.js:8362:10)

Desired behavior

The tests should not fail with this error or atleast should correct itself in retries.

Test code to reproduce

Unable to reproduce the error consistently.

Versions

Cypress: 5.3.0
Browser: Custom Chrome 86 (headless)

@sgomezcnvdev
Copy link

We are getting this error as well in our CI env and sometimes Cypress throws the following error

image

image

Errors are generated randomly.

Versions
Cypress: 4.12.1
Browser: Chrome 83 (headless) (cypress/browsers:node12.18.0-chrome83-ff77)

@jennifer-shehane
Copy link
Member

Are either of you testing file upload in your tests? Or Cypress.Blob anywhere? I've seen this error when involved with file upload before.

Also, I see that both of you you are using an older version of Cypress. Please update to the current version of Cypress and let us know if this is still happening for you.

Can you share the code around file upload where this is failing? It would be best if you could get this occurring locally in the same browser and open DevTools to see the full error and where it's originating from.

@jennifer-shehane jennifer-shehane added the stage: needs information Not enough info to reproduce the issue label Dec 4, 2020
@xtroncode
Copy link
Author

Hi @jennifer-shehane , thanks for the reply.

We are not testing file uploads in any of our tests.

From what I can understand looking at the stack trace, the error is originating here when it is being called from here when loading the spec files in the browser. As what we saw in the video that was recorded is that the tests don't even start running.

We'll be updating to the latest cypress version this week and let you know if this still persists.

@sgomezcnvdev
Copy link

Hi @jennifer-shehane ,
In our case, we don't use Cypress.Blob and there is only one test to automate upload files. It is using this library cypress-file-upload for that. Below is the code:

image

But I saw that the error happened when Cypress tried to launch Mocha JS. In this point any test has been executed yet. Is there a way to get more information about the error? I used DEBUG option but the information is not enoght to know what happend.

Regarding the version, I started migration to Cypress 6.0.0 last week but I had some issues with new command cy.interceptor(). Some of them were already reported in other tickets and I created this question in discusion section #9364. When they are fixed, I will continue with the migration.

Thanks for your assistance.

@nikhilesh009
Copy link

we are getting a kinda similar error on the CI environment on random spec file, local works fine. not able to reproduce locally.
Screenshot 2021-01-21 at 13 54 07

@andreieftimie
Copy link

I started seeing these and other (similar in nature) errors when switching to running more than 1 cypress test in parallel on the same machine.

The following failures are observed:

InvalidCharacterError: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
SyntaxError: The following error originated from your test code, not from Cypress.
> Unexpected end of input
SyntaxError: The following error originated from your test code, not from Cypress.
> Invalid or unexpected token

All of these are always visible on the first test of each chunk, which leads me to think that cypress or the browser are not properly initiated (or the app does not manage finishing loading) before the test attempts to start.

We are running cypress 5.3.0 — would really like to solve these before attempting to upgrade to the latest version since there's a non-trivial amount of work to update of the cy.route calls.

I am looking into issues relating to:

  • resource constrains — since we are running multiple processes in parallel, the machine might not have enough resources to allow the test run to complete correctly
  • resource locking — maybe one of the processes breaks one of the others that is running on the same machine

@sgomezcnvdev
Copy link

Hi @andreieftimie , I have a similar scenario (multiple cypress process in parallel) and Cypress is throwing the same errors with latest version (6.5.0). Yesterday I upgraded the version from 4.12.1 to 6.5.0 but the errors presists. Maybe Cypress does not have support to be executed in parallel in the same machine. In my case, errors happen randomly and other time all tests passed without any errors.

@andreieftimie
Copy link

Maybe Cypress does not have support to be executed in parallel in the same machine.

This is how it actually looks. There seem to be multiple factors at play here.

Unfortunately I am not in control over the CI infra, and can't run real parallelism at the moment.

@ggascoigne
Copy link

ggascoigne commented May 10, 2021

Mostly chiming in here to say that we see this pretty regularly on our CI system as well, and that it seems nigh on impossible to reproduce when we're specifically looking for it.

edited to add that we're using Cypress 7.2.0 and headless electron 89.

@VickyLund
Copy link

This might help. We used to run 3 parallel processes of Cypress on one server. This caused a lot of issues for us one of which was this one.
After isolating the processes via containers, we did not get this again.

@suniljaiswal01
Copy link

I am also getting the same error while uploading .svg file. I am using the latest version of cypress (7.5.0). Below is the script to upload file:
cy.fixture(fileName).then(fileContent => { cy.xpath(xpath).attachFile({ fileContent: Cypress.Blob.base64StringToBlob(fileContent.toString()), fileName: fileName, }, { subjectType: 'drag-n-drop' }); });

I am able to upload .jpg/.png/json file using the same script

@jennifer-shehane
Copy link
Member

We don't recommended running more than 1 Cypress process in parallel on a single machine. There are a few issues that happen when this is done and the majority of the time, there is not enough resources on the machine to run Cypress and it still be performant.

@andreieftimie
Copy link

We don't recommended running more than 1 Cypress process in parallel on a single machine. There are a few issues that happen when this is done and the majority of the time, there is not enough resources on the machine to run Cypress and it still be performant.

Based on the inquires in this thread there are numerous people running multiple instances on the same machine. For example we don't have full control over the CI environment (and I suspect similar constrains for other people) so a "poor man's" parallelism is achieved through running 2-3 instances on the same machine.

While proper multi-machine parallelism would be better, we did halve the running time from ~60min to ~30 min by running 3 instances in parallel.

@poponuts
Copy link

I am having same issue now with my CI. And yes, I think running parallel tests on your CI is a common standard now.

@sgomezcnvdev
Copy link

Hi folks, I had similar issues in my CI enviroment. In my case, I was able to fix it increasing the SHM size to 4 gb (args '--shm-size="4g"') in the jenkins file and assigning different temp folder by each cypress process (XDG_CONFIG_HOME=/tmp/cyhome). In my case, jenkins job is executing 6 cypress instance in parallel without errors.

jenkins file:
image

image

Versions
Cypress: 7.2.0
Browser: Chrome 89 (headless) (cypress/browsers:node12.18.3-chrome89-ff86)
CI: Jenkins

@andreieftimie
Copy link

@sgomezcnvdev nice!
What are the machine specs? (CPU cores and RAM)

@sgomezcnvdev
Copy link

@andreieftimie

  • E52066 2.0Gz CPU(s) 8
  • 16 GB
    Processes consume around 85% of resources (memory/cpu). I tried to add more processes in parallel but cypress gets slower because need more resources. So I think that I will need add another build machine in the long term.

@romankhomitskyi
Copy link

romankhomitskyi commented Nov 12, 2021

@andreieftimie Solution that helped me Fix unexpected token and win atob

@BlueWinds
Copy link
Contributor

@romankhomitskyi - that is really interesting, thanks for the article, and I think you've correctly identified a root cause here.

If you (or anyone else) wanted to open a PR to do something similarly inside Cypress itself, we'd definitely be interested in taking a look at it.

@BlueWinds BlueWinds removed the stage: needs information Not enough info to reproduce the issue label Nov 12, 2021
@romankhomitskyi
Copy link

romankhomitskyi commented Nov 14, 2021

@romankhomitskyi - that is really interesting, thanks for the article, and I think you've correctly identified a root cause here.

If you (or anyone else) wanted to open a PR to do something similarly inside Cypress itself, we'd definitely be interested in taking a look at it.

I think there is an experienced dev at Cypress that could do this in 1-2 days

@kavehsaket
Copy link

kavehsaket commented Nov 12, 2022

I get the same error when I run my tests on GitHub actions. Cypress on ci is painful.

@stefangluszek
Copy link

We don't recommended running more than 1 Cypress process in parallel on a single machine. There are a few issues that happen when this is done and the majority of the time, there is not enough resources on the machine to run Cypress and it still be performant.

@jennifer-shehane is this documented anywhere? Also in your jenkins example you do run multiple parallel cypress processes on a single agent:
https://github.com/cypress-io/cypress-example-kitchensink/blob/master/Jenkinsfile

@guychienll
Copy link

guychienll commented Jun 29, 2023

any updates ?

@lmiller1990
Copy link
Contributor

lmiller1990 commented Jun 30, 2023

Not right now -- is this still an issue in later versions of Cypress (eg Cypress 12)?

It's hard to assign someone to work on this when it's so difficult to reproduce consistently - hard to debug and fix something that's primarily a race condition, especially if it only occurs running many Cypress instances in on a single machine in parallel, which isn't something we generally recommend (parallelization via CI and separate machines, however, is definitely something we use heavily).

You could try #9442 (comment). I don't fully understand how the webpack preprocessor conflict occurs that is suggested in that article, nor how it would lead to the atob error.

@jennifer-shehane jennifer-shehane added stage: needs information Not enough info to reproduce the issue and removed Needs Reproduction labels Oct 5, 2023
@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label Apr 3, 2024
@cypress-app-bot
Copy link
Collaborator

This issue has been closed due to inactivity.

@cypress-app-bot cypress-app-bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: needs information Not enough info to reproduce the issue stale no activity on this issue for a long period
Projects
None yet
Development

No branches or pull requests