Skip to content

Commit 7d9e7fb

Browse files
committed
initial changes
1 parent e75e182 commit 7d9e7fb

File tree

7 files changed

+764
-2
lines changed

7 files changed

+764
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports.API_URL = 'https://accessibility.browserstack.com/api';
Lines changed: 310 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,310 @@
1+
/* Event listeners + custom commands for Cypress */
2+
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) => {
13+
14+
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+
74+
})
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+
97+
98+
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
175+
},
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
205+
}
206+
}
207+
}, {log: false}).then((res) => {
208+
}).catch((err) => {
209+
});
210+
});
211+
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+
});
230+
});
231+
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(' ');
237+
}
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) => {
307+
});
308+
});
309+
310+

0 commit comments

Comments
 (0)