I am adding Cypress to a large monorepo. I am using:
"laracasts/cypress": "^3.0", and
"cypress": "^12.0.1",
I have followed the installation instructions in the laracasts cypress package found here:
https://github.com/laracasts/cypress
I have replaced the generated example.cy.js file with:
describe('Example Test', () => {
before(() => {
cy.refreshDatabase();
})
... some other bits that aren't hit
});
I have database called cypress_testing set in my cypress env file.
When I run this file, it hangs before returning:
cy.request() timed out waiting 30000ms for a response from your server.
The request we sent was:
Method: POST
URL: http://localhost:3000/cypress/artisan
No response was received within the timeout.
There are no laravel logs, no console logs - just this timeout error. In cypress config file, I have:
const threeMinutesInMiliseconds = 180000;
module.exports = defineConfig({
chromeWebSecurity: false,
retries: 2,
defaultCommandTimeout: threeMinutesInMiliseconds,
responsetimeout: threeMinutesInMiliseconds,
requestTimeout: threeMinutesInMiliseconds,
Has anyone else encountered this while working with Laravel/Vue and Cypress?
Related
I'm practicing documentation example of intercept and then used wait alias of intercept but it's giving this error:
CypressError: Timed out retrying after 60000ms: `cy.wait()` timed out waiting `60000ms` for the 1st response to the route: `login`. No response ever occurred.
Mine code:
it("Should redirect to '/school-admin' if School Admin is authenticated", () => {
cy.intercept('POST', `**/auth/local`).as('login')
cy.visit('/')
cy.get(textboxSelector).click()
cy.wait('#login').then(interceptions => {
expect(interceptions.response.statusCode).to.equal(200)
})
})
Also, tried following code but it the same result:
it("Should redirect to '/school-admin' if School Admin is authenticated", () => {
cy.intercept('POST', `**/auth/local`).as('login')
cy.visit('/')
cy.get(textboxSelector)
.click()
.wait('#login').then(interceptions => {
expect(interceptions.response.statusCode).to.equal(200)
})
})
Locally works perfect, but when GH actions starting work - tests were failing randomly but the error remains the same.
Cypress v9.6.0 but also tried with v10 as well
I'm trying to log errors using Http Transport and it's not working properly inside the custom report EVENT_TEST_FAIL. transport.Console is logging the error when a test fails but it is not passing the data to the log server.
This is my code inside the custom reporter
runner
.on(EVENT_TEST_FAIL, (test, err) => {
ddLogger.log('error', 'HELLO')
})
Here's the code for ddLogger:
const httpTransport = new transports.Http({
host: 'http-intake.logs.datadoghq.com',
path: `/v1/input/${process.env.DATADOG_API_KEY}?ddsource=nodejs&service=PEPINO`,
ssl: true,
})
const ddLogger = createLogger({
level: 'error',
exitOnError: false,
format: format.json(),
transports: [
httpTransport,
// new transports.Console
],
})
This outputs {"level":"error","message":"HELLO"} in Console but data is not passed to log server.
Well, as it so happens you have wrongly declared your transport, which should be
transports: [ new transports.Http(httpTransport), ... ]
Hello and thanks in advance...
We have what I would consider to be a fairly standard local development environment... frontend running at localhost on one port and the API running at localhost on a different port.
SPA running locally at http://localhost:4200
Backend API running locally at http://localhost:65370
We have the need to instruct Cypress to make a PUT request to the API in order to reset some data (long running task) on the backend before the test suite runs. To accomplish this, we are using the "before" hook to call cy.request to our backend API.
The call in the "before" hook using cy.request does in fact make the request to the API running on port 65370 and responds with a 200 status.
When it gets to cy.visit in the beforeEach hook, it hangs up and cy.visit fails (even though the server at http://localhost:4200 is indeed running and functioning as expected).
However, I can "make it work" if I add cy.visit('/') BEFORE the call to cy.request in the "before" hook. Why is this? And, what is the proper way to address this?
cypress.json
{
"defaultCommandTimeout": 20000,
"requestTimeout": 20000,
"baseUrl": "http://localhost:4200"
}
mytest.spec.js
describe('MY TEST COMPONENT', () => {
before(() => {
// Un-commenting the line below allows everything to work as expected
// cy.visit('/')
cy.request({
url: 'http://localhost:65370/api/reset',
method: 'PUT',
body: <UNIMPORTANT_PAYLOAD>,
timeout: 200000
}).then(resestResponse => {
cy.log('Reset succeeded')
})
})
beforeEach(() => {
cy.visit(`/my-start-url`)
})
it('should...', function () {
expect(true).to.be(true)
})
})
I have a test that passes locally but it fail during Gitlab CI pipeline due to timeout error.
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Which way can I go through to debug this? I tried to increase defaultTimeoutInterval to 240000 in protractor configuratoin file, but nothing has changed.
Test
describe('Test', () => {
beforeAll(async () => {
console.log('1) start beforeAll');
await api_wrapper.generateAllLatestMeasureToPatient(patient); // it breaks here
console.log('2) API calls completed'); // it never gets here
await page.navigateTo();
console.log('3) end beforeAll');
});
it('should display map, edit fence button and toggle fence button', async () => {
console.log('4) start test');
// ...
});
});
In generateAllLatestMeasureToPatient() I do ten HTTP POST requests to API endpoint. In CI it stops at fourth, locally works fine.
Console output
1) start beforeAll
4) start test
I use 2 types of timeouts :
defaultTimeoutInterval: 120000,
also in
exports.config = {
allScriptsTimeout: 90000,
}
my test also used to timeout more in CI environment I started running them in headless mode with Browser window-size set and it really helped.
capabilities: {
'browserName': 'chrome'
},
'chromeOptions': {
'args': ["--headless", "--disable-gpu", "--window-size=1920,1080"]
},
}
Fairly new to Cypress and it's been smooth sailing so far until I wanted to fake out a network request. Code is like this:
describe('Some test', function(){
it('Can fake out an XHR response', function(){
cy.server()
cy.route('https://reqres.in/api/users', [{ id: 1, name: 'Pat' }]).as('getMessages')
cy.request('https://reqres.in/api/users')
cy.wait(['#getMessages'])
...
No matter what I try I get:
CypressError: Timed out retrying: cy.wait() timed out waiting 5000ms for the 1st request to the route: 'getMessages'. No request ever occurred.
What am I doing wrong here?
EDIT: I changed the code to this:
cy.server()
cy.route('https://reqres.in/api/users', [{ id: 1, name: 'Pat' }]).as('getMessages')
cy.request('https://reqres.in/api/users')
cy.wait(['#getMessages'])
But the result was as below:
As of Cypress 6.0.0 cy.intercept() is the successor to cy.route() and can be used to return an expected response as follows:
cy.intercept('GET','/api/users', expectedResult).as('interceptedRequest');
cy.wait('#interceptedRequest');
https://docs.cypress.io/api/commands/intercept