@@ -3,12 +3,14 @@ const { API_URL } = require('./constants');
33const utils = require ( '../helpers/utils' ) ;
44const fs = require ( 'fs' ) ;
55const path = require ( 'path' ) ;
6- const request = require ( 'request ' ) ;
6+ const axios = require ( 'axios ' ) ;
77const os = require ( 'os' ) ;
88const glob = require ( 'glob' ) ;
99const helper = require ( '../helpers/helper' ) ;
1010const { CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS } = require ( '../helpers/constants' ) ;
11+ const { consoleHolder } = require ( "../testObservability/helper/constants" ) ;
1112const supportFileContentMap = { }
13+ const HttpsProxyAgent = require ( 'https-proxy-agent' ) ;
1214
1315exports . checkAccessibilityPlatform = ( user_config ) => {
1416 let accessibility = false ;
@@ -86,8 +88,8 @@ exports.createAccessibilityTestRun = async (user_config, framework) => {
8688
8789 const config = {
8890 auth : {
89- user : userName ,
90- pass : accessKey
91+ username : userName ,
92+ password : accessKey
9193 } ,
9294 headers : {
9395 'Content-Type' : 'application/json'
@@ -105,19 +107,21 @@ exports.createAccessibilityTestRun = async (user_config, framework) => {
105107 process . env . BROWSERSTACK_TEST_ACCESSIBILITY = 'true' ;
106108 }
107109 logger . debug ( `BrowserStack Accessibility Automation Test Run ID: ${ response . data . data . id } ` ) ;
108-
110+
109111 this . setAccessibilityCypressCapabilities ( user_config , response . data ) ;
110112 helper . setBrowserstackCypressCliDependency ( user_config ) ;
111113
112114 } catch ( error ) {
113115 if ( error . response ) {
116+ logger . error ( "Incorrect Cred" )
114117 logger . error (
115118 `Exception while creating test run for BrowserStack Accessibility Automation: ${
116119 error . response . status
117120 } ${ error . response . statusText } ${ JSON . stringify ( error . response . data ) } `
118121 ) ;
119122 } else {
120123 if ( error . message === 'Invalid configuration passed.' ) {
124+ logger . error ( "Invalid configuration passed." )
121125 logger . error (
122126 `Exception while creating test run for BrowserStack Accessibility Automation: ${
123127 error . message || error . stack
@@ -126,7 +130,7 @@ exports.createAccessibilityTestRun = async (user_config, framework) => {
126130 for ( const errorkey of error . errors ) {
127131 logger . error ( errorkey . message ) ;
128132 }
129-
133+
130134 } else {
131135 logger . error (
132136 `Exception while creating test run for BrowserStack Accessibility Automation: ${
@@ -143,33 +147,43 @@ exports.createAccessibilityTestRun = async (user_config, framework) => {
143147
144148const nodeRequest = ( type , url , data , config ) => {
145149 return new Promise ( async ( resolve , reject ) => {
146- const options = { ...config , ...{
150+ const options = {
151+ ...config ,
147152 method : type ,
148153 url : `${ API_URL } /${ url } ` ,
149- body : data ,
150- json : config . headers [ 'Content-Type' ] === 'application/json' ,
151- } } ;
154+ data : data
155+ } ;
152156
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 } ` ) ;
160170 } 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+ }
166177 }
167- }
168- resolve ( {
169- data : body
170- } ) ;
178+ resolve ( {
179+ data : response . data
180+ } ) ;
171181 }
172- } ) ;
182+ } ) . catch ( error => {
183+
184+ logger . info ( "error in nodeRequest" , error ) ;
185+ reject ( error ) ;
186+ } )
173187 } ) ;
174188}
175189
@@ -211,7 +225,7 @@ exports.setAccessibilityEventListeners = (bsConfig) => {
211225 try {
212226 if ( ! file . includes ( 'commands.js' ) && ! file . includes ( 'commands.ts' ) ) {
213227 const defaultFileContent = fs . readFileSync ( file , { encoding : 'utf-8' } ) ;
214-
228+
215229 let cypressCommandEventListener = getAccessibilityCypressCommandEventListener ( path . extname ( file ) ) ;
216230 if ( ! defaultFileContent . includes ( cypressCommandEventListener ) ) {
217231 let newFileContent = defaultFileContent +
0 commit comments