From 014cc756bcebec850df31e013f6b620bc6b0c47a Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Mon, 12 Dec 2022 00:22:31 -0800 Subject: [PATCH] Only run css selector identifier tests to run on desktop --- .../offline/05_offline_identifier_check.cy.js | 48 ++++++++++--------- .../online/05_online_identifier_check.cy.js | 20 ++++---- .../browser/cypress/support/filterTests.js | 24 ++++++++++ test/automated/browser/run.sh | 4 +- 4 files changed, 64 insertions(+), 32 deletions(-) create mode 100644 test/automated/browser/cypress/support/filterTests.js diff --git a/test/automated/browser/cypress/e2e/offline/05_offline_identifier_check.cy.js b/test/automated/browser/cypress/e2e/offline/05_offline_identifier_check.cy.js index 23f456876..a79948cbe 100644 --- a/test/automated/browser/cypress/e2e/offline/05_offline_identifier_check.cy.js +++ b/test/automated/browser/cypress/e2e/offline/05_offline_identifier_check.cy.js @@ -6,6 +6,8 @@ These should be documented so people know how to customize their pages. If you change one of these identifiers, you must update the documentation. */ +import filterTests from '../../support/filterTests'; + const identifiers = [ 'header', // The entire header component 'footer', // The entire footer component @@ -16,29 +18,31 @@ const identifiers = [ '#follow-button', // The follow button ]; -describe(`Has correct identifiers for overrides`, () => { - it('Can visit the page', () => { - cy.visit('http://localhost:8080/'); - }); +filterTests(['desktop'], () => { + describe(`Has correct identifiers for overrides`, () => { + it('Can visit the page', () => { + cy.visit('http://localhost:8080/'); + }); - // Loop over each identifier and verify it exists. - identifiers.forEach((identifier) => { - it(`Has identifier: ${identifier}`, () => { - cy.get(identifier).should('be.visible'); + // Loop over each identifier and verify it exists. + identifiers.forEach((identifier) => { + it(`Has identifier: ${identifier}`, () => { + cy.get(identifier).should('be.visible'); + }); + }); + + // Followers + const followersCollection = '#followers-collection'; + it(`Has identifier: ${followersCollection}`, () => { + cy.contains('Followers').click(); + cy.get(followersCollection).should('be.visible'); + }); + + // Modal + const modalContainer = '#modal-container'; + it(`Has identifier ${modalContainer}`, () => { + cy.contains('Notify').click(); + cy.get(modalContainer, { timeout: 2000 }).should('be.visible'); }); }); - - // Followers - const followersCollection = '#followers-collection'; - it(`Has identifier: ${followersCollection}`, () => { - cy.contains('Followers').click(); - cy.get(followersCollection).should('be.visible'); - }); - - // Modal - const modalContainer = '#modal-container'; - it(`Has identifier ${modalContainer}`, () => { - cy.contains('Notify').click(); - cy.get(modalContainer, { timeout: 2000 }).should('be.visible'); - }); }); diff --git a/test/automated/browser/cypress/e2e/online/05_online_identifier_check.cy.js b/test/automated/browser/cypress/e2e/online/05_online_identifier_check.cy.js index fae6c21cc..321a1591d 100644 --- a/test/automated/browser/cypress/e2e/online/05_online_identifier_check.cy.js +++ b/test/automated/browser/cypress/e2e/online/05_online_identifier_check.cy.js @@ -6,19 +6,23 @@ These should be documented so people know how to customize their pages. If you change one of these identifiers, you must update the documentation. */ +import filterTests from '../../support/filterTests'; + const identifiers = [ '#chat-container', // The entire chat container component ]; -describe(`Has correct identifiers for overrides`, () => { - it('Can visit the page', () => { - cy.visit('http://localhost:8080/'); - }); +filterTests(['desktop'], () => { + describe(`Has correct identifiers for overrides`, () => { + it('Can visit the page', () => { + cy.visit('http://localhost:8080/'); + }); - // Loop over each identifier and verify it exists. - identifiers.forEach((identifier) => { - it(`Has identifier: ${identifier}`, () => { - cy.get(identifier).should('be.visible'); + // Loop over each identifier and verify it exists. + identifiers.forEach((identifier) => { + it(`Has identifier: ${identifier}`, () => { + cy.get(identifier).should('be.visible'); + }); }); }); }); diff --git a/test/automated/browser/cypress/support/filterTests.js b/test/automated/browser/cypress/support/filterTests.js new file mode 100644 index 000000000..198b08634 --- /dev/null +++ b/test/automated/browser/cypress/support/filterTests.js @@ -0,0 +1,24 @@ +/// + +/** + * Filter Cypress tests based on a given tag or tags. If no tags are present, run tests. + * + * @param {[string]} definedTags An array of tags + * @param {Function} runTest All tests captured within a Cypress run + * @example npm run open --env tags=api + * @example npm run open --env tags=api/ui + */ +const filterTests = (definedTags, runTest) => { + if (Cypress.env('tags')) { + const tags = Cypress.env('tags').split('/'); + const found = definedTags.some(($definedTag) => tags.includes($definedTag)); + + if (found) { + runTest(); + } + } else { + // runTest(); + } +}; + +export default filterTests; diff --git a/test/automated/browser/run.sh b/test/automated/browser/run.sh index fe7e48673..27fce4e09 100755 --- a/test/automated/browser/run.sh +++ b/test/automated/browser/run.sh @@ -42,7 +42,7 @@ SERVER_PID=$! pushd test/automated/browser # Run cypress browser tests for desktop -npx cypress run --group "desktop-offline" --ci-build-id $BUILD_ID --tag "desktop,offline" --record --key e9c8b547-7a8f-452d-8c53-fd7531491e3b --spec "cypress/e2e/offline/*.cy.js" +npx cypress run --group "desktop-offline" --env tags=desktop --ci-build-id $BUILD_ID --tag "desktop,offline" --record --key e9c8b547-7a8f-452d-8c53-fd7531491e3b --spec "cypress/e2e/offline/*.cy.js" # Run cypress browser tests for mobile npx cypress run --group "mobile-offline" --ci-build-id $BUILD_ID --tag "mobile,offline" --record --key e9c8b547-7a8f-452d-8c53-fd7531491e3b --spec "cypress/e2e/offline/*.cy.js" --config viewportWidth=375,viewportHeight=667 @@ -62,6 +62,6 @@ trap finish EXIT SIGHUP SIGINT SIGTERM SIGQUIT SIGABRT SIGTERM sleep 20 # Run cypress browser tests for desktop -npx cypress run --group "desktop-online" --ci-build-id $BUILD_ID --tag "desktop,online" --record --key e9c8b547-7a8f-452d-8c53-fd7531491e3b --spec "cypress/e2e/online/*.cy.js" +npx cypress run --group "desktop-online" --env tags=desktop --ci-build-id $BUILD_ID --tag "desktop,online" --record --key e9c8b547-7a8f-452d-8c53-fd7531491e3b --spec "cypress/e2e/online/*.cy.js" # Run cypress browser tests for mobile npx cypress run --group "mobile-online" --ci-build-id $BUILD_ID --tag "mobile,online" --record --key e9c8b547-7a8f-452d-8c53-fd7531491e3b --spec "cypress/e2e/online/*.cy.js" --config viewportWidth=375,viewportHeight=667