@@ -3,12 +3,14 @@ const { API_URL } = require('./constants');
3
3
const utils = require ( '../helpers/utils' ) ;
4
4
const fs = require ( 'fs' ) ;
5
5
const path = require ( 'path' ) ;
6
- const request = require ( 'request ' ) ;
6
+ const axios = require ( 'axios ' ) ;
7
7
const os = require ( 'os' ) ;
8
8
const glob = require ( 'glob' ) ;
9
9
const helper = require ( '../helpers/helper' ) ;
10
10
const { CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS } = require ( '../helpers/constants' ) ;
11
+ const { consoleHolder } = require ( "../testObservability/helper/constants" ) ;
11
12
const supportFileContentMap = { }
13
+ const HttpsProxyAgent = require ( 'https-proxy-agent' ) ;
12
14
13
15
exports . checkAccessibilityPlatform = ( user_config ) => {
14
16
let accessibility = false ;
@@ -86,8 +88,8 @@ exports.createAccessibilityTestRun = async (user_config, framework) => {
86
88
87
89
const config = {
88
90
auth : {
89
- user : userName ,
90
- pass : accessKey
91
+ username : userName ,
92
+ password : accessKey
91
93
} ,
92
94
headers : {
93
95
'Content-Type' : 'application/json'
@@ -105,19 +107,21 @@ exports.createAccessibilityTestRun = async (user_config, framework) => {
105
107
process . env . BROWSERSTACK_TEST_ACCESSIBILITY = 'true' ;
106
108
}
107
109
logger . debug ( `BrowserStack Accessibility Automation Test Run ID: ${ response . data . data . id } ` ) ;
108
-
110
+
109
111
this . setAccessibilityCypressCapabilities ( user_config , response . data ) ;
110
112
helper . setBrowserstackCypressCliDependency ( user_config ) ;
111
113
112
114
} catch ( error ) {
113
115
if ( error . response ) {
116
+ logger . error ( "Incorrect Cred" )
114
117
logger . error (
115
118
`Exception while creating test run for BrowserStack Accessibility Automation: ${
116
119
error . response . status
117
120
} ${ error . response . statusText } ${ JSON . stringify ( error . response . data ) } `
118
121
) ;
119
122
} else {
120
123
if ( error . message === 'Invalid configuration passed.' ) {
124
+ logger . error ( "Invalid configuration passed." )
121
125
logger . error (
122
126
`Exception while creating test run for BrowserStack Accessibility Automation: ${
123
127
error . message || error . stack
@@ -126,7 +130,7 @@ exports.createAccessibilityTestRun = async (user_config, framework) => {
126
130
for ( const errorkey of error . errors ) {
127
131
logger . error ( errorkey . message ) ;
128
132
}
129
-
133
+
130
134
} else {
131
135
logger . error (
132
136
`Exception while creating test run for BrowserStack Accessibility Automation: ${
@@ -143,33 +147,43 @@ exports.createAccessibilityTestRun = async (user_config, framework) => {
143
147
144
148
const nodeRequest = ( type , url , data , config ) => {
145
149
return new Promise ( async ( resolve , reject ) => {
146
- const options = { ...config , ...{
150
+ const options = {
151
+ ...config ,
147
152
method : type ,
148
153
url : `${ API_URL } /${ url } ` ,
149
- body : data ,
150
- json : config . headers [ 'Content-Type' ] === 'application/json' ,
151
- } } ;
154
+ data : data
155
+ } ;
152
156
153
- request ( options , function callback ( error , response , body ) {
154
- if ( error ) {
155
- logger . info ( "error in nodeRequest" , error ) ;
156
- reject ( error ) ;
157
- } else if ( ! ( response . statusCode == 201 || response . statusCode == 200 ) ) {
158
- logger . info ( "response.statusCode in nodeRequest" , response . statusCode ) ;
159
- reject ( response && response . body ? response . body : `Received response from BrowserStack Server with status : ${ response . statusCode } ` ) ;
157
+ if ( process . env . HTTP_PROXY ) {
158
+ options . proxy = false
159
+ options . httpsAgent = new HttpsProxyAgent ( process . env . HTTP_PROXY ) ;
160
+
161
+ } else if ( process . env . HTTPS_PROXY ) {
162
+ options . proxy = false
163
+ options . httpsAgent = new HttpsProxyAgent ( process . env . HTTPS_PROXY ) ;
164
+ }
165
+
166
+ axios ( options ) . then ( response => {
167
+ if ( ! ( response . status == 201 || response . status == 200 ) ) {
168
+ logger . info ( "response.status in nodeRequest" , response . status ) ;
169
+ reject ( response && response . data ? response . data : `Received response from BrowserStack Server with status : ${ response . status } ` ) ;
160
170
} else {
161
- try {
162
- if ( typeof ( body ) !== 'object' ) body = JSON . parse ( body ) ;
163
- } catch ( e ) {
164
- if ( ! url . includes ( '/stop' ) ) {
165
- reject ( 'Not a JSON response from BrowserStack Server' ) ;
171
+ try {
172
+ if ( typeof ( response . data ) !== 'object' ) body = JSON . parse ( response . data ) ;
173
+ } catch ( e ) {
174
+ if ( ! url . includes ( '/stop' ) ) {
175
+ reject ( 'Not a JSON response from BrowserStack Server' ) ;
176
+ }
166
177
}
167
- }
168
- resolve ( {
169
- data : body
170
- } ) ;
178
+ resolve ( {
179
+ data : response . data
180
+ } ) ;
171
181
}
172
- } ) ;
182
+ } ) . catch ( error => {
183
+
184
+ logger . info ( "error in nodeRequest" , error ) ;
185
+ reject ( error ) ;
186
+ } )
173
187
} ) ;
174
188
}
175
189
@@ -211,7 +225,7 @@ exports.setAccessibilityEventListeners = (bsConfig) => {
211
225
try {
212
226
if ( ! file . includes ( 'commands.js' ) && ! file . includes ( 'commands.ts' ) ) {
213
227
const defaultFileContent = fs . readFileSync ( file , { encoding : 'utf-8' } ) ;
214
-
228
+
215
229
let cypressCommandEventListener = getAccessibilityCypressCommandEventListener ( path . extname ( file ) ) ;
216
230
if ( ! defaultFileContent . includes ( cypressCommandEventListener ) ) {
217
231
let newFileContent = defaultFileContent +
0 commit comments