Cypress GUI looping test forever.
Can not take screenshot because tests are looping fast so I got the video.
My use case:
I have login api function in index.js file and I'm saving response into file.
In tests I use different parts of that json e.g acc token or ref token.
Cypress GUI run test once.
When user select test and run it. Test should run once.
Import
import * as
commands.js
Cypress.Commands.add('apiLoginFe', (body) => {
querystring.stringify(body)
return cy.request({
method: 'POST',
url: apiUrl+signin,
form: true,
body
})
.its('body')
})
index.js
before(() => {
cy.loginRequest(users.admin)
.then((resp) => {
cy.writeFile('cypress/data/credential.json', resp.data)
})
});
I didn't try all versions but on 3+ is not working.
System OSX, Browsers all
I see you have a cy.visit() command within the video. Does this loop run forever when you remove the cy.visit() command? I would like to exclude that as potentially being the cause.
Here is test without cy.visit()
import users from '../../data/users/userData';
describe('Random API tests', () => {
const admin = users.admin;
const credetnialFilepath = 'cypress/data/credential.json';
it('Login with admin user and save tokens to file', () => {
cy.apiLoginFe(admin)
.then((resp) => {
cy.writeFile(credetnialFilepath, resp)
})
})
})
Here is video
withoutVisit.zip
And it doesn't rerun with just the cy.apiLoginFe(admin) command?
It does rerun in loop always when i have Import
import * as
in any function in my code.
I can give you access to code base if you want to check it.
@nikolaJosifovic Yeah, that would be helpful if you could. You can also email [email protected] to send information to our support team.
Hey @nikolaJosifovic Any updates on this issue?
@jennifer-shehane my tests are running an infinite loop. Here's more info STACKOVERFLOW_LINK
@jasmeet17 The stackoverflow link was answered by one of our engineers. You cannot have multiple domains within a single test and you cannot have multiple top level describes in a file. If you're still experiencing this issue - provide an example in a new issue that we can run on our machines.
Unfortunately we have to close the original issue due to inactivity. Please comment if there is new information to provide concerning the original issue and we can reopen.
@jennifer-shehane I think I've encountered the same issue.
Cypress version 3.4.1 on Windows with Typescript setup via browserify.
Reproduces if I add import * as something from './somewhere' to the file which is imported by the test file.
Don't even need to use something to trigger this. If the line is removed issue disappears.
Actual behaviour: test starts, "before all" part runs, tests starts and immediately after that interrupts and test starts again, "before all" runs again...
On each loop iteration there is an error printed and immediately cleared.
Uncaught TypeError: Cannot read property 'stop' of null
at $Cypress.stop (cypress_runner.js:78554)
at Object._reRun (cypress_runner.json:157679)
at Socket.rerun
The looping issue occurred to me when I have run the cy.writeFile several times and overriding the json file. My code below:
cy.request(...).then(response) => {
cy.WriteFile('cypress/fixtures/tokens.json', response.body);
}
I deleted tokens.json and it works fine. The looping only happens when the json file already exists then overwriting the contents of the json file.
The looping issue occurred to me when I have run the cy.writeFile several times and overriding the json file. My code below:
cy.request(...).then(response) => { cy.WriteFile('cypress/fixtures/tokens.json', response.body); }I deleted tokens.json and it works fine. The looping only happens when the json file already exists then overwriting the contents of the json file.
@poponuts I had the same problem, and in the end, I realized that this is not a bug. You need to set watchForFileChanges to false because every time you overwrite your JSON file, cypress is listening to changes and restarting the test. I'm wondering now, is there any way to config ignore list related to changes?
Yes, this may be the cause. You'll need to turn set watchForFileChanges to false as a workaround. More info on file watching here. https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests.html#Configuration
I actually am not able to reproduce it with the above code alone though. I tried this code and it works fine. Am I missing another piece.
it('cy.request() - make an XHR request', () => {
cy.visit('https://example.cypress.io/commands/network-requests')
cy.request('https://jsonplaceholder.cypress.io/comments')
.then((response) => {
cy.writeFile('cypress/fixtures/example.json', response.body)
})
})
@jennifer-shehane if you add an import, and assuming there's an initial file in the fixtures folder, it'll continuously re-run.
import example from '../fixtures/example.json';
it('cy.request() - make an XHR request', () => {
cy.visit('https://example.cypress.io/commands/network-requests')
cy.request('https://jsonplaceholder.cypress.io/comments')
.then((response) => {
cy.writeFile('cypress/fixtures/example.json', response.body)
})
})
Most helpful comment
Yes, this may be the cause. You'll need to turn set
watchForFileChangestofalseas a workaround. More info on file watching here. https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests.html#ConfigurationI actually am not able to reproduce it with the above code alone though. I tried this code and it works fine. Am I missing another piece.