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

cypress run doesn't return to command line #815

Closed
paulpruteanu opened this issue Oct 26, 2017 · 20 comments
Closed

cypress run doesn't return to command line #815

paulpruteanu opened this issue Oct 26, 2017 · 20 comments
Labels

Comments

@paulpruteanu
Copy link

paulpruteanu commented Oct 26, 2017

Current behavior:

cypress run

does not return to command line, under some circumstances, irrespective of the test results.

Desired behavior:

to return to command line, as the exit code is relevant when creating a build.

How to reproduce:

I could not replicate it, but the sequence of events in GUI is:
VISIT url # containing a hash-bang
XHR GET 200
XHR POST 404
XHR GET 200 # removes part of the URL hash-bang
CONTAINS something
XHR POST 200
XHR POST 200 # that's when the DOM get's updated with something
XHR GET 200
NEW URL # restoring the hash-bang

It works fine in the GUI, on both Chrome and Electron, but it's stuck in CLI with default browser (Electron).

Additional Info (images, stack traces, etc)

  • Operating System: MacOS Sierra 10.12.6
  • Cypress Version: 1.0.2
  • Browser Version: Electron 53
@youknowriad
Copy link

We're trying to use Cypress for WordPress's Gutenberg editor and we're experiencing the same issue. (See the travis job here https://travis-ci.org/WordPress/gutenberg/jobs/293142523)

@bahmutov
Copy link
Contributor

Hmm, interesting, can we have diagnostic log - if you run cypress with DEBUG=cypress:* environment variable it will show a lot more

@youknowriad
Copy link

Sure

screen shot 2017-10-26 at 15 03 08

@bahmutov
Copy link
Contributor

@brian-mann could it be timer problem? Because what we usually see after reporting test results is this

  - Cypress Version: 1.0.2
  cypress:server:timers queuing timer id 25 after 30000 ms +83ms
  cypress:server:timers child received timer id 25 +79ms
  cypress:server:timers clearing timer id 25 from queue { '24': { args: [], ms: 85000, cb: [Function] }, '25': { args: [], ms: 30000, cb: [Function: bound cleanupWebsocketResources] } } +3ms
  cypress:server:timers clearing timer id 24 from queue { '24': { args: [], ms: 85000, cb: [Function] } } +2ms
  cypress:server:timers clearing timer id 24 from queue {} +0ms
  cypress:server:timers child sending timer id 9 +89ms


  (Video)

  - Started processing:   Compressing to 32 CRF
  - Finished processing:  /tmp/cypress-test-tiny/cypress/videos/d3tft.mp4 (0 seconds)
  cypress:server Should copy Circle Artifacts? undefined +927ms


  (All Done)

  cypress:server about to exit with code 0 +2ms

@gziolo
Copy link

gziolo commented Oct 27, 2017

We're trying to use Cypress for WordPress's Gutenberg editor and we're experiencing the same issue. (See the travis job here https://travis-ci.org/WordPress/gutenberg/jobs/293142523)

I tried to run the same tests with Chrome using cypress run --browser chrome and it returns to the command line just after finishing all tests.

When I execute the tests with --headed flag I see the following list of requests in the Network tab:

screen shot 2017-10-27 at 09 18 35

I also see this error on the console:

screen shot 2017-10-27 at 09 22 29

@belohlavek
Copy link

I'm having the same issue, how did you guys solve this?

@gziolo
Copy link

gziolo commented Nov 6, 2017

Use chrome instead of electron as the selected browser 😎

@brian-mann
Copy link
Member

I've seen an issue in TravisCI before with it not killing background processes per command. Basically those will continue to keep it open.

I'd try splitting up booting + backgrounding your webserver from running the Cypress process to see if that fixes it.

@youknowriad
Copy link

@brian-mann I just want to precise than It happens locally as well. (MacOS 10.13)

@paulpruteanu
Copy link
Author

paulpruteanu commented Nov 7, 2017 via email

@bahmutov
Copy link
Contributor

bahmutov commented Nov 7, 2017 via email

@paulpruteanu
Copy link
Author

paulpruteanu commented Nov 7, 2017

