Skip to content

Commit a88f32a

Browse files
committed
changes
1 parent 7d9e7fb commit a88f32a

File tree

4 files changed

+175
-336
lines changed

4 files changed

+175
-336
lines changed

bin/accessibility-automation/cypress/index.js

Lines changed: 90 additions & 293 deletions
Original file line numberDiff line numberDiff line change
@@ -1,309 +1,106 @@
11
/* Event listeners + custom commands for Cypress */
22

3-
/* Used to detect Gherkin steps */
4-
Cypress.on('log:added', (log) => {
5-
return () => {
6-
return cy.now('task', 'test_observability_step', {
7-
log
8-
}, {log: false})
9-
}
10-
});
11-
12-
Cypress.on('test:before:run', (attributes, runnable) => {
3+
Cypress.on('test:before:run', () => {
134

145
console.log("env ACCESSIBILITY_EXTENSION_PATH ", process.env.ACCESSIBILITY_EXTENSION_PATH)
15-
// window.eval(`console.log('test:before:run!!!!!!!!! ${process.env.ACCESSIBILITY_EXTENSION_PATH}')`);
16-
// window.eval("console.log(`test:before:run!!!!!!!!!, ${JSON.stringify(attributes)}`)");
17-
console.log(`test:before:run!!!!!!!!!, JSON.stringify(attributes)}`, JSON.stringify(attributes))
18-
19-
window.eval("console.log('test:before:run!!!!!!!!!')");
20-
window.eval("console.log('test:before:run!!!!!!!!!')");
21-
window.eval("console.log('test:before:run!!!!!!!!!')");
22-
window.eval("console.log('test:before:run!!!!!!!!!')");
23-
const dataForExtension = {
24-
"saveResults": true,
25-
"testDetails": {
26-
"name": 'BStackDemo',
27-
"testRunId": '5058',
28-
"filePath": 'cypress-test-file-path',
29-
"scopeList": [
30-
'path',
31-
'name'
32-
]
33-
},
34-
"platform": {
35-
"os_name": 'OS X',
36-
"os_version": 'Big Sur',
37-
"browser_name": 'chrome',
38-
"browser_version": '117.0.5938.62'
39-
}
40-
};
41-
42-
// window.eval(`
43-
// const e = new CustomEvent('A11Y_TEST_END', {detail: ${dataForExtension}});
44-
// window.parent.dispatchEvent(e);
45-
// console.log('test:before:run A11Y END !!!!!!')`);
46-
47-
// window.eval(`
48-
// const e = new CustomEvent('A11Y_TEST_END', {detail: {
49-
// "saveResults": true,
50-
// "testDetails": {
51-
// "name": 'BStackDemo',
52-
// "testRunId": '5164',
53-
// "filePath": 'cypress-test-file-path',
54-
// "scopeList": [
55-
// 'path',
56-
// 'name'
57-
// ]
58-
// },
59-
// "platform": {
60-
// "os_name": 'OS X',
61-
// "os_version": 'Big Sur',
62-
// "browser_name": 'chrome',
63-
// "browser_version": '117.0.5938.62'
64-
// }
65-
// }});
66-
// window.parent.dispatchEvent(e);
67-
// console.log('test:before:run A11Y END !!!!!!')`);
68-
69-
70-
// window.eval("console.log('test:before:run!!!!!!!!!')");
71-
// window.eval(`console.log('test:before:run!!!!!!!!!', ${attributes})`);
72-
73-
6+
console.log("Cypress.config()")
7+
console.log(Cypress.config())
8+
console.log("cypress.env.ACCESSIBILITY_EXTENSION_PATH")
9+
console.log(Cypress.env())
10+
11+
// if (process.env.ACCESSIBILITY_EXTENSION_PATH !== undefined) {
12+
let rs = new Promise((resolve, reject) => {
13+
window.parent.addEventListener('A11Y_TAP_STARTED', () => {
14+
console.log("A11Y_TAP_STARTED !!!! resolving")
15+
resolve("A11Y_TAP_STARTED");
16+
console.log("A11Y_TAP_STARTED !!!! after resolve")
17+
});
18+
const e = new CustomEvent('A11Y_FORCE_START');
19+
window.parent.dispatchEvent(e);
20+
})
21+
console.log("rs")
22+
console.log(rs)
23+
console.log("rs 1")
24+
// }
7425
})
75-
// Cypress.on('test:before:run', (command) => {
76-
77-
// // console.log("command", command)
78-
// // console.log("process variables BS_A11Y_JWT", process.env.ACCESSIBILITY);
79-
// // window.eval(`console.log("command", ${command})`);
80-
// // window.eval(`console.log("BS_A11Y_JWT", ${process.env.BS_A11Y_JWT})`);
81-
// window.eval("console.log('test:before:run!!!!!!!!!')")
82-
83-
// window.eval("window.name='A11Y_TEST_BEFORE_RUN_CHECK'")
84-
// // cy.now('task', 'a11y_command', {
85-
// // type: 'a11y'
86-
// // });
87-
88-
// // cy.log("testing!!!!!!!")
89-
// // cy.get('body').type('{command}', {release: false});
90-
// // cy.get('body').type('{alt}', {release: false});
91-
// // cy.get('body').type('J');
92-
// // cy.get('body').type('{alt}{command}');
93-
94-
// });
95-
96-
9726

9827
Cypress.on('test:after:run', (attributes, runnable) => {
99-
window.eval("console.log('test:after:run!!!!!!!!!')");
100-
window.eval("console.log('test:after:run!!!!!!!!!')");
101-
102-
const dataForExtension = {
103-
"saveResults": true,
104-
"testDetails": {
105-
"name": 'BStackDemo',
106-
"testRunId": '5164',
107-
"filePath": 'cypress-test-file-path',
108-
"scopeList": [
109-
'path',
110-
'name'
111-
]
112-
},
113-
"platform": {
114-
"os_name": 'OS X',
115-
"os_version": 'Big Sur',
116-
"browser_name": 'chrome',
117-
"browser_version": '117.0.5938.62'
118-
}
119-
};
120-
// window.eval(` console.log('A11Y_TEST_END in test:after:run !!!!!!!!!')
121-
// const e = new CustomEvent('A11Y_TEST_END', {detail: ${JSON.stringify(dataForExtension)}}); window.parent.dispatchEvent(e);`);
122-
123-
window.eval(`
124-
125-
const e = new CustomEvent('A11Y_TEST_END', {detail: ${dataForExtension}});
126-
window.parent.dispatchEvent(e);`);
127-
128-
// window.eval(`
129-
// const e = new CustomEvent('A11Y_TEST_END', {detail: {
130-
// "saveResults": true,
131-
// "testDetails": {
132-
// "name": 'BStackDemo',
133-
// "testRunId": '5164',
134-
// "filePath": 'cypress-test-file-path',
135-
// "scopeList": [
136-
// 'path',
137-
// 'name'
138-
// ]
139-
// },
140-
// "platform": {
141-
// "os_name": 'OS X',
142-
// "os_version": 'Big Sur',
143-
// "browser_name": 'chrome',
144-
// "browser_version": '117.0.5938.62'
145-
// }
146-
// }}); window.dispatchEvent(e);`);
147-
148-
window.eval("console.log('test:after:run!!!!!!!!!')");
149-
window.eval("console.log('test:after:run!!!!!!!!!')");
150-
window.eval("console.log('test:after:run!!!!!!!!!')");
151-
152-
// window.eval(`console.log('test:after:run!!!!!!!!!', ${attributes})`);
153-
154-
155-
// window.eval(`const e = new CustomEvent('A11Y_TEST_END', {detail: ${dataForExtension}});
156-
// window.dispatchEvent(e);`);
157-
158-
// window.eval("1+1");window.eval("1+1");window.eval("1+1");window.eval("1+1");window.eval("1+1");window.eval("1+1");window.eval("1+1");window.eval("1+1");window.eval("1+1");window.eval("1+1");window.eval("1+1");window.eval("1+1");window.eval("1+1");
159-
160-
});
161-
162-
Cypress.on('command:start', (command) => {
163-
if(!command || !command.attributes) return;
164-
if(command.attributes.name == 'log' || (command.attributes.name == 'task' && (command.attributes.args.includes('test_observability_command') || command.attributes.args.includes('test_observability_log')))) {
165-
return;
166-
}
167-
/* Send command details */
168-
cy.now('task', 'test_observability_command', {
169-
type: 'COMMAND_START',
170-
command: {
171-
attributes: {
172-
id: command.attributes.id,
173-
name: command.attributes.name,
174-
args: command.attributes.args
28+
console.log("test:after:run !!!!!!!")
29+
console.log("test:after:run !!!!!!!")
30+
console.log("test:after:run !!!!!!!")
31+
console.log("test:after:run !!!!!!!")
32+
console.log("test:after:run !!!!!!!")
33+
// if (process.env.ACCESSIBILITY_EXTENSION_PATH !== undefined) {
34+
35+
let shouldScanTestForAccessibility = true;
36+
// if (process.env.BROWSERSTACK_TEST_ACCESSIBILITY_CONFIGURATION_YML) {
37+
// try {
38+
// const accessibilityConfig = JSON.parse(process.env.BROWSERSTACK_TEST_ACCESSIBILITY_CONFIGURATION_YML);
39+
40+
// const includeTags = Array.isArray(accessibilityConfig.includeTagsInTestingScope) ? accessibilityConfig.includeTagsInTestingScope : [];
41+
// const excludeTags = Array.isArray(accessibilityConfig.excludeTagsInTestingScope) ? accessibilityConfig.excludeTagsInTestingScope : [];
42+
43+
// const fullTestName = attributes.title;
44+
// const excluded = excludeTags.some((exclude) => fullTestName.includes(exclude));
45+
// const included = includeTags.length === 0 || includeTags.some((include) => fullTestName.includes(include));
46+
// shouldScanTestForAccessibility = !excluded && included;
47+
// } catch (error){
48+
// console.log("Error while validating test case for accessibility before scanning. Error : ", error);
49+
// }
50+
// }
51+
const dataForExtension = {
52+
"saveResults": shouldScanTestForAccessibility,
53+
"testDetails": {
54+
"name": attributes.title,
55+
"testRunId": '5058', // variable not consumed, shouldn't matter what we send
56+
"filePath": attributes.invocationDetails.relativeFile,
57+
"scopeList": [
58+
attributes.invocationDetails.relativeFile,
59+
attributes.title
60+
]
17561
},
176-
state: 'pending'
177-
}
178-
}, {log: false}).then((res) => {
179-
}).catch((err) => {
180-
});
181-
182-
/* Send platform details */
183-
cy.now('task', 'test_observability_platform_details', {
184-
testTitle: Cypress.currentTest.title,
185-
browser: Cypress.browser,
186-
platform: Cypress.platform,
187-
cypressVersion: Cypress.version
188-
}, {log: false}).then((res) => {
189-
}).catch((err) => {
190-
});
191-
});
192-
193-
Cypress.on('command:retry', (command) => {
194-
if(!command || !command.attributes) return;
195-
if(command.attributes.name == 'log' || (command.attributes.name == 'task' && (command.attributes.args.includes('test_observability_command') || command.attributes.args.includes('test_observability_log')))) {
196-
return;
197-
}
198-
cy.now('task', 'test_observability_command', {
199-
type: 'COMMAND_RETRY',
200-
command: {
201-
_log: command._log,
202-
error: {
203-
message: command && command.error ? command.error.message : null,
204-
isDefaultAssertionErr: command && command.error ? command.error.isDefaultAssertionErr : null
62+
"platform": {
63+
"os_name": process.env.SESSION_OS,
64+
"os_version": process.env.OS_VERSION,
65+
"browser_name": process.env.BROWSER,
66+
"browser_version": process.env.BROWSER_VERSION
20567
}
206-
}
207-
}, {log: false}).then((res) => {
208-
}).catch((err) => {
209-
});
210-
});
68+
};
69+
console.log("test:after:run !!!!!!! dataForExtension")
70+
console.log(dataForExtension)
71+
console.log("test:after:run !!!!!!! dataForExtension 2 ")
72+
return new Promise((resolve, reject) => {
73+
console.log("dataForExtension")
74+
console.log(dataForExtension)
75+
76+
if (dataForExtension.saveResults) {
77+
window.parent.addEventListener('A11Y_TAP_TRANSPORTER', (event) => {
78+
resolve(event.detail);
79+
});
80+
}
81+
const e = new CustomEvent('A11Y_TEST_END', {detail: dataForExtension});
82+
window.parent.dispatchEvent(e);
83+
if (dataForExtension.saveResults !== true ) {
84+
resolve();
85+
}
86+
});
87+
// }
21188

212-
Cypress.on('command:end', (command) => {
213-
if(!command || !command.attributes) return;
214-
if(command.attributes.name == 'log' || (command.attributes.name == 'task' && (command.attributes.args.includes('test_observability_command') || command.attributes.args.includes('test_observability_log')))) {
215-
return;
216-
}
217-
cy.now('task', 'test_observability_command', {
218-
'type': 'COMMAND_END',
219-
'command': {
220-
'attributes': {
221-
'id': command.attributes.id,
222-
'name': command.attributes.name,
223-
'args': command.attributes.args
224-
},
225-
'state': command.state
226-
}
227-
}, {log: false}).then((res) => {
228-
}).catch((err) => {
229-
});
23089
});
23190

232-
Cypress.Commands.overwrite('log', (originalFn, ...args) => {
233-
if(args.includes('test_observability_log') || args.includes('test_observability_command')) return;
234-
const message = args.reduce((result, logItem) => {
235-
if (typeof logItem === 'object') {
236-
return [result, JSON.stringify(logItem)].join(' ');
91+
Cypress.Commands.add('getAccessibilityResultsSummary', () => {
92+
return new Promise(function (resolve, reject) {
93+
try{
94+
const e = new CustomEvent('A11Y_TAP_GET_RESULTS_SUMMARY');
95+
const fn = function (event) {
96+
window.parent.removeEventListener('A11Y_RESULTS_SUMMARY_RESPONSE', fn);
97+
resolve(event.detail.summary);
98+
};
99+
window.parent.addEventListener('A11Y_RESULTS_SUMMARY_RESPONSE', fn);
100+
window.parent.dispatchEvent(e);
101+
} catch (err) {
102+
reject(err);
237103
}
238-
239-
return [result, logItem ? logItem.toString() : ''].join(' ');
240-
}, '');
241-
cy.now('task', 'test_observability_log', {
242-
'level': 'info',
243-
message,
244-
}, {log: false}).then((res) => {
245-
}).catch((err) => {
246-
});
247-
originalFn(...args);
248-
});
249-
250-
Cypress.Commands.add('trace', (message, file) => {
251-
cy.now('task', 'test_observability_log', {
252-
level: 'trace',
253-
message,
254-
file,
255-
}).then((res) => {
256-
}).catch((err) => {
257-
});
258-
});
259-
260-
Cypress.Commands.add('logDebug', (message, file) => {
261-
cy.now('task', 'test_observability_log', {
262-
level: 'debug',
263-
message,
264-
file,
265-
}).then((res) => {
266-
}).catch((err) => {
267-
});
268-
});
269-
270-
Cypress.Commands.add('info', (message, file) => {
271-
cy.now('task', 'test_observability_log', {
272-
level: 'info',
273-
message,
274-
file,
275-
}).then((res) => {
276-
}).catch((err) => {
277-
});
278-
});
279-
280-
Cypress.Commands.add('warn', (message, file) => {
281-
cy.now('task', 'test_observability_log', {
282-
level: 'warn',
283-
message,
284-
file,
285-
}).then((res) => {
286-
}).catch((err) => {
287-
});
288-
});
289-
290-
Cypress.Commands.add('error', (message, file) => {
291-
cy.now('task', 'test_observability_log', {
292-
level: 'error',
293-
message,
294-
file,
295-
}).then((res) => {
296-
}).catch((err) => {
297-
});
298-
});
299-
300-
Cypress.Commands.add('fatal', (message, file) => {
301-
cy.now('task', 'test_observability_log', {
302-
level: 'fatal',
303-
message,
304-
file,
305-
}).then((res) => {
306-
}).catch((err) => {
307104
});
308105
});
309106

0 commit comments

Comments
 (0)