From b31ef68fece5fb6256e0d5dd1218d1eb3f29d204 Mon Sep 17 00:00:00 2001 From: nateekar Date: Fri, 5 Jan 2024 16:11:20 -0800 Subject: [PATCH 1/6] Milo Libs runs --- .github/workflows/milolib.yml | 52 ++++++++++++++++++++++++++++++ tests/milo/accordion.block.test.js | 7 ++-- 2 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/milolib.yml diff --git a/.github/workflows/milolib.yml b/.github/workflows/milolib.yml new file mode 100644 index 00000000..78a3e688 --- /dev/null +++ b/.github/workflows/milolib.yml @@ -0,0 +1,52 @@ +name: Run Nala on Milo Libs Manually + +on: + workflow_dispatch: + inputs: + branch: + description: 'Provide the branch url' + required: false + type: string + milolibs: + description: 'Provide MiloLibs param' + required: false + type: string + tags: + description: 'Test scenario tags, if empty all tests will run. i.e., @marquee' + required: false + type: string + platform: + description: 'Platform to run tests on; select one, options: [ubuntu-latest, windows-latest, macos-latest]' + required: true + type: string + +jobs: + action: + name: Running tests + runs-on: ${{ inputs.platform }} + + steps: + - name: Check out repository + uses: actions/checkout@v3 + - name: Set permissions + run: chmod +x ./path/to/run.sh + - name: Set environment variables + run: | + echo "PR_BRANCH_LIVE_URL_GH=${{ github.event.inputs.branch }}" >> $GITHUB_ENV + echo "MILO_LIBS=${{ github.event.inputs.milolibs }}" >> $GITHUB_ENV + + - name: Run Nala ${{ inputs.platform }} + uses: ./ + env: + labels: ${{ inputs.tags }} + IMS_EMAIL: ${{ secrets.IMS_EMAIL }} + IMS_PASS: ${{ secrets.IMS_PASS }} + HLX_TKN: ${{ secrets.HLX_TKN }} + SLACK_WH: ${{ secrets.SLACK_WH }} + - name: Persist JSON Artifact + uses: actions/upload-artifact@v3 + if: always() + with: + name: nala-results + path: nala-results.json + retention-days: 30 diff --git a/tests/milo/accordion.block.test.js b/tests/milo/accordion.block.test.js index efdda553..b57b5cda 100644 --- a/tests/milo/accordion.block.test.js +++ b/tests/milo/accordion.block.test.js @@ -6,6 +6,7 @@ import AccordionBlock from '../../selectors/milo/accordion.block.page.js'; let webUtil; let accordion; let consoleErrors = []; +let miloLib = '?milolibs=stage'; const knownConsoleErrors = ['Access-Control-Allow-Origin','Failed to load resource: net::ERR_FAILED']; test.describe('Milo Accordion Block test suite', () => { @@ -26,13 +27,13 @@ test.describe('Milo Accordion Block test suite', () => { // Test 0 : Accordion test(`${features[0].name},${features[0].tags}`, async ({ page, baseURL }) => { - console.info(`[Test Page]: ${baseURL}${features[0].path}`); + console.info(`[Test Page]: ${baseURL}${features[0].path}${miloLib}`); const { data } = features[0]; await test.step('step-1: Go to Accordion block test page', async () => { - await page.goto(`${baseURL}${features[0].path}`); + await page.goto(`${baseURL}${features[0].path}${miloLib}`); await page.waitForLoadState('domcontentloaded'); - await expect(page).toHaveURL(`${baseURL}${features[0].path}`); + await expect(page).toHaveURL(`${baseURL}${features[0].path}${miloLib}`); }); await test.step('step-2: Verify Accrodion block content/specs', async () => { From 2174d0922ff7792f450d7c46f6a21a0c7d3b52e6 Mon Sep 17 00:00:00 2001 From: nateekar Date: Sat, 6 Jan 2024 12:33:11 -0800 Subject: [PATCH 2/6] milo libs run test --- .github/workflows/milolib.yml | 10 +- global.setup_1.js | 148 +++++++++++++++++++++++++++++ playwright.config.js | 2 +- tests/milo/accordion.block.test.js | 20 ++-- 4 files changed, 165 insertions(+), 15 deletions(-) create mode 100644 global.setup_1.js diff --git a/.github/workflows/milolib.yml b/.github/workflows/milolib.yml index 78a3e688..8e8d0392 100644 --- a/.github/workflows/milolib.yml +++ b/.github/workflows/milolib.yml @@ -24,17 +24,19 @@ jobs: action: name: Running tests runs-on: ${{ inputs.platform }} + env: + WORKFLOW_NAME: 'Milo Libs Run' + MILO_LIBS_RUN: 'true' steps: - name: Check out repository uses: actions/checkout@v3 - - name: Set permissions - run: chmod +x ./path/to/run.sh + - name: Set environment variables run: | - echo "PR_BRANCH_LIVE_URL_GH=${{ github.event.inputs.branch }}" >> $GITHUB_ENV + echo "PR_BRANCH_MILOLIBS_LIVE_URL=${{ github.event.inputs.branch }}" >> $GITHUB_ENV echo "MILO_LIBS=${{ github.event.inputs.milolibs }}" >> $GITHUB_ENV - + - name: Run Nala ${{ inputs.platform }} uses: ./ env: diff --git a/global.setup_1.js b/global.setup_1.js new file mode 100644 index 00000000..d64fba30 --- /dev/null +++ b/global.setup_1.js @@ -0,0 +1,148 @@ +import { exit } from 'process'; +const { execSync } = require('child_process'); +const { isBranchURLValid } = require('./libs/baseurl.js'); +const axios = require('axios'); + +async function getGitHubPRBranchLiveUrl() { + // get the pr number + const prReference = process.env.GITHUB_REF; + const prNumber = prReference.split('/')[2]; + + // get the pr branch name + const branch = process.env.GITHUB_HEAD_REF; + const prBranch = branch.replace(/\//g, '-'); + + // get the org and repo + const repository = process.env.GITHUB_REPOSITORY; + const repoParts = repository.split('/'); + const toRepoOrg = repoParts[0]; + const toRepoName = repoParts[1]; + + // Get the org and repo from the environment variables + const prFromOrg = process.env.prOrg; + const prFromRepoName = process.env.prRepo; + + let prBranchLiveUrl; + + if (toRepoName === 'nala' || toRepoName === 'janus') { + prBranchLiveUrl = `https://main--milo--adobecom.hlx.live`; + } else { + prBranchLiveUrl = `https://${prBranch}--${prFromRepoName}--${prFromOrg}.hlx.live`; + } + + try { + if (await isBranchURLValid(prBranchLiveUrl)) { + process.env.PR_BRANCH_LIVE_URL = prBranchLiveUrl; + } + console.info('PR Repository : ', repository); + console.info('PR TO ORG : ', toRepoOrg); + console.info('PR TO REPO : ', toRepoName); + console.info('PR From ORG : ', prFromOrg); + console.info('PR From REPO : ', prFromRepoName); + console.info('PR Branch : ', branch); + console.info('PR Branch(U) : ', prBranch); + console.info('PR Number : ', prNumber); + console.info('PR From Branch live url : ', prBranchLiveUrl); + } catch (err) { + console.error(`Error => Error in setting PR Branch test URL : ${prBranchLiveUrl}`); + console.info(`Note: PR branch test url ${prBranchLiveUrl} is not valid, Exiting test execution.`); + process.exit(1); + } +} + +async function getGitHubMiloLibsBranchLiveUrl() { + const repository = process.env.GITHUB_REPOSITORY; + + let prBranchLiveUrl; + let miloLibs; + + prBranchLiveUrl = process.env.PR_BRANCH_MILOLIBS_LIVE_URL; + miloLibs = process.env.MILO_LIBS; + + try { + if (await isBranchURLValid(prBranchLiveUrl)) { + process.env.PR_BRANCH_LIVE_URL = prBranchLiveUrl; + process.env.MILO_LIBS = prBranchLiveUrl; + } + console.info('PR Repository : ', repository); + console.info('PR Branch live url : ', prBranchLiveUrl); + console.info('Milo Libs : ', miloLibs); + } catch (err) { + console.error(`Error => Error in setting PR Branch test URL : ${prBranchLiveUrl}`); + console.info(`Note: PR branch test url ${prBranchLiveUrl} is not valid, Exiting test execution.`); + process.exit(1); + } +} + +async function getCircleCIBranchLiveUrl() { + const stageBranchLiveUrl = 'https://milo.stage.adobe.com'; + + try { + if (await isBranchURLValid(stageBranchLiveUrl)) { + process.env.PR_BRANCH_LIVE_URL = stageBranchLiveUrl; + } + console.info('Stage Branch Live URL : ', stageBranchLiveUrl); + } catch (err) { + console.error('Error => Error in setting Stage Branch test URL : ', stageBranchLiveUrl); + console.info('Note: Stage branch test url is not valid, Exiting test execution.'); + process.exit(1); + } +} + +async function getLocalBranchLiveUrl() { + try { + const localGitRootDir = execSync('git rev-parse --show-toplevel', { encoding: 'utf-8' }).trim(); + + if (localGitRootDir) { + const gitRemoteOriginUrl = execSync('git config --get remote.origin.url', { cwd: localGitRootDir, encoding: 'utf-8' }).trim(); + const match = gitRemoteOriginUrl.match(/github\.com\/(.*?)\/(.*?)\.git/); + + if (match) { + const [localOrg, localRepo] = match.slice(1, 3); + const localBranch = execSync('git rev-parse --abbrev-ref HEAD', { cwd: localGitRootDir, encoding: 'utf-8' }).trim(); + let localTestLiveUrl; + + if (localRepo === 'nala' || localRepo === 'janus') { + localTestLiveUrl = `https://main--milo--adobecom.hlx.live`; + process.env.MILO_LIBS = '?milolibs=stage'; + } else { + localTestLiveUrl = `http://localhost:3000`; + } + + if (await isBranchURLValid(localTestLiveUrl)) { + process.env.LOCAL_TEST_LIVE_URL = localTestLiveUrl; + } + console.info('Git ORG : ', localOrg); + console.info('Git REPO : ', localRepo); + console.info('Local Branch : ', localBranch); + console.info('Local Test Live URL : ', process.env.LOCAL_TEST_LIVE_URL); + } + } + } catch (error) { + console.error(`Error => Error in setting local test URL : ${localTestLiveUrl}`); + console.info(`Note: Local or branch test url is not valid, Exiting test execution.`); + process.exit(1); + } +} + +async function globalSetup() { + console.info('----Executing Global setup---------'); + + if (process.env.GITHUB_ACTIONS === 'true') { + console.info('---- Running Tests in the GitHub environment ---------'); + + if (process.env.MILO_LIBS_RUN === 'true') { + await getGitHubMiloLibsBranchLiveUrl(); + } else { + await getGitHubPRBranchLiveUrl(); + } + } else if (process.env.CIRCLECI) { + console.info('---- Running Tests in the CircleCI environment ---------'); + await getCircleCIBranchLiveUrl(); + } else { + console.info('---- Running Tests in the Local environment ---------'); + await getLocalBranchLiveUrl(); + } +} + +export default globalSetup; diff --git a/playwright.config.js b/playwright.config.js index 0f656c10..6f89ad59 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -9,7 +9,7 @@ const envs = require('./envs/envs.js'); const config = { testDir: './tests/milo', outputDir: './test-results', - globalSetup: './global.setup.js', + globalSetup: './global.setup_1.js', /* Maximum time one test can run for. */ timeout: 30 * 1000, expect: { diff --git a/tests/milo/accordion.block.test.js b/tests/milo/accordion.block.test.js index b57b5cda..9d0e8a63 100644 --- a/tests/milo/accordion.block.test.js +++ b/tests/milo/accordion.block.test.js @@ -6,7 +6,7 @@ import AccordionBlock from '../../selectors/milo/accordion.block.page.js'; let webUtil; let accordion; let consoleErrors = []; -let miloLib = '?milolibs=stage'; +let miloLibs = process.env.MILO_LIBS; const knownConsoleErrors = ['Access-Control-Allow-Origin','Failed to load resource: net::ERR_FAILED']; test.describe('Milo Accordion Block test suite', () => { @@ -27,13 +27,13 @@ test.describe('Milo Accordion Block test suite', () => { // Test 0 : Accordion test(`${features[0].name},${features[0].tags}`, async ({ page, baseURL }) => { - console.info(`[Test Page]: ${baseURL}${features[0].path}${miloLib}`); + console.info(`[Test Page]: ${baseURL}${features[0].path}${miloLibs}`); const { data } = features[0]; await test.step('step-1: Go to Accordion block test page', async () => { - await page.goto(`${baseURL}${features[0].path}${miloLib}`); + await page.goto(`${baseURL}${features[0].path}${miloLibs}`); await page.waitForLoadState('domcontentloaded'); - await expect(page).toHaveURL(`${baseURL}${features[0].path}${miloLib}`); + await expect(page).toHaveURL(`${baseURL}${features[0].path}${miloLibs}`); }); await test.step('step-2: Verify Accrodion block content/specs', async () => { @@ -69,13 +69,13 @@ test.describe('Milo Accordion Block test suite', () => { // Test 1 : Accordion (seo) test(`${features[1].name},${features[1].tags}`, async ({ page, baseURL }) => { - console.info(`[Test Page]: ${baseURL}${features[1].path}`); + console.info(`[Test Page]: ${baseURL}${features[1].path}${miloLibs}`); const { data } = features[1]; await test.step('step-1: Go to Accordion block test page', async () => { - await page.goto(`${baseURL}${features[1].path}`); + await page.goto(`${baseURL}${features[1].path}${miloLibs}`); await page.waitForLoadState('domcontentloaded'); - await expect(page).toHaveURL(`${baseURL}${features[1].path}`); + await expect(page).toHaveURL(`${baseURL}${features[1].path}${miloLibs}`); }); await test.step('step-2: Verify Accrodion seo block specs', async () => { @@ -103,13 +103,13 @@ test.describe('Milo Accordion Block test suite', () => { // Test 2 : Accordion (quiet, max-width-12-desktop-large) test(`${features[2].name},${features[2].tags}`, async ({ page, baseURL }) => { - console.info(`[Test Page]: ${baseURL}${features[2].path}`); + console.info(`[Test Page]: ${baseURL}${features[2].path}${miloLibs}`); const { data } = features[2]; await test.step('step-1: Go to Accordion block test page', async () => { - await page.goto(`${baseURL}${features[2].path}`); + await page.goto(`${baseURL}${features[2].path}${miloLibs}`); await page.waitForLoadState('domcontentloaded'); - await expect(page).toHaveURL(`${baseURL}${features[2].path}`); + await expect(page).toHaveURL(`${baseURL}${features[2].path}${miloLibs}`); }); await test.step('step-2: Verify Accrodion block content/specs', async () => { From d3736b5576248ae2dbe73edc5e4ba78df015513f Mon Sep 17 00:00:00 2001 From: nateekar Date: Sat, 6 Jan 2024 12:39:44 -0800 Subject: [PATCH 3/6] add empty striting --- tests/milo/accordion.block.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/milo/accordion.block.test.js b/tests/milo/accordion.block.test.js index 9d0e8a63..33134923 100644 --- a/tests/milo/accordion.block.test.js +++ b/tests/milo/accordion.block.test.js @@ -6,7 +6,7 @@ import AccordionBlock from '../../selectors/milo/accordion.block.page.js'; let webUtil; let accordion; let consoleErrors = []; -let miloLibs = process.env.MILO_LIBS; +let miloLibs = process.env.MILO_LIBS || ''; const knownConsoleErrors = ['Access-Control-Allow-Origin','Failed to load resource: net::ERR_FAILED']; test.describe('Milo Accordion Block test suite', () => { From 8f16c52342e22f5bfdd37b0477179fd274ac9873 Mon Sep 17 00:00:00 2001 From: nateekar Date: Sat, 6 Jan 2024 13:35:19 -0800 Subject: [PATCH 4/6] update base reporter --- global.setup_1.js | 5 +++-- tests/milo/accordion.block.test.js | 3 ++- utils/reporters/base-reporter.js | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/global.setup_1.js b/global.setup_1.js index d64fba30..3efbd19d 100644 --- a/global.setup_1.js +++ b/global.setup_1.js @@ -22,10 +22,12 @@ async function getGitHubPRBranchLiveUrl() { const prFromOrg = process.env.prOrg; const prFromRepoName = process.env.prRepo; + let prBranchLiveUrl; if (toRepoName === 'nala' || toRepoName === 'janus') { prBranchLiveUrl = `https://main--milo--adobecom.hlx.live`; + } else { prBranchLiveUrl = `https://${prBranch}--${prFromRepoName}--${prFromOrg}.hlx.live`; } @@ -61,8 +63,7 @@ async function getGitHubMiloLibsBranchLiveUrl() { try { if (await isBranchURLValid(prBranchLiveUrl)) { - process.env.PR_BRANCH_LIVE_URL = prBranchLiveUrl; - process.env.MILO_LIBS = prBranchLiveUrl; + process.env.PR_BRANCH_LIVE_URL = prBranchLiveUrl; } console.info('PR Repository : ', repository); console.info('PR Branch live url : ', prBranchLiveUrl); diff --git a/tests/milo/accordion.block.test.js b/tests/milo/accordion.block.test.js index 33134923..4c9e83e0 100644 --- a/tests/milo/accordion.block.test.js +++ b/tests/milo/accordion.block.test.js @@ -6,7 +6,8 @@ import AccordionBlock from '../../selectors/milo/accordion.block.page.js'; let webUtil; let accordion; let consoleErrors = []; -let miloLibs = process.env.MILO_LIBS || ''; + +const miloLibs = process.env.MILO_LIBS || ''; const knownConsoleErrors = ['Access-Control-Allow-Origin','Failed to load resource: net::ERR_FAILED']; test.describe('Milo Accordion Block test suite', () => { diff --git a/utils/reporters/base-reporter.js b/utils/reporters/base-reporter.js index 4a14057a..25543840 100644 --- a/utils/reporters/base-reporter.js +++ b/utils/reporters/base-reporter.js @@ -93,7 +93,9 @@ class BaseReporter { const totalTests = this.results.length; const passPercentage = ((this.passedTests / totalTests) * 100).toFixed(2); const failPercentage = ((this.failedTests / totalTests) * 100).toFixed(2); - let envURL = process.env.PR_BRANCH_LIVE_URL || this.config.projects[0].use.baseURL; + const miloLibs = process.env.MILO_LIBS || ''; + const prBranchUrl = process.env.PR_BRANCH_LIVE_URL + miloLibs + let envURL = prBranchUrl || this.config.projects[0].use.baseURL; let exeEnv = 'Local Environment'; let runUrl = 'Local Environment'; let runName = 'Nala Local Run'; From 5ca6cb009aec9daeb14a26423449cea39f4cf109 Mon Sep 17 00:00:00 2001 From: nateekar Date: Sun, 7 Jan 2024 15:51:00 -0800 Subject: [PATCH 5/6] update global setup --- global.setup_1.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/global.setup_1.js b/global.setup_1.js index 3efbd19d..c1faaf0f 100644 --- a/global.setup_1.js +++ b/global.setup_1.js @@ -3,6 +3,10 @@ const { execSync } = require('child_process'); const { isBranchURLValid } = require('./libs/baseurl.js'); const axios = require('axios'); +const MAIN_BRANCH_LIVE_URL = 'https://main--milo--adobecom.hlx.live'; +const STAGE_BRANCH_URL = 'https://milo.stage.adobe.com'; +const LOCALHOST_URL = 'http://localhost:3000'; + async function getGitHubPRBranchLiveUrl() { // get the pr number const prReference = process.env.GITHUB_REF; @@ -26,8 +30,7 @@ async function getGitHubPRBranchLiveUrl() { let prBranchLiveUrl; if (toRepoName === 'nala' || toRepoName === 'janus') { - prBranchLiveUrl = `https://main--milo--adobecom.hlx.live`; - + prBranchLiveUrl = MAIN_BRANCH_LIVE_URL; } else { prBranchLiveUrl = `https://${prBranch}--${prFromRepoName}--${prFromOrg}.hlx.live`; } @@ -76,7 +79,7 @@ async function getGitHubMiloLibsBranchLiveUrl() { } async function getCircleCIBranchLiveUrl() { - const stageBranchLiveUrl = 'https://milo.stage.adobe.com'; + const stageBranchLiveUrl = STAGE_BRANCH_URL; try { if (await isBranchURLValid(stageBranchLiveUrl)) { @@ -104,10 +107,9 @@ async function getLocalBranchLiveUrl() { let localTestLiveUrl; if (localRepo === 'nala' || localRepo === 'janus') { - localTestLiveUrl = `https://main--milo--adobecom.hlx.live`; - process.env.MILO_LIBS = '?milolibs=stage'; + localTestLiveUrl = MAIN_BRANCH_LIVE_URL; } else { - localTestLiveUrl = `http://localhost:3000`; + localTestLiveUrl = LOCALHOST_URL; } if (await isBranchURLValid(localTestLiveUrl)) { From 9685a57132207c8ed0ef0064c558024e5b93b3ca Mon Sep 17 00:00:00 2001 From: nateekar Date: Sun, 7 Jan 2024 16:02:18 -0800 Subject: [PATCH 6/6] update manul yml --- .github/workflows/manual.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/manual.yml b/.github/workflows/manual.yml index 98b3e29c..6238f969 100644 --- a/.github/workflows/manual.yml +++ b/.github/workflows/manual.yml @@ -20,8 +20,7 @@ jobs: steps: - name: Check out repository uses: actions/checkout@v3 - - name: Set permissions - run: chmod +x ./path/to/run.sh + - name: Run Nala ${{ inputs.platform }} uses: ./ env: