From 319f9bb1c45e77920ea5f96865f21bf3ce6513af Mon Sep 17 00:00:00 2001 From: amaanbs Date: Tue, 11 Jul 2023 13:10:21 +0530 Subject: [PATCH 1/4] pack and upload local cli as dependency --- bin/helpers/packageInstaller.js | 9 ++++++++- bin/testObservability/helper/helper.js | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/bin/helpers/packageInstaller.js b/bin/helpers/packageInstaller.js index 35850237..92d1bf5c 100644 --- a/bin/helpers/packageInstaller.js +++ b/bin/helpers/packageInstaller.js @@ -8,7 +8,7 @@ utils = require('./utils'), { get_version } = require('./usageReporting'), process = require('process'), - { spawn } = require('child_process'), + { spawn, execSync } = require('child_process'), util = require('util'); let nodeProcess; @@ -80,6 +80,13 @@ const packageInstall = (packageDir) => { const npm_major_version = utils.getMajorVersion(npm_version); logger.debug(`Fetched npm version: ${npm_version} and its major version: ${npm_major_version}`); + try { + logger.info(`Running npm pack command : ${path.resolve(__dirname, '..', '..', '..', 'browserstack-cypress-cli')}`); + execSync(`${/^win/.test(process.platform) ? 'npm.cmd' : 'npm'} pack`, {cwd: path.resolve(__dirname, '..', '..', '..', 'browserstack-cypress-cli')}, function(err, stdout, stderr) {}); + } catch(e) { + logger.info(`Error running npm pack command`); + } + // add --legacy-peer-deps flag while installing dependencies for npm v7+ // For more info please read "Peer Dependencies" section here -> https://github.blog/2021-02-02-npm-7-is-now-generally-available/ if (parseInt(npm_major_version) >= 7) { diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index 021c6af9..1786359e 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -445,7 +445,7 @@ const setBrowserstackCypressCliDependency = (bsConfig) => { typeof runSettings.npm_dependencies === 'object') { if (!("browserstack-cypress-cli" in runSettings.npm_dependencies)) { logger.warn("Missing browserstack-cypress-cli not found in npm_dependencies"); - runSettings.npm_dependencies['browserstack-cypress-cli'] = exports.getAgentVersion() || "latest"; + runSettings.npm_dependencies['browserstack-cypress-cli'] = path.resolve(__dirname, '..', '..', '..', '..', 'browserstack-cypress-cli', `browserstack-cypress-cli-${exports.getAgentVersion()}.tgz`); logger.warn(`Adding browserstack-cypress-cli version ${runSettings.npm_dependencies['browserstack-cypress-cli']} in npm_dependencies`); } } From 35d17ebbc48dcceebbe81863652586f3a3e1dc57 Mon Sep 17 00:00:00 2001 From: amaanbs Date: Mon, 22 Jul 2024 17:33:02 +0530 Subject: [PATCH 2/4] changes post refactoring --- bin/helpers/helper.js | 3 ++- bin/testObservability/helper/helper.js | 12 ------------ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/bin/helpers/helper.js b/bin/helpers/helper.js index 8a985829..e0d04269 100644 --- a/bin/helpers/helper.js +++ b/bin/helpers/helper.js @@ -315,10 +315,11 @@ exports.getBuildDetails = (bsConfig, isO11y = false) => { exports.setBrowserstackCypressCliDependency = (bsConfig) => { const runSettings = bsConfig.run_settings; if (runSettings.npm_dependencies !== undefined && + Object.keys(runSettings.npm_dependencies).length !== 0 && typeof runSettings.npm_dependencies === 'object') { if (!("browserstack-cypress-cli" in runSettings.npm_dependencies)) { logger.warn("Missing browserstack-cypress-cli not found in npm_dependencies"); - runSettings.npm_dependencies['browserstack-cypress-cli'] = this.getAgentVersion() || "latest"; + runSettings.npm_dependencies['browserstack-cypress-cli'] = path.resolve(__dirname, '..', '..', '..', 'browserstack-cypress-cli', `browserstack-cypress-cli-${exports.getAgentVersion()}.tgz`); logger.warn(`Adding browserstack-cypress-cli version ${runSettings.npm_dependencies['browserstack-cypress-cli']} in npm_dependencies`); } } diff --git a/bin/testObservability/helper/helper.js b/bin/testObservability/helper/helper.js index 7f9abae8..a7537985 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -322,18 +322,6 @@ const getBuildDetails = (bsConfig) => { }; } -const setBrowserstackCypressCliDependency = (bsConfig) => { - const runSettings = bsConfig.run_settings; - if (runSettings.npm_dependencies !== undefined && - Object.keys(runSettings.npm_dependencies).length !== 0 && - typeof runSettings.npm_dependencies === 'object') { - if (!("browserstack-cypress-cli" in runSettings.npm_dependencies)) { - logger.warn("Missing browserstack-cypress-cli not found in npm_dependencies"); - runSettings.npm_dependencies['browserstack-cypress-cli'] = path.resolve(__dirname, '..', '..', '..', '..', 'browserstack-cypress-cli', `browserstack-cypress-cli-${exports.getAgentVersion()}.tgz`); - logger.warn(`Adding browserstack-cypress-cli version ${runSettings.npm_dependencies['browserstack-cypress-cli']} in npm_dependencies`); - } - } -} const getCypressConfigFileContent = (bsConfig, cypressConfigPath) => { try { const cypressConfigFile = require(path.resolve(bsConfig ? bsConfig.run_settings.cypress_config_file : cypressConfigPath)); From bc9217b3305e2400c984789724776d553e4953ba Mon Sep 17 00:00:00 2001 From: rev-doshi Date: Wed, 24 Jul 2024 18:17:49 +0530 Subject: [PATCH 3/4] helper pr for debugging o11y and a11y --- bin/accessibility-automation/cypress/index.js | 16 ++++++++++++++-- bin/accessibility-automation/helper.js | 2 ++ bin/accessibility-automation/plugin/index.js | 3 +++ bin/helpers/helper.js | 10 +++++++--- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index 6bc8aa3b..6fb79f7d 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -1,7 +1,7 @@ /* Event listeners + custom commands for Cypress */ const browserStackLog = (message) => { - if (!Cypress.env('BROWSERSTACK_LOGS')) return; + // if (!Cypress.env('BROWSERSTACK_LOGS')) return; cy.task('browserstack_log', message); } @@ -231,11 +231,14 @@ const saveTestResults = (win, payloadToSend) => }) const shouldScanForAccessibility = (attributes) => { + browserStackLog(`>>> shouldScanForAccessibility : IS_ACCESSIBILITY_EXTENSION_LOADED ${Cypress.env("IS_ACCESSIBILITY_EXTENSION_LOADED")}`); if (Cypress.env("IS_ACCESSIBILITY_EXTENSION_LOADED") !== "true") return false; const extensionPath = Cypress.env("ACCESSIBILITY_EXTENSION_PATH"); const isHeaded = Cypress.browser.isHeaded; + browserStackLog(`>>> shouldScanForAccessibility : 2 : ${isHeaded} ${extensionPath}`); + if (!isHeaded || (extensionPath === undefined)) return false; let shouldScanTestForAccessibility = true; @@ -254,6 +257,9 @@ const shouldScanForAccessibility = (attributes) => { const fullTestName = attributes.title; const excluded = excludeTagArray.some((exclude) => fullTestName.includes(exclude)); const included = includeTagArray.length === 0 || includeTags.some((include) => fullTestName.includes(include)); + + browserStackLog(`>>> shouldScanForAccessibility : 3 : ${included} ${excluded}`); + shouldScanTestForAccessibility = !excluded && included; } catch (error) { browserStackLog("Error while validating test case for accessibility before scanning. Error : ", error); @@ -283,12 +289,16 @@ Cypress.on('command:start', async (command) => { }) afterEach(() => { + browserStackLog(">>> afterEach"); const attributes = Cypress.mocha.getRunner().suite.ctx.currentTest; cy.window().then(async (win) => { + browserStackLog(`>>> afterEach : before shouldScanTestForAccessibility`); let shouldScanTestForAccessibility = shouldScanForAccessibility(attributes); + browserStackLog(`>>> afterEach : shouldScanTestForAccessibility : ${shouldScanTestForAccessibility}`); if (!shouldScanTestForAccessibility) return cy.wrap({}); cy.wrap(performScan(win), {timeout: 30000}).then(() => { + browserStackLog(">>> afterEach : cy.wrap()"); try { let os_data; if (Cypress.env("OS")) { @@ -296,10 +306,12 @@ afterEach(() => { } else { os_data = Cypress.platform === 'linux' ? 'mac' : "win" } + browserStackLog(">>> afterEach : before filePath"); let filePath = ''; if (attributes.invocationDetails !== undefined && attributes.invocationDetails.relativeFile !== undefined) { filePath = attributes.invocationDetails.relativeFile; } + browserStackLog(">>> afterEach : before payloadToSend"); const payloadToSend = { "saveResults": shouldScanTestForAccessibility, "testDetails": { @@ -318,7 +330,7 @@ afterEach(() => { "browser_version": Cypress.browser.version } }; - browserStackLog(`Saving accessibility test results`); + browserStackLog(`Saving accessibility test results : ${payloadToSend}`); cy.wrap(saveTestResults(win, payloadToSend), {timeout: 30000}).then(() => { browserStackLog(`Saved accessibility test results`); }) diff --git a/bin/accessibility-automation/helper.js b/bin/accessibility-automation/helper.js index 8a08b674..4bde1112 100644 --- a/bin/accessibility-automation/helper.js +++ b/bin/accessibility-automation/helper.js @@ -107,6 +107,8 @@ exports.createAccessibilityTestRun = async (user_config, framework) => { logger.debug(`BrowserStack Accessibility Automation Test Run ID: ${response.data.data.id}`); this.setAccessibilityCypressCapabilities(user_config, response.data); + logger.info(`BrowserStack Accessibility Automation Test Run ID: ${response.data.data.id}`); + helper.setBrowserstackCypressCliDependency(user_config); } catch (error) { diff --git a/bin/accessibility-automation/plugin/index.js b/bin/accessibility-automation/plugin/index.js index dd47f208..42744f31 100644 --- a/bin/accessibility-automation/plugin/index.js +++ b/bin/accessibility-automation/plugin/index.js @@ -15,6 +15,7 @@ const browserstackAccessibility = (on, config) => { }, }) on('before:browser:launch', (browser = {}, launchOptions) => { + console.log(`\n CAME TO before:browser:launch \n`); try { if (process.env.ACCESSIBILITY_EXTENSION_PATH !== undefined) { if (browser.name !== 'chrome') { @@ -29,6 +30,7 @@ const browserstackAccessibility = (on, config) => { console.log(`Accessibility Automation will not run on legacy headless mode. Switch to new headless mode or avoid using headless mode.`); browser_validation = false; } + console.log(`\n CAME TO before:browser:launch 2 : ${browser_validation} \n`); if (browser_validation) { const ally_path = path.dirname(process.env.ACCESSIBILITY_EXTENSION_PATH) launchOptions.extensions.push(ally_path); @@ -39,6 +41,7 @@ const browserstackAccessibility = (on, config) => { }) config.env.ACCESSIBILITY_EXTENSION_PATH = process.env.ACCESSIBILITY_EXTENSION_PATH + console.log(`\n CAME TO before:browser:launch 3 : ${config.env.ACCESSIBILITY_EXTENSION_PATH} \n`); config.env.OS_VERSION = process.env.OS_VERSION config.env.OS = process.env.OS diff --git a/bin/helpers/helper.js b/bin/helpers/helper.js index e0d04269..2d7464c6 100644 --- a/bin/helpers/helper.js +++ b/bin/helpers/helper.js @@ -317,10 +317,14 @@ exports.setBrowserstackCypressCliDependency = (bsConfig) => { if (runSettings.npm_dependencies !== undefined && Object.keys(runSettings.npm_dependencies).length !== 0 && typeof runSettings.npm_dependencies === 'object') { - if (!("browserstack-cypress-cli" in runSettings.npm_dependencies)) { - logger.warn("Missing browserstack-cypress-cli not found in npm_dependencies"); + logger.info("inside setBrowserstackCypressCliDependency and runSettings.npm_dependencies"); + logger.info(("browserstack-cypress-cli" in runSettings.npm_dependencies)); + + + if (true) { + logger.info("Missing browserstack-cypress-cli not found in npm_dependencies"); runSettings.npm_dependencies['browserstack-cypress-cli'] = path.resolve(__dirname, '..', '..', '..', 'browserstack-cypress-cli', `browserstack-cypress-cli-${exports.getAgentVersion()}.tgz`); - logger.warn(`Adding browserstack-cypress-cli version ${runSettings.npm_dependencies['browserstack-cypress-cli']} in npm_dependencies`); + logger.info(`Adding browserstack-cypress-cli version ${runSettings.npm_dependencies['browserstack-cypress-cli']} in npm_dependencies`); } } } From e52a491b5c5d3785b46478de7d72511272ec23d4 Mon Sep 17 00:00:00 2001 From: rev-doshi Date: Mon, 29 Jul 2024 16:42:59 +0530 Subject: [PATCH 4/4] add erro log --- bin/accessibility-automation/plugin/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/accessibility-automation/plugin/index.js b/bin/accessibility-automation/plugin/index.js index 42744f31..1dbc2d48 100644 --- a/bin/accessibility-automation/plugin/index.js +++ b/bin/accessibility-automation/plugin/index.js @@ -37,7 +37,9 @@ const browserstackAccessibility = (on, config) => { return launchOptions } } - } catch(err) {} + } catch(err) { + console.log(`\n CAME TO before:browser:launch CATCH ERROR : ${err} \n`); + } }) config.env.ACCESSIBILITY_EXTENSION_PATH = process.env.ACCESSIBILITY_EXTENSION_PATH