// cypress/integration/test.js
describe(`my feature file`, () => {
    context(`that has a describe/ context/ it clause(s) which altogether contains
a combined description string length of 250 characters, when your test fails for
some reason or another`, () => {
        it(`halts, without showing the error, or returning to the CLI prompt`, () => {
            cy.visit('https://www.cypress.io/')
            cy.contains('Finally').should('not.exist')
        })
    })
})
/* `my feature filethat has a describe/ context/ it clause(s) which altogether contains
a combined description string length of 250 characters, when your test fails for
some reason or anotherhalts, without showing the error, or returning to the CLI prompt`
.length == 251. try remove 2 characters from any of the describe/ context/ it, and
the error will appear, alongside with the return to the command prompt.*/
./node_modules/.bin/cypress run --spec cypress/integration/test.js

It worths mentioning that if the test passes, the feedback is given, and it successfully returns to the prompt, irrespective of the combined string length.

@belohlavek
Copy link

belohlavek commented Nov 7, 2017

For me it happens with Electron headless and

describe('Log Viewer', () => {
  beforeEach(() => {
    cy.visit(Cypress.env('HOST'));
  });

  it('should open the Log Viewer', () => {
    cy.getElementByTestId('log-viewer-tab').click();
    cy.getElementByTestId('log-viewer-notice').should('be.visible');
  });
});

Both locally on Mac and on Travis.
getElementByTestId is mine :)

@paulpruteanu
Copy link
Author

Another issue I'm facing is related to beforeunload (#796).

<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        window.pageRefreshConfirmation = (e) => {
            (e||window.event).returnValue = "Are you sure?";
        }
        window.addEventListener("beforeunload", window.pageRefreshConfirmation)
    </script>
</head>
<body>
    foo bar
</body>
</html>
// cypress/integration/test.js
describe(`beforeunload issue`, () => {

    context(`electron browser fails to return to CLI on a page with beforeunload,
even when removing the listener`, () => {
        it(`checks foo`, () => {
            cy.visit('http://127.0.0.1:8080/')
                .then(() => {
                    cy.window().then(win => win.removeEventListener(
                        'beforeunload',
                        win.pageRefreshConfirmation)
                    )
                })
            cy.contains('foo').should('be.visible')
        })
        it(`checks bar`, () => {
            cy.visit('http://127.0.0.1:8080/')
            cy.contains('bar').should('be.visible')
        })
    })
})

when running

./node_modules/.bin/cypress run --spec cypress/integration/test.js

you hang up, not getting returned to command prompt:
screen shot 2017-11-07 at 11 44 06

If I remove the event listener from index.html:

<script>
    window.pageRefreshConfirmation = (e) => {
        (e||window.event).returnValue = "If you continue, any information you have entered will not be saved.";
    }
    //window.addEventListener("beforeunload", window.pageRefreshConfirmation)
</script>

then I am returned to the command prompt
screen shot 2017-11-07 at 11 52 13

@jennifer-shehane jennifer-shehane added the stage: needs investigating Someone from Cypress needs to look at this label Nov 7, 2017
@fsodano
Copy link

fsodano commented Nov 28, 2017

Thanks for your detailed report @paulpruteanu, it allowed me to solve this issue with a small workaround:

I simply clear the onbeforeunload function from the window. I am running it beforeEach although I suspect this is an overkill.

beforeEach(function () {
    cy.window().then(win => win.onbeforeunload = undefined);
});

@krishnaxv
Copy link

@brian-mann @bahmutov I am also facing this issue in GitLab CI. All the tests are running fine but the control is not returning back to CLI.

Is this an issue with Cypress or I am doing something wrong?

I have attached a screenshot of this issue.

cypress ci build

Any help or direction will be greatly appreciated. Thanks!

@mgalindo
Copy link

I am experiencing the same issue running locally in OS X

@igor-starostenko-ag
Copy link

I've had the same issue when running my tests with Electron.
In my case it was caused by a browser warning message that shows up when you're trying to close the page.
Like this one:
leave_site_prompt
I had to add some steps to navigate to another page that doesn't trigger this warning. Then the process could exit properly.
Hope this can help.

@mgalindo
Copy link

@igor-starostenko-ag Is funny that you posted that screenshot exactly when I was dealing with an issue in electron cause by that prompt

@jennifer-shehane
Copy link
Member

Unfortunately we have to close this issue due to inactivity. Please open a new issue if there is new information to provide concerning the original issue.

@cypress-io cypress-io locked and limited conversation to collaborators Jul 23, 2019
@jennifer-shehane jennifer-shehane removed the stage: needs investigating Someone from Cypress needs to look at this label Jul 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests