@@ -7,6 +7,8 @@ const request = require('request');
77const os = require ( 'os' ) ;
88const glob = require ( 'glob' ) ;
99const helper = require ( '../helpers/helper' ) ;
10+ const { CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS } = require ( '../helpers/constants' ) ;
11+ const supportFileContentMap = { }
1012
1113exports . checkAccessibilityPlatform = ( user_config ) => {
1214 let accessibility = false ;
@@ -32,9 +34,20 @@ exports.setAccessibilityCypressCapabilities = async (user_config, accessibilityR
3234 user_config . run_settings . system_env_vars . push ( `ACCESSIBILITY_SCANNERVERSION=${ accessibilityResponse . data . scannerVersion } ` )
3335}
3436
37+ exports . isAccessibilitySupportedCypressVersion = ( cypress_config_filename ) => {
38+ const extension = cypress_config_filename . split ( '.' ) . pop ( ) ;
39+ return CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS . includes ( extension ) ;
40+ }
41+
3542exports . createAccessibilityTestRun = async ( user_config , framework ) => {
3643
3744 try {
45+ if ( ! this . isAccessibilitySupportedCypressVersion ( user_config . run_settings . cypress_config_file ) ) {
46+ logger . warn ( `Accessibility Testing is not supported on Cypress version 9 and below.` )
47+ process . env . BROWSERSTACK_TEST_ACCESSIBILITY = 'false' ;
48+ user_config . run_settings . accessibility = false ;
49+ return ;
50+ }
3851 const userName = user_config [ "auth" ] [ "username" ] ;
3952 const accessKey = user_config [ "auth" ] [ "access_key" ] ;
4053 let settings = utils . isUndefined ( user_config . run_settings . accessibilityOptions ) ? { } : user_config . run_settings . accessibilityOptions
@@ -158,6 +171,17 @@ const nodeRequest = (type, url, data, config) => {
158171 } ) ;
159172}
160173
174+ exports . supportFileCleanup = ( ) => {
175+ logger . debug ( "Cleaning up support file changes added for accessibility. " )
176+ Object . keys ( supportFileContentMap ) . forEach ( file => {
177+ try {
178+ fs . writeFileSync ( file , supportFileContentMap [ file ] , { encoding : 'utf-8' } ) ;
179+ } catch ( e ) {
180+ logger . debug ( `Error while replacing file content for ${ file } with it's original content with error : ${ e } ` , true , e ) ;
181+ }
182+ } ) ;
183+ }
184+
161185const getAccessibilityCypressCommandEventListener = ( ) => {
162186 return (
163187 `require('browserstack-cypress-cli/bin/accessibility-automation/cypress');`
0 commit comments