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..1dbc2d48 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,16 +30,20 @@ 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); 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 + 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 8a985829..2d7464c6 100644 --- a/bin/helpers/helper.js +++ b/bin/helpers/helper.js @@ -315,11 +315,16 @@ 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"; - logger.warn(`Adding browserstack-cypress-cli version ${runSettings.npm_dependencies['browserstack-cypress-cli']} 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.info(`Adding browserstack-cypress-cli version ${runSettings.npm_dependencies['browserstack-cypress-cli']} in npm_dependencies`); } } } diff --git a/bin/helpers/packageInstaller.js b/bin/helpers/packageInstaller.js index 1cdc3ea4..b0fb15cc 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 deacff95..a7537985 100644 --- a/bin/testObservability/helper/helper.js +++ b/bin/testObservability/helper/helper.js @@ -288,6 +288,40 @@ exports.setEventListeners = (bsConfig) => { } } +const getBuildDetails = (bsConfig) => { + const isTestObservabilityOptionsPresent = !utils.isUndefined(bsConfig["testObservabilityOptions"]); + let buildName = '', + projectName = '', + buildDescription = '', + buildTags = []; + + /* Pick from environment variables */ + buildName = process.env.BROWSERSTACK_BUILD_NAME || buildName; + projectName = process.env.BROWSERSTACK_PROJECT_NAME || projectName; + + /* Pick from testObservabilityOptions */ + if(isTestObservabilityOptionsPresent) { + buildName = buildName || bsConfig["testObservabilityOptions"]["buildName"]; + projectName = projectName || bsConfig["testObservabilityOptions"]["projectName"]; + if(!utils.isUndefined(bsConfig["testObservabilityOptions"]["buildTag"])) buildTags = [...buildTags, ...bsConfig["testObservabilityOptions"]["buildTag"]]; + buildDescription = buildDescription || bsConfig["testObservabilityOptions"]["buildDescription"]; + } + + /* Pick from run settings */ + buildName = buildName || bsConfig["run_settings"]["build_name"]; + projectName = projectName || bsConfig["run_settings"]["project_name"]; + if(!utils.isUndefined(bsConfig["run_settings"]["build_tag"])) buildTags = [...buildTags, bsConfig["run_settings"]["build_tag"]]; + + buildName = buildName || path.basename(path.resolve(process.cwd())); + + return { + buildName, + projectName, + buildDescription, + buildTags + }; +} + const getCypressConfigFileContent = (bsConfig, cypressConfigPath) => { try { const cypressConfigFile = require(path.resolve(bsConfig ? bsConfig.run_settings.cypress_config_file : cypressConfigPath));