@@ -21,7 +21,6 @@ import * as PERFORMANCE_SDK_EVENTS from './instrumentation/performance/constants
2121import { logBuildError , handleErrorForObservability , handleErrorForAccessibility , getProductMapForBuildStartCall } from './testHub/utils.js'
2222import type BrowserStackConfig from './config.js'
2323import type { Errors } from './testHub/utils.js'
24-
2524import type { UserConfig , UploadType , BrowserstackConfig , BrowserstackOptions , LaunchResponse } from './types.js'
2625import type { ITestCaseHookParameter } from './cucumber-types.js'
2726import {
@@ -328,9 +327,11 @@ export const processAccessibilityResponse = (response: LaunchResponse) => {
328327
329328 if ( response . accessibility . options ) {
330329 const { accessibilityToken, pollingTimeout, scannerVersion } = jsonifyAccessibilityArray ( response . accessibility . options . capabilities , 'name' , 'value' )
330+ const result = jsonifyAccessibilityArray ( response . accessibility . options . capabilities , 'name' , 'value' )
331331 const scriptsJson = {
332332 'scripts' : jsonifyAccessibilityArray ( response . accessibility . options . scripts , 'name' , 'command' ) ,
333- 'commands' : response . accessibility . options . commandsToWrap . commands
333+ 'commands' : response . accessibility . options . commandsToWrap . commands ,
334+ 'nonBStackInfraA11yChromeOptions' : result [ 'goog:chromeOptions' ]
334335 }
335336 if ( scannerVersion ) {
336337 process . env . BSTACK_A11Y_SCANNER_VERSION = scannerVersion as string
@@ -398,6 +399,11 @@ export const launchTestSession = PerformanceTester.measureWrapper(PERFORMANCE_SD
398399 config : { }
399400 }
400401
402+ if ( accessibilityAutomation && ( isTurboScale ( options ) || data . browserstackAutomation === false ) ) {
403+ data . accessibility . settings ??= { }
404+ data . accessibility . settings [ 'includeEncodedExtension' ] = true
405+ }
406+
401407 try {
402408 if ( Object . keys ( CrashReporter . userConfigForReporting ) . length === 0 ) {
403409 CrashReporter . userConfigForReporting = process . env . USER_CONFIG_FOR_REPORTING !== undefined ? JSON . parse ( process . env . USER_CONFIG_FOR_REPORTING ) : { }
@@ -420,6 +426,7 @@ export const launchTestSession = PerformanceTester.measureWrapper(PERFORMANCE_SD
420426 body : JSON . stringify ( data )
421427 } )
422428 const jsonResponse : LaunchResponse = await response . json ( )
429+ delete data ?. accessibility ?. settings ?. includeEncodedExtension
423430 BStackLogger . debug ( `[Start_Build] Success response: ${ JSON . stringify ( jsonResponse ) } ` )
424431 process . env [ TESTOPS_BUILD_COMPLETED_ENV ] = 'true'
425432 if ( jsonResponse . jwt ) {
@@ -486,6 +493,20 @@ export const validateCapsWithA11y = (deviceName?: any, platformMeta?: { [key: st
486493 return false
487494}
488495
496+ export const validateCapsWithNonBstackA11y = ( browserName ?: string | undefined , browserVersion ?:string | undefined ) => {
497+
498+ if ( browserName ?. toLowerCase ( ) !== 'chrome' ) {
499+ BStackLogger . warn ( 'Accessibility Automation will run only on Chrome browsers.' )
500+ return false
501+ }
502+ if ( ! isUndefined ( browserVersion ) && ! ( browserVersion === 'latest' || parseFloat ( browserVersion + '' ) > 100 ) ) {
503+ BStackLogger . warn ( 'Accessibility Automation will run only on Chrome browser version greater than 100.' )
504+ return false
505+ }
506+ return true
507+
508+ }
509+
489510export const shouldScanTestForAccessibility = ( suiteTitle : string | undefined , testTitle : string , accessibilityOptions ?: { [ key : string ] : string ; } , world ?: { [ key : string ] : unknown ; } , isCucumber ?: boolean ) => {
490511 try {
491512 const includeTags = Array . isArray ( accessibilityOptions ?. includeTagsInTestingScope ) ? accessibilityOptions ?. includeTagsInTestingScope : [ ]
@@ -551,10 +572,6 @@ export const _getParamsForAppAccessibility = ( commandName?: string ): { thTestR
551572
552573/* eslint-disable @typescript-eslint/no-explicit-any */
553574export const performA11yScan = async ( isAppAutomate : boolean , browser : WebdriverIO . Browser | WebdriverIO . MultiRemoteBrowser , isBrowserStackSession ?: boolean , isAccessibility ?: boolean | string , commandName ?: string ) : Promise < { [ key : string ] : any ; } | undefined > => {
554- if ( ! isBrowserStackSession ) {
555- BStackLogger . warn ( 'Not a BrowserStack Automate session, cannot perform Accessibility scan.' )
556- return // since we are running only on Automate as of now
557- }
558575
559576 if ( ! isAccessibilityAutomationSession ( isAccessibility ) ) {
560577 BStackLogger . warn ( 'Not an Accessibility Automation session, cannot perform Accessibility scan.' )
@@ -580,10 +597,6 @@ export const performA11yScan = async (isAppAutomate: boolean, browser: Webdriver
580597}
581598
582599export const getA11yResults = PerformanceTester . measureWrapper ( PERFORMANCE_SDK_EVENTS . A11Y_EVENTS . GET_RESULTS , async ( isAppAutomate : boolean , browser : WebdriverIO . Browser , isBrowserStackSession ?: boolean , isAccessibility ?: boolean | string ) : Promise < Array < { [ key : string ] : any ; } > > => {
583- if ( ! isBrowserStackSession ) {
584- BStackLogger . warn ( 'Not a BrowserStack Automate session, cannot retrieve Accessibility results.' )
585- return [ ] // since we are running only on Automate as of now
586- }
587600
588601 if ( ! isAccessibilityAutomationSession ( isAccessibility ) ) {
589602 BStackLogger . warn ( 'Not an Accessibility Automation session, cannot retrieve Accessibility results.' )
@@ -663,9 +676,6 @@ const getAppA11yResultResponse = async (apiUrl: string, isAppAutomate: boolean,
663676}
664677
665678export const getA11yResultsSummary = PerformanceTester . measureWrapper ( PERFORMANCE_SDK_EVENTS . A11Y_EVENTS . GET_RESULTS_SUMMARY , async ( isAppAutomate : boolean , browser : WebdriverIO . Browser , isBrowserStackSession ?: boolean , isAccessibility ?: boolean | string ) : Promise < { [ key : string ] : any ; } > => {
666- if ( ! isBrowserStackSession ) {
667- return { } // since we are running only on Automate as of now
668- }
669679
670680 if ( ! isAccessibilityAutomationSession ( isAccessibility ) ) {
671681 BStackLogger . warn ( 'Not an Accessibility Automation session, cannot retrieve Accessibility results summary.' )
@@ -1640,3 +1650,43 @@ export function getBooleanValueFromString(value: string | undefined): boolean {
16401650 return [ 'true' ] . includes ( value . trim ( ) . toLowerCase ( ) )
16411651}
16421652
1653+ export function mergeDeep ( target : Record < string , any > , ...sources : any [ ] ) : Record < string , any > {
1654+ if ( ! sources . length ) { return target }
1655+ const source = sources . shift ( )
1656+
1657+ if ( isObject ( target ) && isObject ( source ) ) {
1658+ for ( const key in source ) {
1659+ const sourceValue = source [ key ]
1660+ const targetValue = target [ key ]
1661+
1662+ if ( isObject ( sourceValue ) ) {
1663+ if ( ! targetValue || ! isObject ( targetValue ) ) {
1664+ target [ key ] = { }
1665+ }
1666+ mergeDeep ( target [ key ] , sourceValue )
1667+ } else {
1668+ target [ key ] = sourceValue
1669+ }
1670+ }
1671+ }
1672+
1673+ return mergeDeep ( target , ...sources )
1674+ }
1675+
1676+ export function mergeChromeOptions ( base : Capabilities . ChromeOptions , override : Partial < Capabilities . ChromeOptions > ) : Capabilities . ChromeOptions {
1677+ const merged : Capabilities . ChromeOptions = { ...base }
1678+
1679+ if ( override . args ) {
1680+ merged . args = [ ...( base . args || [ ] ) , ...override . args ]
1681+ }
1682+
1683+ if ( override . extensions ) {
1684+ merged . extensions = [ ...( base . extensions || [ ] ) , ...override . extensions ]
1685+ }
1686+
1687+ if ( override . prefs ) {
1688+ merged . prefs = mergeDeep ( { ...( base . prefs || { } ) } , override . prefs )
1689+ }
1690+ return merged
1691+ }
1692+
0 commit comments