Skip to content

Commit 641f4ee

Browse files
committed
changed request to axios
1 parent a608608 commit 641f4ee

File tree

9 files changed

+2255
-0
lines changed

9 files changed

+2255
-0
lines changed
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
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('command:start', (command) => {
13+
if(!command || !command.attributes) return;
14+
if(command.attributes.name == 'log' || (command.attributes.name == 'task' && (command.attributes.args.includes('test_observability_command') || command.attributes.args.includes('test_observability_log')))) {
15+
return;
16+
}
17+
/* Send command details */
18+
cy.now('task', 'test_observability_command', {
19+
type: 'COMMAND_START',
20+
command: {
21+
attributes: {
22+
id: command.attributes.id,
23+
name: command.attributes.name,
24+
args: command.attributes.args
25+
},
26+
state: 'pending'
27+
}
28+
}, {log: false}).then((res) => {
29+
}).catch((err) => {
30+
});
31+
32+
/* Send platform details */
33+
cy.now('task', 'test_observability_platform_details', {
34+
testTitle: Cypress.currentTest.title,
35+
browser: Cypress.browser,
36+
platform: Cypress.platform,
37+
cypressVersion: Cypress.version
38+
}, {log: false}).then((res) => {
39+
}).catch((err) => {
40+
});
41+
});
42+
43+
Cypress.on('command:retry', (command) => {
44+
if(!command || !command.attributes) return;
45+
if(command.attributes.name == 'log' || (command.attributes.name == 'task' && (command.attributes.args.includes('test_observability_command') || command.attributes.args.includes('test_observability_log')))) {
46+
return;
47+
}
48+
cy.now('task', 'test_observability_command', {
49+
type: 'COMMAND_RETRY',
50+
command: {
51+
_log: command._log,
52+
error: {
53+
message: command && command.error ? command.error.message : null,
54+
isDefaultAssertionErr: command && command.error ? command.error.isDefaultAssertionErr : null
55+
}
56+
}
57+
}, {log: false}).then((res) => {
58+
}).catch((err) => {
59+
});
60+
});
61+
62+
Cypress.on('command:end', (command) => {
63+
if(!command || !command.attributes) return;
64+
if(command.attributes.name == 'log' || (command.attributes.name == 'task' && (command.attributes.args.includes('test_observability_command') || command.attributes.args.includes('test_observability_log')))) {
65+
return;
66+
}
67+
cy.now('task', 'test_observability_command', {
68+
'type': 'COMMAND_END',
69+
'command': {
70+
'attributes': {
71+
'id': command.attributes.id,
72+
'name': command.attributes.name,
73+
'args': command.attributes.args
74+
},
75+
'state': command.state
76+
}
77+
}, {log: false}).then((res) => {
78+
}).catch((err) => {
79+
});
80+
});
81+
82+
Cypress.Commands.overwrite('log', (originalFn, ...args) => {
83+
if(args.includes('test_observability_log') || args.includes('test_observability_command')) return;
84+
const message = args.reduce((result, logItem) => {
85+
if (typeof logItem === 'object') {
86+
return [result, JSON.stringify(logItem)].join(' ');
87+
}
88+
89+
return [result, logItem ? logItem.toString() : ''].join(' ');
90+
}, '');
91+
cy.now('task', 'test_observability_log', {
92+
'level': 'info',
93+
message,
94+
}, {log: false}).then((res) => {
95+
}).catch((err) => {
96+
});
97+
originalFn(...args);
98+
});
99+
100+
Cypress.Commands.add('trace', (message, file) => {
101+
cy.now('task', 'test_observability_log', {
102+
level: 'trace',
103+
message,
104+
file,
105+
}).then((res) => {
106+
}).catch((err) => {
107+
});
108+
});
109+
110+
Cypress.Commands.add('logDebug', (message, file) => {
111+
cy.now('task', 'test_observability_log', {
112+
level: 'debug',
113+
message,
114+
file,
115+
}).then((res) => {
116+
}).catch((err) => {
117+
});
118+
});
119+
120+
Cypress.Commands.add('info', (message, file) => {
121+
cy.now('task', 'test_observability_log', {
122+
level: 'info',
123+
message,
124+
file,
125+
}).then((res) => {
126+
}).catch((err) => {
127+
});
128+
});
129+
130+
Cypress.Commands.add('warn', (message, file) => {
131+
cy.now('task', 'test_observability_log', {
132+
level: 'warn',
133+
message,
134+
file,
135+
}).then((res) => {
136+
}).catch((err) => {
137+
});
138+
});
139+
140+
Cypress.Commands.add('error', (message, file) => {
141+
cy.now('task', 'test_observability_log', {
142+
level: 'error',
143+
message,
144+
file,
145+
}).then((res) => {
146+
}).catch((err) => {
147+
});
148+
});
149+
150+
Cypress.Commands.add('fatal', (message, file) => {
151+
cy.now('task', 'test_observability_log', {
152+
level: 'fatal',
153+
message,
154+
file,
155+
}).then((res) => {
156+
}).catch((err) => {
157+
});
158+
});
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
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('command:start', (command) => {
13+
if(!command || !command.attributes) return;
14+
if(command.attributes.name == 'log' || (command.attributes.name == 'task' && (command.attributes.args.includes('test_observability_command') || command.attributes.args.includes('test_observability_log')))) {
15+
return;
16+
}
17+
/* Send command details */
18+
cy.now('task', 'test_observability_command', {
19+
type: 'COMMAND_START',
20+
command: {
21+
attributes: {
22+
id: command.attributes.id,
23+
name: command.attributes.name,
24+
args: command.attributes.args
25+
},
26+
state: 'pending'
27+
}
28+
}, {log: false}).then((res) => {
29+
}).catch((err) => {
30+
});
31+
32+
/* Send platform details */
33+
cy.now('task', 'test_observability_platform_details', {
34+
testTitle: Cypress.currentTest.title,
35+
browser: Cypress.browser,
36+
platform: Cypress.platform,
37+
cypressVersion: Cypress.version
38+
}, {log: false}).then((res) => {
39+
}).catch((err) => {
40+
});
41+
});
42+
43+
Cypress.on('command:retry', (command) => {
44+
if(!command || !command.attributes) return;
45+
if(command.attributes.name == 'log' || (command.attributes.name == 'task' && (command.attributes.args.includes('test_observability_command') || command.attributes.args.includes('test_observability_log')))) {
46+
return;
47+
}
48+
cy.now('task', 'test_observability_command', {
49+
type: 'COMMAND_RETRY',
50+
command: {
51+
_log: command._log,
52+
error: {
53+
message: command && command.error ? command.error.message : null,
54+
isDefaultAssertionErr: command && command.error ? command.error.isDefaultAssertionErr : null
55+
}
56+
}
57+
}, {log: false}).then((res) => {
58+
}).catch((err) => {
59+
});
60+
});
61+
62+
Cypress.on('command:end', (command) => {
63+
if(!command || !command.attributes) return;
64+
if(command.attributes.name == 'log' || (command.attributes.name == 'task' && (command.attributes.args.includes('test_observability_command') || command.attributes.args.includes('test_observability_log')))) {
65+
return;
66+
}
67+
cy.now('task', 'test_observability_command', {
68+
'type': 'COMMAND_END',
69+
'command': {
70+
'attributes': {
71+
'id': command.attributes.id,
72+
'name': command.attributes.name,
73+
'args': command.attributes.args
74+
},
75+
'state': command.state
76+
}
77+
}, {log: false}).then((res) => {
78+
}).catch((err) => {
79+
});
80+
});
81+
82+
Cypress.Commands.overwrite('log', (originalFn, ...args) => {
83+
if(args.includes('test_observability_log') || args.includes('test_observability_command')) return;
84+
const message = args.reduce((result, logItem) => {
85+
if (typeof logItem === 'object') {
86+
return [result, JSON.stringify(logItem)].join(' ');
87+
}
88+
89+
return [result, logItem ? logItem.toString() : ''].join(' ');
90+
}, '');
91+
cy.now('task', 'test_observability_log', {
92+
'level': 'info',
93+
message,
94+
}, {log: false}).then((res) => {
95+
}).catch((err) => {
96+
});
97+
originalFn(...args);
98+
});
99+
100+
Cypress.Commands.add('trace', (message, file) => {
101+
cy.now('task', 'test_observability_log', {
102+
level: 'trace',
103+
message,
104+
file,
105+
}).then((res) => {
106+
}).catch((err) => {
107+
});
108+
});
109+
110+
Cypress.Commands.add('logDebug', (message, file) => {
111+
cy.now('task', 'test_observability_log', {
112+
level: 'debug',
113+
message,
114+
file,
115+
}).then((res) => {
116+
}).catch((err) => {
117+
});
118+
});
119+
120+
Cypress.Commands.add('info', (message, file) => {
121+
cy.now('task', 'test_observability_log', {
122+
level: 'info',
123+
message,
124+
file,
125+
}).then((res) => {
126+
}).catch((err) => {
127+
});
128+
});
129+
130+
Cypress.Commands.add('warn', (message, file) => {
131+
cy.now('task', 'test_observability_log', {
132+
level: 'warn',
133+
message,
134+
file,
135+
}).then((res) => {
136+
}).catch((err) => {
137+
});
138+
});
139+
140+
Cypress.Commands.add('error', (message, file) => {
141+
cy.now('task', 'test_observability_log', {
142+
level: 'error',
143+
message,
144+
file,
145+
}).then((res) => {
146+
}).catch((err) => {
147+
});
148+
});
149+
150+
Cypress.Commands.add('fatal', (message, file) => {
151+
cy.now('task', 'test_observability_log', {
152+
level: 'fatal',
153+
message,
154+
file,
155+
}).then((res) => {
156+
}).catch((err) => {
157+
});
158+
});
159+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const path = require('path');
2+
3+
exports.consoleHolder = Object.assign({},console);
4+
exports.BATCH_SIZE = 1000;
5+
exports.BATCH_INTERVAL = 2000;
6+
exports.API_URL = 'https://collector-observability.browserstack.com';
7+
8+
exports.IPC_EVENTS = {
9+
LOG: 'testObservability:cypressLog',
10+
CONFIG: 'testObservability:cypressConfig',
11+
SCREENSHOT: 'testObservability:cypressScreenshot',
12+
COMMAND: 'testObservability:cypressCommand',
13+
CUCUMBER: 'testObservability:cypressCucumberStep',
14+
PLATFORM_DETAILS: 'testObservability:cypressPlatformDetails'
15+
};
16+
17+
exports.OBSERVABILITY_ENV_VARS = [
18+
"BROWSERSTACK_TEST_OBSERVABILITY",
19+
"BROWSERSTACK_AUTOMATION",
20+
"BS_TESTOPS_BUILD_COMPLETED",
21+
"BS_TESTOPS_JWT",
22+
"BS_TESTOPS_BUILD_HASHED_ID",
23+
"BS_TESTOPS_ALLOW_SCREENSHOTS",
24+
"OBSERVABILITY_LAUNCH_SDK_VERSION",
25+
"BROWSERSTACK_OBSERVABILITY_DEBUG",
26+
"OBS_CRASH_REPORTING_USERNAME",
27+
"OBS_CRASH_REPORTING_ACCESS_KEY",
28+
"OBS_CRASH_REPORTING_BS_CONFIG_PATH",
29+
"OBS_CRASH_REPORTING_CYPRESS_CONFIG_PATH"
30+
];
31+
32+
exports.TEST_OBSERVABILITY_REPORTER = 'browserstack-cypress-cli/bin/testObservability/reporter';
33+
34+
exports.TEST_OBSERVABILITY_REPORTER_LOCAL = path.join(__dirname, '..', 'reporter');
35+
36+
exports.PENDING_QUEUES_FILE = `pending_queues_${process.pid}.json`;

0 commit comments

Comments
 (0)