From 46df5b069446237910aa22c01a0c635d10d87d7e Mon Sep 17 00:00:00 2001 From: Alex Grozav Date: Thu, 15 Jun 2023 14:40:23 +0300 Subject: [PATCH] fix: Fix randomly failing scheduler node e2e tests (no-changelog) (#6430) * fix: fix randomly failing scheduler node e2e tests (no-changelog) * chore: rename variable name * fix: update all cy.request calls to use backend base url * fix: add back mistkenly removed workflowId code * fix: remove unnecessary .then * fix: update how workflowId is retrieved --- cypress/constants.ts | 2 + cypress/e2e/15-scheduler-node.cy.ts | 63 +++++++++++++---------------- cypress/e2e/16-webhook-node.cy.ts | 32 +++++++-------- 3 files changed, 44 insertions(+), 53 deletions(-) diff --git a/cypress/constants.ts b/cypress/constants.ts index 5118696bc81d3..a7e29665774de 100644 --- a/cypress/constants.ts +++ b/cypress/constants.ts @@ -1,3 +1,5 @@ +export const BACKEND_BASE_URL = 'http://localhost:5678'; + export const N8N_AUTH_COOKIE = 'n8n-auth'; export const DEFAULT_USER_EMAIL = 'nathan@n8n.io'; diff --git a/cypress/e2e/15-scheduler-node.cy.ts b/cypress/e2e/15-scheduler-node.cy.ts index b59db99ba5ea6..8ad0b8ad95525 100644 --- a/cypress/e2e/15-scheduler-node.cy.ts +++ b/cypress/e2e/15-scheduler-node.cy.ts @@ -1,6 +1,7 @@ import { randFirstName, randLastName } from '@ngneat/falso'; import { DEFAULT_USER_EMAIL, DEFAULT_USER_PASSWORD } from '../constants'; import { WorkflowPage, WorkflowsPage, NDV } from '../pages'; +import { BACKEND_BASE_URL } from '../constants'; const workflowsPage = new WorkflowsPage(); const workflowPage = new WorkflowPage(); @@ -47,44 +48,34 @@ describe('Schedule Trigger node', async () => { workflowPage.actions.activateWorkflow(); workflowPage.getters.activatorSwitch().should('have.class', 'is-checked'); - cy.request('GET', '/rest/workflows') - .then((response) => { + cy.url().then((url) => { + const workflowId = url.split('/').pop(); + + cy.wait(1200); + cy.request('GET', `${BACKEND_BASE_URL}/rest/executions`).then((response) => { expect(response.status).to.eq(200); - expect(response.body.data).to.have.length(1); - const workflowId = response.body.data[0].id.toString(); - expect(workflowId).to.not.be.empty; - return workflowId; - }) - .then((workflowId) => { + expect(workflowId).to.not.be.undefined; + expect(response.body.data.results.length).to.be.greaterThan(0); + const matchingExecutions = response.body.data.results.filter( + (execution: any) => execution.workflowId === workflowId, + ); + expect(matchingExecutions).to.have.length(1); + cy.wait(1200); - cy.request('GET', '/rest/executions') - .then((response) => { - expect(response.status).to.eq(200); - expect(response.body.data.results.length).to.be.greaterThan(0); - const matchingExecutions = response.body.data.results.filter( - (execution: any) => execution.workflowId === workflowId, - ); - expect(matchingExecutions).to.have.length(1); - return workflowId; - }) - .then((workflowId) => { - cy.wait(1200); - cy.request('GET', '/rest/executions') - .then((response) => { - expect(response.status).to.eq(200); - expect(response.body.data.results.length).to.be.greaterThan(0); - const matchingExecutions = response.body.data.results.filter( - (execution: any) => execution.workflowId === workflowId, - ); - expect(matchingExecutions).to.have.length(2); - }) - .then(() => { - workflowPage.actions.activateWorkflow(); - workflowPage.getters.activatorSwitch().should('not.have.class', 'is-checked'); - cy.visit(workflowsPage.url); - workflowsPage.actions.deleteWorkFlow('Schedule Trigger Workflow'); - }); - }); + cy.request('GET', `${BACKEND_BASE_URL}/rest/executions`).then((response) => { + expect(response.status).to.eq(200); + expect(response.body.data.results.length).to.be.greaterThan(0); + const matchingExecutions = response.body.data.results.filter( + (execution: any) => execution.workflowId === workflowId, + ); + expect(matchingExecutions).to.have.length(2); + + workflowPage.actions.activateWorkflow(); + workflowPage.getters.activatorSwitch().should('not.have.class', 'is-checked'); + cy.visit(workflowsPage.url); + workflowsPage.actions.deleteWorkFlow('Schedule Trigger Workflow'); + }); }); + }); }); }); diff --git a/cypress/e2e/16-webhook-node.cy.ts b/cypress/e2e/16-webhook-node.cy.ts index a5e0dbe0f48a7..ebd9d6a766672 100644 --- a/cypress/e2e/16-webhook-node.cy.ts +++ b/cypress/e2e/16-webhook-node.cy.ts @@ -2,7 +2,7 @@ import { WorkflowPage, NDV, CredentialsModal } from '../pages'; import { v4 as uuid } from 'uuid'; import { cowBase64 } from '../support/binaryTestFiles'; import { randFirstName, randLastName } from '@ngneat/falso'; -import { DEFAULT_USER_EMAIL, DEFAULT_USER_PASSWORD } from '../constants'; +import { BACKEND_BASE_URL, DEFAULT_USER_EMAIL, DEFAULT_USER_PASSWORD } from '../constants'; const email = DEFAULT_USER_EMAIL; const password = DEFAULT_USER_PASSWORD; @@ -90,7 +90,7 @@ const simpleWebhookCall = (options: SimpleWebhookCallOptions) => { ndv.actions.execute(); cy.wait(waitForWebhook); - cy.request(method, '/webhook-test/' + webhookPath).then((response) => { + cy.request(method, `${BACKEND_BASE_URL}/webhook-test/${webhookPath}`).then((response) => { expect(response.status).to.eq(200); ndv.getters.outputPanel().contains('headers'); }); @@ -106,12 +106,10 @@ describe('Webhook Trigger node', async () => { cy.signin({ email, password }); workflowPage.actions.visit(); - cy.window().then( - (win) => { - // @ts-ignore - win.preventNodeViewBeforeUnload = true; - }, - ); + cy.window().then((win) => { + // @ts-ignore + win.preventNodeViewBeforeUnload = true; + }); }); it('should listen for a GET request', () => { @@ -162,7 +160,7 @@ describe('Webhook Trigger node', async () => { workflowPage.actions.executeWorkflow(); cy.wait(waitForWebhook); - cy.request('GET', '/webhook-test/' + webhookPath).then((response) => { + cy.request('GET', `${BACKEND_BASE_URL}/webhook-test/${webhookPath}`).then((response) => { expect(response.status).to.eq(200); expect(response.body.MyValue).to.eq(1234); }); @@ -180,7 +178,7 @@ describe('Webhook Trigger node', async () => { ndv.actions.execute(); cy.wait(waitForWebhook); - cy.request('GET', '/webhook-test/' + webhookPath).then((response) => { + cy.request('GET', `${BACKEND_BASE_URL}/webhook-test/${webhookPath}`).then((response) => { expect(response.status).to.eq(201); }); }); @@ -209,7 +207,7 @@ describe('Webhook Trigger node', async () => { workflowPage.actions.executeWorkflow(); cy.wait(waitForWebhook); - cy.request('GET', '/webhook-test/' + webhookPath).then((response) => { + cy.request('GET', `${BACKEND_BASE_URL}/webhook-test/${webhookPath}`).then((response) => { expect(response.status).to.eq(200); expect(response.body.MyValue).to.eq(1234); }); @@ -254,7 +252,7 @@ describe('Webhook Trigger node', async () => { workflowPage.actions.executeWorkflow(); cy.wait(waitForWebhook); - cy.request('GET', '/webhook-test/' + webhookPath).then((response) => { + cy.request('GET', `${BACKEND_BASE_URL}/webhook-test/${webhookPath}`).then((response) => { expect(response.status).to.eq(200); expect(Object.keys(response.body).includes('data')).to.be.true; }); @@ -271,7 +269,7 @@ describe('Webhook Trigger node', async () => { }); ndv.actions.execute(); cy.wait(waitForWebhook); - cy.request('GET', '/webhook-test/' + webhookPath).then((response) => { + cy.request('GET', `${BACKEND_BASE_URL}/webhook-test/${webhookPath}`).then((response) => { expect(response.status).to.eq(200); expect(response.body.MyValue).to.be.undefined; }); @@ -295,7 +293,7 @@ describe('Webhook Trigger node', async () => { cy.wait(waitForWebhook); cy.request({ method: 'GET', - url: '/webhook-test/' + webhookPath, + url: `${BACKEND_BASE_URL}/webhook-test/${webhookPath}`, auth: { user: 'username', pass: 'password', @@ -308,7 +306,7 @@ describe('Webhook Trigger node', async () => { .then(() => { cy.request({ method: 'GET', - url: '/webhook-test/' + webhookPath, + url: `${BACKEND_BASE_URL}/webhook-test/${webhookPath}`, auth: { user: 'test', pass: 'test', @@ -338,7 +336,7 @@ describe('Webhook Trigger node', async () => { cy.wait(waitForWebhook); cy.request({ method: 'GET', - url: '/webhook-test/' + webhookPath, + url: `${BACKEND_BASE_URL}/webhook-test/${webhookPath}`, headers: { test: 'wrong', }, @@ -350,7 +348,7 @@ describe('Webhook Trigger node', async () => { .then(() => { cy.request({ method: 'GET', - url: '/webhook-test/' + webhookPath, + url: `${BACKEND_BASE_URL}/webhook-test/${webhookPath}`, headers: { test: 'test', },