Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress debug branch #851

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
16 changes: 14 additions & 2 deletions bin/accessibility-automation/cypress/index.js
Original file line number Diff line number Diff line change
@@ -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);
}

Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -283,23 +289,29 @@ 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")) {
os_data = Cypress.env("OS");
} 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": {
Expand All @@ -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`);
})
Expand Down
2 changes: 2 additions & 0 deletions bin/accessibility-automation/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion bin/accessibility-automation/plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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

Expand Down
13 changes: 9 additions & 4 deletions bin/helpers/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion bin/helpers/packageInstaller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
34 changes: 34 additions & 0 deletions bin/testObservability/helper/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down