Skip to content

Commit

Permalink
[MILOLIBS RUN : MWPW-141223] Provide support to run nala tests on a g…
Browse files Browse the repository at this point in the history
…iven milo libs (#240)

* update the test files

* update the tests

* update the failures

* update the personalizataion and iframe tests

* update wait

---------

Co-authored-by: nateekar <[email protected]>
  • Loading branch information
skumar09 and nateekar authored Jan 12, 2024
1 parent 0ae64ab commit d629cf9
Show file tree
Hide file tree
Showing 32 changed files with 663 additions and 537 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/milolib.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: Run Nala on Milo Libs Manually
name: Run Nala on Milo Libs

on:
workflow_dispatch:
inputs:
branch:
description: 'Provide the branch url'
description: 'Provide the live branch url. ex: https://main--cc--adobecom.hlx.live'
required: false
type: string
milolibs:
description: 'Provide MiloLibs param'
description: 'Provide MiloLibs param. ex: ?milolibs=marquee-static-hover'
required: false
type: string
tags:
Expand Down
2 changes: 1 addition & 1 deletion features/milo/georouting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
desc: 'User accessing DE page from US locale.',
path: '/de/drafts/nala/features/georouting/georouting',
data: {
title: 'This Adobe site doesn\'t match your location.',
title: /This Adobe site doesn[' ]t match your location./,
text: 'Based on your location, we think you may prefer the United States website',
button: 'United States',
link: 'Deutschland',
Expand Down
231 changes: 131 additions & 100 deletions global.setup.js
Original file line number Diff line number Diff line change
@@ -1,120 +1,151 @@
import { exit } from 'process';

const { execSync } = require('child_process');
const { isBranchURLValid } = require('./libs/baseurl.js');
const axios = require('axios');

async function globalSetup() {
console.info('----Executing Global setup---------');
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;
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;
let stageBranchLiveUrl;
let localTestLiveUrl;
let localOrg;
let localRepo;
let prNumber

// Check if the code is running in a GitHub CI/CD environment
if (process.env.GITHUB_ACTIONS === 'true') {
console.info('---- Running Tests in the GitHub environment ---------');

// get the pr number
const prReference = process.env.GITHUB_REF;
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;

try {
// Construct the pr branch URL
if (toRepoName === 'nala' || toRepoName === 'janus') {
prBranchLiveUrl = `https://main--milo--adobecom.hlx.live`;
} else {
prBranchLiveUrl = `https://${prBranch}--${prFromRepoName}--${prFromOrg}.hlx.live`;
}
if (toRepoName === 'nala' || toRepoName === 'janus') {
prBranchLiveUrl = MAIN_BRANCH_LIVE_URL;
} else {
prBranchLiveUrl = `https://${prBranch}--${prFromRepoName}--${prFromOrg}.hlx.live`;
}

// Validate the pr branch URL by making an HTTP request
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);
}
} else if (process.env.CIRCLECI) {
console.info('---- Running Tests in the CircleCI environment ---------');
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;
}
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);
}
}

stageBranchLiveUrl = 'https://milo.stage.adobe.com';

// Validate the stage URL by making an HTTP request
async function getCircleCIBranchLiveUrl() {
const stageBranchLiveUrl = STAGE_BRANCH_URL;

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);
}
}

} else {

console.info('---- Running Tests in the Local environment ---------');

try {
// Run 'git rev-parse --show-toplevel' to get the root directory of the Git repository
const localGitRootDir = execSync('git rev-parse --show-toplevel', { encoding: 'utf-8' }).trim();

if (localGitRootDir) {
// Get the repository and organization/owner name from the Git remote URL
const gitRemoteOriginUrl = execSync('git config --get remote.origin.url', { cwd: localGitRootDir, encoding: 'utf-8' }).trim();
const match = gitRemoteOriginUrl.match(/github\.com\/(.*?)\/(.*?)\.git/);
console.info('Git Local Remote Origin : ', gitRemoteOriginUrl );
if (match) {
localOrg = match[1];
localRepo = match[2];

console.info('Git ORG : ', localOrg );
console.info('Git REPO : ', localRepo );

// get the current local branch name
const localBranch = execSync('git rev-parse --abbrev-ref HEAD', { cwd: localGitRootDir, encoding: 'utf-8' }).trim();
console.info('Local Branch : ', localBranch );

if ( localRepo === 'nala' || localRepo === 'janus'){
localTestLiveUrl = `https://main--milo--adobecom.hlx.live`;
} else {
localTestLiveUrl = `http://localhost:3000`;
}

// Validate the pr branch URL by making an HTTP request
if ( await isBranchURLValid(localTestLiveUrl)){
process.env.LOCAL_TEST_LIVE_URL = localTestLiveUrl;
}
console.info('Local Test Live URL : ', process.env.LOCAL_TEST_LIVE_URL );
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 = MAIN_BRANCH_LIVE_URL;
} else {
localTestLiveUrl = LOCALHOST_URL;
}

if (await isBranchURLValid(localTestLiveUrl)) {
process.env.LOCAL_TEST_LIVE_URL = localTestLiveUrl;
}
}
} catch (error) {
console.error(`Error => Error in setting local test URL : ${localTestLiveUrl}`)
console.info(`Note : Local or branch test url ${localTestLiveUrl} is not valid, Exiting test execution.`);
process.exit(1);
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;
2 changes: 1 addition & 1 deletion playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const envs = require('./envs/envs.js');
const config = {
testDir: './tests/milo',
outputDir: './test-results',
globalSetup: './global.setup_1.js',
globalSetup: './global.setup.js',
/* Maximum time one test can run for. */
timeout: 30 * 1000,
expect: {
Expand Down
3 changes: 2 additions & 1 deletion selectors/milo/georouting.feature.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export default class Georouting {

// global footer locators
this.footer = this.page.locator('.global-footer');
this.changeRegionLink = this.footer.locator('//a[@data-modal-path="/fragments/regions"]');
//this.changeRegionLink = this.footer.locator('//a[@data-modal-path="/fragments/regions"]');
this.changeRegionLink = this.footer.locator('.modal.link-block');

// change region modal locators
this.changeRegionModal = this.page.locator('.dialog-modal');
Expand Down
Loading

0 comments on commit d629cf9

Please sign in to comment.