From 78be20fe4d96f4e18f0c3fdc4b98eb2c92d686bc Mon Sep 17 00:00:00 2001 From: Adam Kol <93466081+AdamKol-up9@users.noreply.github.com> Date: Wed, 2 Feb 2022 16:05:07 +0200 Subject: [PATCH] Cypress: GuiPort test fix & new check in every test (#748) --- acceptanceTests/cypress.json | 3 ++- .../integration/testHelpers/TrafficHelper.js | 12 ++++++++++ .../cypress/integration/tests/GuiPort.js | 20 +++++++++++----- .../integration/tests/IgnoredUserAgents.js | 24 +++++++++---------- .../cypress/integration/tests/NoRedact.js | 6 +++-- .../cypress/integration/tests/Redact.js | 6 +++-- .../cypress/integration/tests/RegexMasking.js | 6 +++-- .../cypress/integration/tests/UiTest.js | 7 +++--- acceptanceTests/tap_test.go | 11 ++++++++- 9 files changed, 65 insertions(+), 30 deletions(-) diff --git a/acceptanceTests/cypress.json b/acceptanceTests/cypress.json index 348434fab..fa0878eea 100644 --- a/acceptanceTests/cypress.json +++ b/acceptanceTests/cypress.json @@ -20,6 +20,7 @@ "testUrl": "http://localhost:8899/", "redactHeaderContent": "User-Header[REDACTED]", "redactBodyContent": "{ \"User\": \"[REDACTED]\" }", - "regexMaskingBodyContent": "[REDACTED]" + "regexMaskingBodyContent": "[REDACTED]", + "minimumEntries": 25 } } diff --git a/acceptanceTests/cypress/integration/testHelpers/TrafficHelper.js b/acceptanceTests/cypress/integration/testHelpers/TrafficHelper.js index 02ac41611..e280c6c2e 100644 --- a/acceptanceTests/cypress/integration/testHelpers/TrafficHelper.js +++ b/acceptanceTests/cypress/integration/testHelpers/TrafficHelper.js @@ -16,3 +16,15 @@ export function resizeToNormalMizu() { cy.viewport(1920, 1080); } +export function verifyMinimumEntries() { + const minimumEntries = Cypress.env('minimumEntries'); + it(`Making sure that mizu shows at least ${minimumEntries} entries`, async function () { + cy.get('#total-entries').then(number => { + const getNum = () => { + const numOfEntries = number.text(); + return parseInt(numOfEntries); + }; + cy.wrap({ there: getNum }).invoke('there').should('be.gte', minimumEntries); + }); + }); +} diff --git a/acceptanceTests/cypress/integration/tests/GuiPort.js b/acceptanceTests/cypress/integration/tests/GuiPort.js index b96cf1b40..4cd0705e5 100644 --- a/acceptanceTests/cypress/integration/tests/GuiPort.js +++ b/acceptanceTests/cypress/integration/tests/GuiPort.js @@ -1,8 +1,16 @@ -it('check', function () { - cy.visit(`http://localhost:${Cypress.env('port')}/`); +import {findLineAndCheck, getExpectedDetailsDict} from "../testHelpers/StatusBarHelper"; +import {verifyMinimumEntries} from "../testHelpers/TrafficHelper"; - cy.get('.header').should('be.visible'); - cy.get('.TrafficPageHeader').should('be.visible'); - cy.get('.TrafficPage-ListContainer').should('be.visible'); - cy.get('.TrafficPage-Container').should('be.visible'); +it('check', function () { + const podName = Cypress.env('name'), namespace = Cypress.env('namespace'); + const port = Cypress.env('port'); + cy.intercept('GET', `http://localhost:${port}/status/tap`).as('statusTap'); + + cy.visit(`http://localhost:${port}`); + cy.wait('@statusTap').its('response.statusCode').should('match', /^2\d{2}/); + + verifyMinimumEntries(); + + cy.get('.podsCount').trigger('mouseover'); + findLineAndCheck(getExpectedDetailsDict(podName, namespace)); }); diff --git a/acceptanceTests/cypress/integration/tests/IgnoredUserAgents.js b/acceptanceTests/cypress/integration/tests/IgnoredUserAgents.js index 8e8fc98cb..7948a70a0 100644 --- a/acceptanceTests/cypress/integration/tests/IgnoredUserAgents.js +++ b/acceptanceTests/cypress/integration/tests/IgnoredUserAgents.js @@ -1,24 +1,24 @@ -import {isValueExistsInElement, resizeToHugeMizu} from "../testHelpers/TrafficHelper"; +import {isValueExistsInElement, resizeToHugeMizu, verifyMinimumEntries} from "../testHelpers/TrafficHelper"; it('Loading Mizu', function () { cy.visit(Cypress.env('testUrl')); }); -it('going through each entry', function () { - resizeToHugeMizu(); - cy.get('#total-entries').then(number => { - const getNum = () => { - const numOfEntries = number.text(); - return parseInt(numOfEntries); - }; - cy.wrap({ there: getNum }).invoke('there').should('be.gte', 25); +verifyMinimumEntries(); +checkEntries(); + +function checkEntries() { + it('checking all entries', function () { checkThatAllEntriesShown(); + resizeToHugeMizu(); - const entriesNum = getNum(); - [...Array(entriesNum).keys()].map(checkEntry); + cy.get('#total-entries').then(number => { + const numOfEntries = parseInt(number.text()); + [...Array(numOfEntries).keys()].map(checkEntry); + }); }); -}); +} function checkThatAllEntriesShown() { cy.get('#entries-length').then(number => { diff --git a/acceptanceTests/cypress/integration/tests/NoRedact.js b/acceptanceTests/cypress/integration/tests/NoRedact.js index c76c5c65d..5ade83cf5 100644 --- a/acceptanceTests/cypress/integration/tests/NoRedact.js +++ b/acceptanceTests/cypress/integration/tests/NoRedact.js @@ -1,8 +1,10 @@ -import {isValueExistsInElement} from '../testHelpers/TrafficHelper'; +import {isValueExistsInElement, verifyMinimumEntries} from '../testHelpers/TrafficHelper'; it('Loading Mizu', function () { cy.visit(Cypress.env('testUrl')); -}) +}); + +verifyMinimumEntries(); isValueExistsInElement(false, Cypress.env('redactHeaderContent'), '#tbody-Headers'); isValueExistsInElement(false, Cypress.env('redactBodyContent'), '.hljs'); diff --git a/acceptanceTests/cypress/integration/tests/Redact.js b/acceptanceTests/cypress/integration/tests/Redact.js index 293ebfd14..45fd9e4aa 100644 --- a/acceptanceTests/cypress/integration/tests/Redact.js +++ b/acceptanceTests/cypress/integration/tests/Redact.js @@ -1,8 +1,10 @@ -import {isValueExistsInElement} from '../testHelpers/TrafficHelper'; +import {isValueExistsInElement, verifyMinimumEntries} from '../testHelpers/TrafficHelper'; it('Loading Mizu', function () { cy.visit(Cypress.env('testUrl')); -}) +}); + +verifyMinimumEntries(); isValueExistsInElement(true, Cypress.env('redactHeaderContent'), '#tbody-Headers'); isValueExistsInElement(true, Cypress.env('redactBodyContent'), '.hljs'); diff --git a/acceptanceTests/cypress/integration/tests/RegexMasking.js b/acceptanceTests/cypress/integration/tests/RegexMasking.js index 2eb620f64..de8676a76 100644 --- a/acceptanceTests/cypress/integration/tests/RegexMasking.js +++ b/acceptanceTests/cypress/integration/tests/RegexMasking.js @@ -1,7 +1,9 @@ -import {isValueExistsInElement} from "../testHelpers/TrafficHelper"; +import {isValueExistsInElement, verifyMinimumEntries} from "../testHelpers/TrafficHelper"; it('Loading Mizu', function () { cy.visit(Cypress.env('testUrl')); -}) +}); + +verifyMinimumEntries(); isValueExistsInElement(true, Cypress.env('regexMaskingBodyContent'), '.hljs'); diff --git a/acceptanceTests/cypress/integration/tests/UiTest.js b/acceptanceTests/cypress/integration/tests/UiTest.js index 101a62830..6baf0a523 100644 --- a/acceptanceTests/cypress/integration/tests/UiTest.js +++ b/acceptanceTests/cypress/integration/tests/UiTest.js @@ -1,5 +1,5 @@ import {findLineAndCheck, getExpectedDetailsDict} from "../testHelpers/StatusBarHelper"; -import {resizeToHugeMizu, resizeToNormalMizu} from "../testHelpers/TrafficHelper"; +import {resizeToHugeMizu, resizeToNormalMizu, verifyMinimumEntries} from "../testHelpers/TrafficHelper"; const greenFilterColor = 'rgb(210, 250, 210)'; const redFilterColor = 'rgb(250, 214, 220)'; const refreshWaitTimeout = 10000; @@ -9,6 +9,8 @@ it('opening mizu', function () { cy.visit(Cypress.env('testUrl')); }); +verifyMinimumEntries(); + it('top bar check', function () { const podName1 = 'httpbin', namespace1 = 'mizu-tests'; const podName2 = 'httpbin2', namespace2 = 'mizu-tests'; @@ -229,7 +231,6 @@ function deeperChcek(leftSidePath, rightSidePath, filterName, leftSideExpectedTe cy.get(`#list #entry-${entryNum}`).click(); rightTextCheck(rightSidePath, rightSideExpectedText); rightOnHoverCheck(rightSidePath, filterName); - checkRightSideResponseBody(); }); } @@ -258,8 +259,6 @@ function checkRightSideResponseBody() { cy.get(`${bodyJsonClass}`).then(value => { const encodedBody = value.text(); - cy.log(encodedBody); - const decodedBody = atob(encodedBody); const responseBody = JSON.parse(decodedBody); diff --git a/acceptanceTests/tap_test.go b/acceptanceTests/tap_test.go index ede2ca766..3840f7799 100644 --- a/acceptanceTests/tap_test.go +++ b/acceptanceTests/tap_test.go @@ -110,7 +110,16 @@ func TestTapGuiPort(t *testing.T) { return } - runCypressTests(t, fmt.Sprintf("npx cypress run --spec \"cypress/integration/tests/GuiPort.js\" --env port=%d", guiPort)) + proxyUrl := getProxyUrl(defaultNamespaceName, defaultServiceName) + for i := 0; i < defaultEntriesCount; i++ { + if _, requestErr := executeHttpGetRequest(fmt.Sprintf("%v/get", proxyUrl)); requestErr != nil { + t.Errorf("failed to send proxy request, err: %v", requestErr) + return + } + } + + runCypressTests(t, fmt.Sprintf("npx cypress run --spec \"cypress/integration/tests/GuiPort.js\" --env name=%v,namespace=%v,port=%d", + "httpbin", "mizu-tests", guiPort)) }) } }