Skip to content

Commit e35c4c1

Browse files
committed
minor fixes
1 parent 14407d2 commit e35c4c1

File tree

6 files changed

+302
-247
lines changed

6 files changed

+302
-247
lines changed

bin/accessibility-automation/cypress/index.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
/* Event listeners + custom commands for Cypress */
22

33
Cypress.on('test:before:run', () => {
4-
console.log(`is loaded from before========> ${Cypress.env("IS_ACCESSIBILITY_EXTENSION_LOADED")}`)
54
if (Cypress.env("IS_ACCESSIBILITY_EXTENSION_LOADED") !== "true") return
65
const extensionPath = Cypress.env("ACCESSIBILITY_EXTENSION_PATH")
76

87
if (extensionPath !== undefined) {
9-
let rs = new Promise((resolve, reject) => {
8+
new Promise((resolve, reject) => {
109
window.parent.addEventListener('A11Y_TAP_STARTED', () => {
1110
console.log("A11Y_TAP_STARTED !!!! resolving")
1211
resolve("A11Y_TAP_STARTED");
@@ -19,14 +18,9 @@ Cypress.on('test:before:run', () => {
1918
})
2019

2120
Cypress.on('test:after:run', (attributes, runnable) => {
22-
console.log(`is loaded from after ========> ${Cypress.env("IS_ACCESSIBILITY_EXTENSION_LOADED")}`)
2321
if (Cypress.env("IS_ACCESSIBILITY_EXTENSION_LOADED") !== "true") return
24-
console.log("test:after:run !!!!!!!")
2522
const extensionPath = Cypress.env("ACCESSIBILITY_EXTENSION_PATH")
2623
const isHeaded = Cypress.browser.isHeaded;
27-
console.log(extensionPath)
28-
console.log(isHeaded)
29-
console.log("test:after:run !!!!!!!")
3024
if (isHeaded && extensionPath !== undefined) {
3125

3226
let shouldScanTestForAccessibility = true;
@@ -78,9 +72,10 @@ Cypress.on('test:after:run', (attributes, runnable) => {
7872
});
7973

8074
Cypress.Commands.add('getAccessibilityResultsSummary', () => {
81-
console.log(`is loaded from get ========> ${Cypress.env("IS_ACCESSIBILITY_EXTENSION_LOADED")}`)
82-
if (Cypress.env("IS_ACCESSIBILITY_EXTENSION_LOADED") !== "true") return
83-
75+
if (Cypress.env("IS_ACCESSIBILITY_EXTENSION_LOADED") !== "true") {
76+
console.log(`Not a Accessibility Automation session, cannot retrieve Accessibility results.`);
77+
return
78+
}
8479
return new Promise(function (resolve, reject) {
8580
try{
8681
const e = new CustomEvent('A11Y_TAP_GET_RESULTS_SUMMARY');
@@ -91,9 +86,30 @@ Cypress.Commands.add('getAccessibilityResultsSummary', () => {
9186
window.parent.addEventListener('A11Y_RESULTS_SUMMARY_RESPONSE', fn);
9287
window.parent.dispatchEvent(e);
9388
} catch (err) {
89+
console.log("No accessibility results summary was found.");
9490
reject(err);
9591
}
9692
});
9793
});
9894

95+
Cypress.Commands.add('getAccessibilityResults', () => {
96+
if (Cypress.env("IS_ACCESSIBILITY_EXTENSION_LOADED") !== "true") {
97+
console.log(`Not a Accessibility Automation session, cannot retrieve Accessibility results.`);
98+
return
99+
}
100+
return new Promise(function (resolve, reject) {
101+
try{
102+
const e = new CustomEvent('A11Y_TAP_GET_RESULTS');
103+
const fn = function (event) {
104+
window.parent.removeEventListener('A11Y_RESULTS_RESPONSE', fn);
105+
resolve(event.detail.summary);
106+
};
107+
window.parent.addEventListener('A11Y_RESULTS_RESPONSE', fn);
108+
window.parent.dispatchEvent(e);
109+
} catch (err) {
110+
console.log("No accessibility results were found.");
111+
reject(err);
112+
}
113+
});
114+
});
99115

bin/accessibility-automation/helper.js

Lines changed: 8 additions & 210 deletions
Original file line numberDiff line numberDiff line change
@@ -3,217 +3,15 @@ const { API_URL } = require('./constants');
33
const utils = require('../helpers/utils');
44
const fs = require('fs');
55
const path = require('path');
6-
const http = require('http');
7-
const https = require('https');
86
const request = require('request');
9-
var gitLastCommit = require('git-last-commit');
10-
const { v4: uuidv4 } = require('uuid');
117
const os = require('os');
12-
const { promisify } = require('util');
13-
const getRepoInfo = require('git-repo-info');
14-
const gitconfig = require('gitconfiglocal');
15-
const { spawn, execSync } = require('child_process');
168
const glob = require('glob');
17-
18-
exports.getFileSeparatorData = () => {
19-
return /^win/.test(process.platform) ? "\\" : "/";
20-
}
21-
22-
exports.findGitConfig = (filePath) => {
23-
const fileSeparator = exports.getFileSeparatorData();
24-
if(filePath == null || filePath == '' || filePath == fileSeparator) {
25-
return null;
26-
}
27-
try {
28-
fs.statSync(filePath + fileSeparator + '.git' + fileSeparator + 'config');
29-
return filePath;
30-
} catch(e) {
31-
let parentFilePath = filePath.split(fileSeparator);
32-
parentFilePath.pop();
33-
return exports.findGitConfig(parentFilePath.join(fileSeparator));
34-
}
35-
}
36-
37-
const getGitMetaData = () => {
38-
return new Promise(async (resolve, reject) => {
39-
try {
40-
var info = getRepoInfo();
41-
if(!info.commonGitDir) {
42-
logger.debug(`Unable to find a Git directory`);
43-
resolve({});
44-
}
45-
if(!info.author && exports.findGitConfig(process.cwd())) {
46-
/* commit objects are packed */
47-
gitLastCommit.getLastCommit(async (err, commit) => {
48-
if(err) {
49-
logger.debug(`Exception in populating Git Metadata with error : ${err}`, true, err);
50-
return resolve({});
51-
}
52-
try {
53-
info["author"] = info["author"] || `${commit["author"]["name"].replace(/[]+/g, '')} <${commit["author"]["email"].replace(/[]+/g, '')}>`;
54-
info["authorDate"] = info["authorDate"] || commit["authoredOn"];
55-
info["committer"] = info["committer"] || `${commit["committer"]["name"].replace(/[]+/g, '')} <${commit["committer"]["email"].replace(/[]+/g, '')}>`;
56-
info["committerDate"] = info["committerDate"] || commit["committedOn"];
57-
info["commitMessage"] = info["commitMessage"] || commit["subject"];
58-
59-
const { remote } = await pGitconfig(info.commonGitDir);
60-
const remotes = Object.keys(remote).map(remoteName => ({name: remoteName, url: remote[remoteName]['url']}));
61-
resolve({
62-
"name": "git",
63-
"sha": info["sha"],
64-
"short_sha": info["abbreviatedSha"],
65-
"branch": info["branch"],
66-
"tag": info["tag"],
67-
"committer": info["committer"],
68-
"committer_date": info["committerDate"],
69-
"author": info["author"],
70-
"author_date": info["authorDate"],
71-
"commit_message": info["commitMessage"],
72-
"root": info["root"],
73-
"common_git_dir": info["commonGitDir"],
74-
"worktree_git_dir": info["worktreeGitDir"],
75-
"last_tag": info["lastTag"],
76-
"commits_since_last_tag": info["commitsSinceLastTag"],
77-
"remotes": remotes
78-
});
79-
} catch(e) {
80-
logger.debug(`Exception in populating Git Metadata with error : ${e}`, true, e);
81-
return resolve({});
82-
}
83-
}, {dst: exports.findGitConfig(process.cwd())});
84-
} else {
85-
const { remote } = await pGitconfig(info.commonGitDir);
86-
const remotes = Object.keys(remote).map(remoteName => ({name: remoteName, url: remote[remoteName]['url']}));
87-
resolve({
88-
"name": "git",
89-
"sha": info["sha"],
90-
"short_sha": info["abbreviatedSha"],
91-
"branch": info["branch"],
92-
"tag": info["tag"],
93-
"committer": info["committer"],
94-
"committer_date": info["committerDate"],
95-
"author": info["author"],
96-
"author_date": info["authorDate"],
97-
"commit_message": info["commitMessage"],
98-
"root": info["root"],
99-
"common_git_dir": info["commonGitDir"],
100-
"worktree_git_dir": info["worktreeGitDir"],
101-
"last_tag": info["lastTag"],
102-
"commits_since_last_tag": info["commitsSinceLastTag"],
103-
"remotes": remotes
104-
});
105-
}
106-
} catch(err) {
107-
logger.debug(`Exception in populating Git metadata with error : ${err}`, true, err);
108-
resolve({});
109-
}
110-
})
111-
}
112-
113-
const getCiInfo = () => {
114-
var env = process.env;
115-
// Jenkins
116-
if ((typeof env.JENKINS_URL === "string" && env.JENKINS_URL.length > 0) || (typeof env.JENKINS_HOME === "string" && env.JENKINS_HOME.length > 0)) {
117-
return {
118-
name: "Jenkins",
119-
build_url: env.BUILD_URL,
120-
job_name: env.JOB_NAME,
121-
build_number: env.BUILD_NUMBER
122-
}
123-
}
124-
// CircleCI
125-
if (env.CI === "true" && env.CIRCLECI === "true") {
126-
return {
127-
name: "CircleCI",
128-
build_url: env.CIRCLE_BUILD_URL,
129-
job_name: env.CIRCLE_JOB,
130-
build_number: env.CIRCLE_BUILD_NUM
131-
}
132-
}
133-
// Travis CI
134-
if (env.CI === "true" && env.TRAVIS === "true") {
135-
return {
136-
name: "Travis CI",
137-
build_url: env.TRAVIS_BUILD_WEB_URL,
138-
job_name: env.TRAVIS_JOB_NAME,
139-
build_number: env.TRAVIS_BUILD_NUMBER
140-
}
141-
}
142-
// Codeship
143-
if (env.CI === "true" && env.CI_NAME === "codeship") {
144-
return {
145-
name: "Codeship",
146-
build_url: null,
147-
job_name: null,
148-
build_number: null
149-
}
150-
}
151-
// Bitbucket
152-
if (env.BITBUCKET_BRANCH && env.BITBUCKET_COMMIT) {
153-
return {
154-
name: "Bitbucket",
155-
build_url: env.BITBUCKET_GIT_HTTP_ORIGIN,
156-
job_name: null,
157-
build_number: env.BITBUCKET_BUILD_NUMBER
158-
}
159-
}
160-
// Drone
161-
if (env.CI === "true" && env.DRONE === "true") {
162-
return {
163-
name: "Drone",
164-
build_url: env.DRONE_BUILD_LINK,
165-
job_name: null,
166-
build_number: env.DRONE_BUILD_NUMBER
167-
}
168-
}
169-
// Semaphore
170-
if (env.CI === "true" && env.SEMAPHORE === "true") {
171-
return {
172-
name: "Semaphore",
173-
build_url: env.SEMAPHORE_ORGANIZATION_URL,
174-
job_name: env.SEMAPHORE_JOB_NAME,
175-
build_number: env.SEMAPHORE_JOB_ID
176-
}
177-
}
178-
// GitLab
179-
if (env.CI === "true" && env.GITLAB_CI === "true") {
180-
return {
181-
name: "GitLab",
182-
build_url: env.CI_JOB_URL,
183-
job_name: env.CI_JOB_NAME,
184-
build_number: env.CI_JOB_ID
185-
}
186-
}
187-
// Buildkite
188-
if (env.CI === "true" && env.BUILDKITE === "true") {
189-
return {
190-
name: "Buildkite",
191-
build_url: env.BUILDKITE_BUILD_URL,
192-
job_name: env.BUILDKITE_LABEL || env.BUILDKITE_PIPELINE_NAME,
193-
build_number: env.BUILDKITE_BUILD_NUMBER
194-
}
195-
}
196-
// Visual Studio Team Services
197-
if (env.TF_BUILD === "True") {
198-
return {
199-
name: "Visual Studio Team Services",
200-
build_url: `${env.SYSTEM_TEAMFOUNDATIONSERVERURI}${env.SYSTEM_TEAMPROJECTID}`,
201-
job_name: env.SYSTEM_DEFINITIONID,
202-
build_number: env.BUILD_BUILDID
203-
}
204-
}
205-
// if no matches, return null
206-
return null;
207-
}
9+
const helper = require('../helpers/helper');
20810

20911
exports.checkAccessibilityPlatform = (user_config) => {
210-
logger.info("checkAccessibilityPlatform start");
21112
let accessibility = false;
212-
// console.log("user_config.browsers", user_config.browsers)
21313
user_config.browsers.forEach(browser => {
214-
console.log("browser", browser)
21514
if (browser.accessibility) {
216-
console.log("inside browser.accessibility")
21715
accessibility = true;
21816
return true;
21917
}
@@ -254,21 +52,21 @@ exports.createAccessibilityTestRun = async (user_config, framework) => {
25452
'startTime': (new Date()).toISOString(),
25553
'description': buildDescription,
25654
'source': {
257-
frameworkName: "framework",
258-
frameworkVersion: "frameworkVersion",
259-
sdkVersion: "sdkVersion"
55+
frameworkName: "Cypress",
56+
frameworkVersion: helper.getPackageVersion('cypress', user_config),
57+
sdkVersion: helper.getAgentVersion()
26058
},
26159
'settings': settings,
262-
'versionControl': await getGitMetaData(),
263-
'ciInfo': getCiInfo(),
60+
'versionControl': await helper.getGitMetaData(),
61+
'ciInfo': helper.getCiInfo(),
26462
'hostInfo': {
26563
hostname: os.hostname(),
26664
platform: os.platform(),
26765
type: os.type(),
26866
version: os.version(),
26967
arch: os.arch()
27068
},
271-
'browserstackAutomation': true // fix!!
69+
'browserstackAutomation': process.env.BROWSERSTACK_AUTOMATION
27270
};
27371

27472
const config = {
@@ -285,7 +83,7 @@ exports.createAccessibilityTestRun = async (user_config, framework) => {
28583
'POST', 'test_runs', data, config
28684
);
28785
logger.info("response in createAccessibilityTestRun", response);
288-
86+
process.env.BROWSERSTACK_TEST_ACCESSIBILITY = 'true';
28987
process.env.BS_A11Y_JWT = response.data.data.accessibilityToken;
29088
process.env.BS_A11Y_TEST_RUN_ID = response.data.data.id;
29189

bin/accessibility-automation/plugin/index.js

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,37 @@ const browserstackAccessibility = (on, config) => {
55
let browser_validation = true;
66
on('before:browser:launch', (browser = {}, launchOptions) => {
77
try {
8-
console.log(`ACCESSIBILITY_EXTENSION_PATH :: ${process.env.ACCESSIBILITY_EXTENSION_PATH}`)
98

10-
if (process.env.ACCESSIBILITY_EXTENSION_PATH === undefined) {
11-
browser_validation = false
12-
return
13-
}
14-
15-
// add accessibility attribute validation !!
16-
// add OS validation !!
179
if (browser.name !== 'chrome') {
18-
// logger.warn(`Accessibility Automation will run only on Chrome browsers.`);
10+
console.log(`Accessibility Automation will run only on Chrome browsers.`);
1911
browser_validation = false;
2012
}
2113
if (browser.majorVersion <= 94) {
22-
// logger.warn(`Accessibility Automation will run only on Chrome browser version greater than 94.`);
14+
console.log(`Accessibility Automation will run only on Chrome browser version greater than 94.`);
2315
browser_validation = false;
2416
}
2517
if (browser.isHeadless === true) {
26-
// logger.warn(`Accessibility Automation will not run on legacy headless mode. Switch to new headless mode or avoid using headless mode.`);
18+
console.log(`Accessibility Automation will not run on legacy headless mode. Switch to new headless mode or avoid using headless mode.`);
2719
browser_validation = false;
2820
}
2921

22+
if (process.env.ACCESSIBILITY_EXTENSION_PATH === undefined) {
23+
browser_validation = false
24+
return
25+
}
26+
3027
if (browser_validation) {
31-
console.log(` inside before browser launch -> process.env.ACCESSIBILITY_EXTENSION_PATH - ${process.env.ACCESSIBILITY_EXTENSION_PATH}`)
3228
const ally_path = path.dirname(process.env.ACCESSIBILITY_EXTENSION_PATH)
33-
console.log(`FROM NODE ally_path : ${ally_path}`)
34-
launchOptions.args.push('--auto-open-devtools-for-tabs');
3529
launchOptions.extensions.push(ally_path);
3630
return launchOptions
3731
}
38-
} catch (e){
39-
console.log(`catch error : ${e}`)
40-
}
32+
} catch {}
4133

4234
})
4335
config.env.ACCESSIBILITY_EXTENSION_PATH = process.env.ACCESSIBILITY_EXTENSION_PATH
4436
config.env.OS_VERSION = process.env.OS_VERSION
4537
config.env.IS_ACCESSIBILITY_EXTENSION_LOADED = browser_validation.toString()
46-
38+
4739
config.env.INCLUDE_TAGS_FOR_ACCESSIBILITY = process.env.ACCESSIBILITY_INCLUDETAGSINTESTINGSCOPE
4840
config.env.EXCLUDE_TAGS_FOR_ACCESSIBILITY = process.env.ACCESSIBILITY_EXCLUDETAGSINTESTINGSCOPE
4941

0 commit comments

Comments
 (0)