From 0c1bfd83150d02b70bb3b8763cea5ba9bfc0bfdb Mon Sep 17 00:00:00 2001 From: Priyanka Vats Date: Fri, 23 Oct 2026 15:49:04 +0530 Subject: [PATCH 1/7] APS-22894 Cypress 16: read plugin values via Cypress.expose() with a Cypress.env() fallback in the TestHub and Accessibility support files Co-Authored-By: Claude Fable 5.1 --- bin/accessibility-automation/cypress/index.js | 50 +++++++++++++------ bin/accessibility-automation/plugin/index.js | 33 ++++++++---- bin/testObservability/cypress/index.js | 32 +++++++++--- bin/testObservability/plugin/index.js | 13 ++++- .../accessibility-automation/plugin/index.js | 50 +++++++++++++++++++ .../plugin/exposeToBrowser.js | 36 +++++++++++++ 6 files changed, 181 insertions(+), 33 deletions(-) create mode 100644 test/unit/bin/accessibility-automation/plugin/index.js create mode 100644 test/unit/bin/testObservability/plugin/exposeToBrowser.js diff --git a/bin/accessibility-automation/cypress/index.js b/bin/accessibility-automation/cypress/index.js index 442553b5..e18efdf6 100644 --- a/bin/accessibility-automation/cypress/index.js +++ b/bin/accessibility-automation/cypress/index.js @@ -1,7 +1,27 @@ /* Event listeners + custom commands for Cypress */ +/* + * Cypress 16 removed Cypress.env() from the browser; values set by the Node plugin now reach + * the browser through config.expose / Cypress.expose() (available from Cypress 15.10). The + * plugin writes every value to both config.env and config.expose, so read expose first and + * fall back to Cypress.env() for Cypress <= 15.x, where expose does not exist yet. [APS-22894] + */ +const bstackBrowserValue = (key) => { + try { + if (typeof Cypress.expose === 'function') { + const exposed = Cypress.expose(key); + if (exposed !== undefined && exposed !== null) return exposed; + } + } catch (e) {} + try { + return Cypress.env(key); + } catch (e) { + return undefined; + } +}; + const browserStackLog = (message) => { - if (!Cypress.env('BROWSERSTACK_LOGS')) return; + if (!bstackBrowserValue('BROWSERSTACK_LOGS')) return; cy.task('browserstack_log', message); } @@ -13,7 +33,7 @@ const browserStackLog = (message) => { let consecutiveA11yTimeouts = 0; let a11yCircuitOpen = false; let a11yCircuitLogged = false; -const getA11yCircuitLimit = () => parseInt(Cypress.env('ACCESSIBILITY_SCAN_CIRCUIT_LIMIT')) || 3; +const getA11yCircuitLimit = () => parseInt(bstackBrowserValue('ACCESSIBILITY_SCAN_CIRCUIT_LIMIT')) || 3; const noteA11yTimeout = () => { consecutiveA11yTimeouts += 1; if (!a11yCircuitOpen && consecutiveA11yTimeouts >= getA11yCircuitLimit()) { @@ -76,7 +96,7 @@ new Promise((resolve) => { } let settled = false; const finish = (val) => { if (!settled) { settled = true; clearTimeout(overallTimer); resolve(val); } }; - const overallTimeout = parseInt(Cypress.env('ACCESSIBILITY_SCAN_TIMEOUT')) || 25000; + const overallTimeout = parseInt(bstackBrowserValue('ACCESSIBILITY_SCAN_TIMEOUT')) || 25000; const overallTimer = setTimeout(() => { noteA11yTimeout(); finish("Accessibility scan timed out"); }, overallTimeout); try { @@ -252,7 +272,7 @@ new Promise((resolve) => { } let settled = false; const finish = (val) => { if (!settled) { settled = true; clearTimeout(overallTimer); resolve(val); } }; - const overallTimeout = parseInt(Cypress.env('ACCESSIBILITY_SCAN_TIMEOUT')) || 25000; + const overallTimeout = parseInt(bstackBrowserValue('ACCESSIBILITY_SCAN_TIMEOUT')) || 25000; const overallTimer = setTimeout(() => { noteA11yTimeout(); finish("Accessibility results save timed out"); }, overallTimeout); try { const isHttpOrHttps = /^(http|https):$/.test(win.location.protocol); @@ -314,24 +334,24 @@ new Promise((resolve) => { }) const shouldScanForAccessibility = (attributes) => { - if (Cypress.env("IS_ACCESSIBILITY_EXTENSION_LOADED") !== "true") return false; + if (bstackBrowserValue("IS_ACCESSIBILITY_EXTENSION_LOADED") !== "true") return false; - const extensionPath = Cypress.env("ACCESSIBILITY_EXTENSION_PATH"); + const extensionPath = bstackBrowserValue("ACCESSIBILITY_EXTENSION_PATH"); const isHeaded = Cypress.browser.isHeaded; if (!isHeaded || (extensionPath === undefined)) return false; let shouldScanTestForAccessibility = true; - if (Cypress.env("INCLUDE_TAGS_FOR_ACCESSIBILITY") || Cypress.env("EXCLUDE_TAGS_FOR_ACCESSIBILITY")) { + if (bstackBrowserValue("INCLUDE_TAGS_FOR_ACCESSIBILITY") || bstackBrowserValue("EXCLUDE_TAGS_FOR_ACCESSIBILITY")) { try { let includeTagArray = []; let excludeTagArray = []; - if (Cypress.env("INCLUDE_TAGS_FOR_ACCESSIBILITY")) { - includeTagArray = Cypress.env("INCLUDE_TAGS_FOR_ACCESSIBILITY").split(";") + if (bstackBrowserValue("INCLUDE_TAGS_FOR_ACCESSIBILITY")) { + includeTagArray = bstackBrowserValue("INCLUDE_TAGS_FOR_ACCESSIBILITY").split(";") } - if (Cypress.env("EXCLUDE_TAGS_FOR_ACCESSIBILITY")) { - excludeTagArray = Cypress.env("EXCLUDE_TAGS_FOR_ACCESSIBILITY").split(";") + if (bstackBrowserValue("EXCLUDE_TAGS_FOR_ACCESSIBILITY")) { + excludeTagArray = bstackBrowserValue("EXCLUDE_TAGS_FOR_ACCESSIBILITY").split(";") } const fullTestName = attributes.title; @@ -383,8 +403,8 @@ afterEach(() => { cy.wrap(performScan(win), {timeout: 30000}).then(() => { try { let os_data; - if (Cypress.env("OS")) { - os_data = Cypress.env("OS"); + if (bstackBrowserValue("OS")) { + os_data = bstackBrowserValue("OS"); } else { os_data = Cypress.platform === 'linux' ? 'mac' : "win" } @@ -404,8 +424,8 @@ afterEach(() => { const payloadToSend = { "thTestRunUuid": testRunUuid, - "thBuildUuid": Cypress.env("BROWSERSTACK_TESTHUB_UUID"), - "thJwtToken": Cypress.env("BROWSERSTACK_TESTHUB_JWT") + "thBuildUuid": bstackBrowserValue("BROWSERSTACK_TESTHUB_UUID"), + "thJwtToken": bstackBrowserValue("BROWSERSTACK_TESTHUB_JWT") }; browserStackLog(`Payload to send: ${JSON.stringify(payloadToSend)}`); diff --git a/bin/accessibility-automation/plugin/index.js b/bin/accessibility-automation/plugin/index.js index c51b2606..b744bc3d 100644 --- a/bin/accessibility-automation/plugin/index.js +++ b/bin/accessibility-automation/plugin/index.js @@ -3,6 +3,17 @@ const { decodeJWTToken } = require("../../helpers/utils"); const utils = require('../../helpers/utils'); const http = require('http'); +// Cypress 16 removed Cypress.env() from the browser. Values the support file needs are +// written to config.expose (read by Cypress.expose(), Cypress >= 15.10) as well as config.env +// (read by Cypress.env(), Cypress <= 15.x). Unknown config.expose is accepted by Cypress 15.8+ +// without error. [APS-22894] +const exposeToBrowser = (config, key, value) => { + config.env = config.env || {}; + config.env[key] = value; + config.expose = config.expose || {}; + config.expose[key] = value; +}; + process.env.BROWSERSTACK_ACCESSIBILITY_PLUGIN_LOADED = 'true'; const browserstackAccessibility = (on, config) => { @@ -11,7 +22,7 @@ const browserstackAccessibility = (on, config) => { process.env.BROWSERSTACK_ACCESSIBILITY_PLUGIN_LOADED = 'true'; let browser_validation = true; if (process.env.BROWSERSTACK_ACCESSIBILITY_DEBUG === 'true') { - config.env.BROWSERSTACK_LOGS = 'true'; + exposeToBrowser(config, 'BROWSERSTACK_LOGS', 'true'); process.env.BROWSERSTACK_LOGS = 'true'; } on('task', { @@ -99,18 +110,18 @@ const browserstackAccessibility = (on, config) => { } catch(err) {} }) - config.env.ACCESSIBILITY_EXTENSION_PATH = process.env.ACCESSIBILITY_EXTENSION_PATH - config.env.OS_VERSION = process.env.OS_VERSION - config.env.OS = process.env.OS - config.env.BROWSERSTACK_TESTHUB_UUID = process.env.BROWSERSTACK_TESTHUB_UUID - config.env.BROWSERSTACK_TESTHUB_JWT = process.env.BROWSERSTACK_TESTHUB_JWT - config.env.BROWSERSTACK_TESTHUB_API_PORT = process.env.BROWSERSTACK_TESTHUB_API_PORT - config.env.REPORTER_API_PORT_NO = process.env.REPORTER_API_PORT_NO + exposeToBrowser(config, 'ACCESSIBILITY_EXTENSION_PATH', process.env.ACCESSIBILITY_EXTENSION_PATH) + exposeToBrowser(config, 'OS_VERSION', process.env.OS_VERSION) + exposeToBrowser(config, 'OS', process.env.OS) + exposeToBrowser(config, 'BROWSERSTACK_TESTHUB_UUID', process.env.BROWSERSTACK_TESTHUB_UUID) + exposeToBrowser(config, 'BROWSERSTACK_TESTHUB_JWT', process.env.BROWSERSTACK_TESTHUB_JWT) + exposeToBrowser(config, 'BROWSERSTACK_TESTHUB_API_PORT', process.env.BROWSERSTACK_TESTHUB_API_PORT) + exposeToBrowser(config, 'REPORTER_API_PORT_NO', process.env.REPORTER_API_PORT_NO) - config.env.IS_ACCESSIBILITY_EXTENSION_LOADED = browser_validation.toString() + exposeToBrowser(config, 'IS_ACCESSIBILITY_EXTENSION_LOADED', browser_validation.toString()) - config.env.INCLUDE_TAGS_FOR_ACCESSIBILITY = process.env.ACCESSIBILITY_INCLUDETAGSINTESTINGSCOPE - config.env.EXCLUDE_TAGS_FOR_ACCESSIBILITY = process.env.ACCESSIBILITY_EXCLUDETAGSINTESTINGSCOPE + exposeToBrowser(config, 'INCLUDE_TAGS_FOR_ACCESSIBILITY', process.env.ACCESSIBILITY_INCLUDETAGSINTESTINGSCOPE) + exposeToBrowser(config, 'EXCLUDE_TAGS_FOR_ACCESSIBILITY', process.env.ACCESSIBILITY_EXCLUDETAGSINTESTINGSCOPE) return config; } diff --git a/bin/testObservability/cypress/index.js b/bin/testObservability/cypress/index.js index cef4aeed..8707e214 100644 --- a/bin/testObservability/cypress/index.js +++ b/bin/testObservability/cypress/index.js @@ -1,5 +1,25 @@ /* Event listeners + custom commands for Cypress */ +/* + * Cypress 16 removed Cypress.env() from the browser; values set by the Node plugin now reach + * the browser through config.expose / Cypress.expose() (available from Cypress 15.10). The + * plugin writes every value to both config.env and config.expose, so read expose first and + * fall back to Cypress.env() for Cypress <= 15.x, where expose does not exist yet. [APS-22894] + */ +const bstackBrowserValue = (key) => { + try { + if (typeof Cypress.expose === 'function') { + const exposed = Cypress.expose(key); + if (exposed !== undefined && exposed !== null) return exposed; + } + } catch (e) {} + try { + return Cypress.env(key); + } catch (e) { + return undefined; + } +}; + /* Used to detect Gherkin steps */ const STEP_KEYWORDS = ['given', 'when', 'then', 'and', 'but', '*']; @@ -42,12 +62,12 @@ const sanitizeForTask = (data) => { const browserStackLog = (message) => { - if (!Cypress.env('BROWSERSTACK_LOGS')) return; + if (!bstackBrowserValue('BROWSERSTACK_LOGS')) return; cy.task('browserstack_log', message); } const shouldSkipCommand = (command) => { - if (!Cypress.env('BROWSERSTACK_O11Y_LOGS')) { + if (!bstackBrowserValue('BROWSERSTACK_O11Y_LOGS')) { return true; } /* the batch task is filtered too, else each dispatch refills the queue */ @@ -55,7 +75,7 @@ const shouldSkipCommand = (command) => { } Cypress.on('log:changed', (attrs) => { - if (!Cypress.env('BROWSERSTACK_O11Y_LOGS')) return; + if (!bstackBrowserValue('BROWSERSTACK_O11Y_LOGS')) return; if (!attrs) return; if (!attrs.createdAtTimestamp || !attrs.updatedAtTimestamp) return; if (attrs.state !== 'passed' && attrs.state !== 'failed') return; @@ -237,7 +257,7 @@ Cypress.on('command:end', (command) => { }); Cypress.on('command:enqueued', (attrs) => { - if (!Cypress.env('BROWSERSTACK_O11Y_LOGS')) return; + if (!bstackBrowserValue('BROWSERSTACK_O11Y_LOGS')) return; if (!attrs || attrs.name !== 'log') return; const args = attrs.args || []; if (args.includes('test_observability_log') || args.includes('test_observability_command')) return; @@ -420,7 +440,7 @@ const flushEventsQueue = () => { beforeEach(() => { /* browserstack internal helper hook */ - if (!Cypress.env('BROWSERSTACK_O11Y_LOGS')) { + if (!bstackBrowserValue('BROWSERSTACK_O11Y_LOGS')) { return; } @@ -430,7 +450,7 @@ beforeEach(() => { afterEach(function() { /* browserstack internal helper hook */ - if (!Cypress.env('BROWSERSTACK_O11Y_LOGS')) { + if (!bstackBrowserValue('BROWSERSTACK_O11Y_LOGS')) { return; } diff --git a/bin/testObservability/plugin/index.js b/bin/testObservability/plugin/index.js index 286a4492..f5dee4ab 100644 --- a/bin/testObservability/plugin/index.js +++ b/bin/testObservability/plugin/index.js @@ -2,10 +2,21 @@ const ipc = require('node-ipc'); const { connectIPCClient } = require('./ipcClient'); const { IPC_EVENTS } = require('../helper/constants'); +// Cypress 16 removed Cypress.env() from the browser. Values the support file needs are +// written to config.expose (read by Cypress.expose(), Cypress >= 15.10) as well as config.env +// (read by Cypress.env(), Cypress <= 15.x). Unknown config.expose is accepted by Cypress 15.8+ +// without error. [APS-22894] +const exposeToBrowser = (config, key, value) => { + config.env = config.env || {}; + config.env[key] = value; + config.expose = config.expose || {}; + config.expose[key] = value; +}; + const browserstackTestObservabilityPlugin = (on, config, callbacks) => { try { - config.env.BROWSERSTACK_O11Y_LOGS = 'true'; + exposeToBrowser(config, 'BROWSERSTACK_O11Y_LOGS', 'true'); process.env.BROWSERSTACK_O11Y_LOGS = 'true'; } catch (err) {} diff --git a/test/unit/bin/accessibility-automation/plugin/index.js b/test/unit/bin/accessibility-automation/plugin/index.js new file mode 100644 index 00000000..7f648956 --- /dev/null +++ b/test/unit/bin/accessibility-automation/plugin/index.js @@ -0,0 +1,50 @@ +'use strict'; +const { expect } = require('chai'); +const sinon = require('sinon'); + +// APS-22894: Cypress 16 removed Cypress.env() from the browser, so every value the +// accessibility support file reads must also be written to config.expose. +describe('accessibility plugin exposes browser values', () => { + const KEYS = [ + 'ACCESSIBILITY_EXTENSION_PATH', 'OS_VERSION', 'OS', 'BROWSERSTACK_TESTHUB_UUID', + 'BROWSERSTACK_TESTHUB_JWT', 'BROWSERSTACK_TESTHUB_API_PORT', 'REPORTER_API_PORT_NO', + 'IS_ACCESSIBILITY_EXTENSION_LOADED', 'INCLUDE_TAGS_FOR_ACCESSIBILITY', 'EXCLUDE_TAGS_FOR_ACCESSIBILITY', + ]; + const saved = {}; + const ENV = { + ACCESSIBILITY_EXTENSION_PATH: '/tmp/a11y-ext', OS_VERSION: '11', OS: 'Windows', + BROWSERSTACK_TESTHUB_UUID: 'uuid-1', BROWSERSTACK_TESTHUB_JWT: 'jwt-1', + BROWSERSTACK_TESTHUB_API_PORT: '4567', REPORTER_API_PORT_NO: '4568', + ACCESSIBILITY_INCLUDETAGSINTESTINGSCOPE: 'a;b', ACCESSIBILITY_EXCLUDETAGSINTESTINGSCOPE: 'c', + BROWSERSTACK_ACCESSIBILITY_DEBUG: 'true', + }; + + beforeEach(() => { + Object.keys(ENV).forEach((k) => { saved[k] = process.env[k]; process.env[k] = ENV[k]; }); + }); + afterEach(() => { + Object.keys(ENV).forEach((k) => { if (saved[k] === undefined) delete process.env[k]; else process.env[k] = saved[k]; }); + }); + + const run = (config) => { + const plugin = require('../../../../../bin/accessibility-automation/plugin/index.js'); + return plugin(sinon.stub(), config); + }; + + it('mirrors every browser-read value into config.expose', () => { + const config = run({ env: {} }); + KEYS.forEach((key) => { + expect(config.env, key).to.have.property(key); + expect(config.expose[key], key).to.eql(config.env[key]); + }); + expect(config.expose.ACCESSIBILITY_EXTENSION_PATH).to.eql('/tmp/a11y-ext'); + expect(config.expose.INCLUDE_TAGS_FOR_ACCESSIBILITY).to.eql('a;b'); + expect(config.expose.IS_ACCESSIBILITY_EXTENSION_LOADED).to.eql('true'); + }); + + it('exposes BROWSERSTACK_LOGS when accessibility debug is on', () => { + const config = run({ env: {} }); + expect(config.env.BROWSERSTACK_LOGS).to.eql('true'); + expect(config.expose.BROWSERSTACK_LOGS).to.eql('true'); + }); +}); diff --git a/test/unit/bin/testObservability/plugin/exposeToBrowser.js b/test/unit/bin/testObservability/plugin/exposeToBrowser.js new file mode 100644 index 00000000..74d81258 --- /dev/null +++ b/test/unit/bin/testObservability/plugin/exposeToBrowser.js @@ -0,0 +1,36 @@ +'use strict'; +const { expect } = require('chai'); +const sinon = require('sinon'); +const proxyquire = require('proxyquire').noCallThru(); + +// APS-22894: Cypress 16 removed Cypress.env() from the browser, so every value the +// support file reads must also be written to config.expose (Cypress.expose()). +describe('testObservability plugin exposes browser values', () => { + const load = () => proxyquire('../../../../../bin/testObservability/plugin/index.js', { + 'node-ipc': { of: {} }, + './ipcClient': { connectIPCClient: sinon.stub() }, + }); + + it('writes BROWSERSTACK_O11Y_LOGS to both config.env and config.expose', () => { + const plugin = load(); + const config = { env: {} }; + plugin(sinon.stub(), config, {}); + expect(config.env.BROWSERSTACK_O11Y_LOGS).to.eql('true'); + expect(config.expose.BROWSERSTACK_O11Y_LOGS).to.eql('true'); + }); + + it('creates config.expose when the project config has none', () => { + const plugin = load(); + const config = { env: {} }; + plugin(sinon.stub(), config, {}); + expect(config.expose).to.be.an('object'); + }); + + it('keeps values a customer already exposed', () => { + const plugin = load(); + const config = { env: {}, expose: { CUSTOMER_FLAG: '1' } }; + plugin(sinon.stub(), config, {}); + expect(config.expose.CUSTOMER_FLAG).to.eql('1'); + expect(config.expose.BROWSERSTACK_O11Y_LOGS).to.eql('true'); + }); +}); From 626846245ba68c4bdaaf250c440bc9383f5c99c1 Mon Sep 17 00:00:00 2001 From: Anish Sinha Date: Fri, 30 Oct 2026 10:31:14 +0530 Subject: [PATCH 2/7] APS-22894 Cypress 16: forward customer ACCESSIBILITY_SCAN_TIMEOUT / CIRCUIT_LIMIT to config.expose Customers set these in their Cypress env config. Cypress 16 no longer passes config.env to the browser, so the support file fell back to the defaults (25000 ms / 3). Copy them into config.expose when set, without overriding a value the customer already exposed. Co-Authored-By: Claude Opus 5.5 --- bin/accessibility-automation/plugin/index.js | 8 ++++++++ .../accessibility-automation/plugin/index.js | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/bin/accessibility-automation/plugin/index.js b/bin/accessibility-automation/plugin/index.js index b744bc3d..3d9b5011 100644 --- a/bin/accessibility-automation/plugin/index.js +++ b/bin/accessibility-automation/plugin/index.js @@ -123,6 +123,14 @@ const browserstackAccessibility = (on, config) => { exposeToBrowser(config, 'INCLUDE_TAGS_FOR_ACCESSIBILITY', process.env.ACCESSIBILITY_INCLUDETAGSINTESTINGSCOPE) exposeToBrowser(config, 'EXCLUDE_TAGS_FOR_ACCESSIBILITY', process.env.ACCESSIBILITY_EXCLUDETAGSINTESTINGSCOPE) + // Customer-tunable keys arrive via config.env, which Cypress 16 no longer passes to the browser. + const customerScanKeys = ['ACCESSIBILITY_SCAN_TIMEOUT', 'ACCESSIBILITY_SCAN_CIRCUIT_LIMIT']; + customerScanKeys.forEach((key) => { + if (config.env[key] !== undefined && config.expose[key] === undefined) { + config.expose[key] = config.env[key]; + } + }); + return config; } diff --git a/test/unit/bin/accessibility-automation/plugin/index.js b/test/unit/bin/accessibility-automation/plugin/index.js index 7f648956..ff774b5c 100644 --- a/test/unit/bin/accessibility-automation/plugin/index.js +++ b/test/unit/bin/accessibility-automation/plugin/index.js @@ -47,4 +47,21 @@ describe('accessibility plugin exposes browser values', () => { expect(config.env.BROWSERSTACK_LOGS).to.eql('true'); expect(config.expose.BROWSERSTACK_LOGS).to.eql('true'); }); + + it('forwards customer-set scan timeout and circuit limit from config.env to config.expose', () => { + const config = run({ env: { ACCESSIBILITY_SCAN_TIMEOUT: 1234, ACCESSIBILITY_SCAN_CIRCUIT_LIMIT: 5 } }); + expect(config.expose.ACCESSIBILITY_SCAN_TIMEOUT).to.eql(1234); + expect(config.expose.ACCESSIBILITY_SCAN_CIRCUIT_LIMIT).to.eql(5); + }); + + it('does not override scan values the customer already set in config.expose', () => { + const config = run({ env: { ACCESSIBILITY_SCAN_TIMEOUT: 1234 }, expose: { ACCESSIBILITY_SCAN_TIMEOUT: 9999 } }); + expect(config.expose.ACCESSIBILITY_SCAN_TIMEOUT).to.eql(9999); + }); + + it('leaves scan keys out of config.expose when the customer did not set them', () => { + const config = run({ env: {} }); + expect(config.expose).to.not.have.property('ACCESSIBILITY_SCAN_TIMEOUT'); + expect(config.expose).to.not.have.property('ACCESSIBILITY_SCAN_CIRCUIT_LIMIT'); + }); }); From 585ae8d13e706b452d60d0235ce1fd89af79de39 Mon Sep 17 00:00:00 2001 From: Priyanka Vats Date: Wed, 18 Nov 2026 12:54:28 +0530 Subject: [PATCH 3/7] APS-22894 Cypress 16: send run_settings.cypressExposeSupport Tells Rails this CLI's TestHub and Accessibility support files read Cypress.expose(), so it may default the build to Cypress 16. Rails keeps CLIs without the flag on Cypress 15 and asks them to upgrade before running 16, where Cypress.env() throws. Co-Authored-By: Claude Opus 5.5 --- bin/helpers/capabilityHelper.js | 3 +++ test/unit/bin/helpers/capabilityHelper.js | 31 +++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/bin/helpers/capabilityHelper.js b/bin/helpers/capabilityHelper.js index 7f8bef59..1bbef885 100644 --- a/bin/helpers/capabilityHelper.js +++ b/bin/helpers/capabilityHelper.js @@ -128,6 +128,9 @@ const caps = (bsConfig, zip) => { bsConfig.run_settings["accessibilityPlatforms"] = getAccessibilityPlatforms(bsConfig); } + // Tells Rails this CLI's support files read Cypress.expose(), so it may run Cypress 16+. + bsConfig.run_settings["cypressExposeSupport"] = true; + // send run_settings as is for other capabilities obj.run_settings = JSON.stringify(bsConfig.run_settings); } diff --git a/test/unit/bin/helpers/capabilityHelper.js b/test/unit/bin/helpers/capabilityHelper.js index 2cfc5699..0f0846d2 100644 --- a/test/unit/bin/helpers/capabilityHelper.js +++ b/test/unit/bin/helpers/capabilityHelper.js @@ -78,6 +78,37 @@ describe("capabilityHelper.js", () => { }); }); + it("tells Rails it supports Cypress.expose()", () => { + let zip_url = "bs://"; + let bsConfig = { + auth: { + username: "random", + access_key: "random", + }, + browsers: [ + { + browser: "chrome", + os: "Windows 10", + versions: ["78"], + }, + ], + run_settings: { + cypress_version: "16" + }, + connection_settings: { + local: false + } + }; + return capabilityHelper + .caps(bsConfig, { zip_url: zip_url }) + .then(function (data) { + chai.assert.equal(JSON.parse(JSON.parse(data).run_settings).cypressExposeSupport, true); + }) + .catch((error) => { + chai.assert.fail("Promise error"); + }); + }); + it("handle empty test_suite", () => { let zip_url = undefined; let incorrectBsConfig = { From a40ac2c317b41fc2aa16ebb8004d1b485b1650b8 Mon Sep 17 00:00:00 2001 From: Priyanka Vats Date: Thu, 19 Nov 2026 18:19:07 +0530 Subject: [PATCH 4/7] feat(helpers): keep accessibility builds on Cypress 15 Accessibility does not support Cypress 16 yet. With accessibility on, a build that sends no cypress_version asks for 15, and one that asks for 16 or later is stopped before upload with ACCESSIBILITY_CYPRESS_VERSION_UNSUPPORTED. Raising MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY lifts the cap without a Rails change. Refs APS-22894 Co-Authored-By: Claude Opus 5.5 --- bin/helpers/capabilityHelper.js | 21 +++++- bin/helpers/constants.js | 8 +++ bin/helpers/utils.js | 3 + test/unit/bin/helpers/capabilityHelper.js | 82 +++++++++++++++++++++++ test/unit/bin/helpers/utils.js | 5 ++ 5 files changed, 118 insertions(+), 1 deletion(-) diff --git a/bin/helpers/capabilityHelper.js b/bin/helpers/capabilityHelper.js index 1bbef885..ad344639 100644 --- a/bin/helpers/capabilityHelper.js +++ b/bin/helpers/capabilityHelper.js @@ -7,6 +7,14 @@ const logger = require("./logger").winstonLogger, Utils = require("./utils"), testhubUtils = require("../testhub/utils"); +const isAccessibilityOn = (bsConfig) => + process.env.BROWSERSTACK_TEST_ACCESSIBILITY === 'true' || String(bsConfig.run_settings.accessibility) === 'true'; + +const isAboveAccessibilityCypressMajor = (cypressVersion) => { + const major = String(cypressVersion).match(/^(\d+)/); + return !!major && Number(major[1]) > Constants.MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY; +}; + const caps = (bsConfig, zip) => { return new Promise(function (resolve, reject) { let user = undefined; @@ -132,7 +140,14 @@ const caps = (bsConfig, zip) => { bsConfig.run_settings["cypressExposeSupport"] = true; // send run_settings as is for other capabilities - obj.run_settings = JSON.stringify(bsConfig.run_settings); + let runSettings = bsConfig.run_settings; + // Rails defaults to its newest Cypress, which accessibility does not support yet, so an + // accessibility build without a version asks for the newest major accessibility supports. + if (isAccessibilityOn(bsConfig) && Utils.isUndefined(runSettings.cypress_version)) { + runSettings = Object.assign({}, runSettings, { cypress_version: String(Constants.MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY) }); + logger.info(Constants.userMessages.ACCESSIBILITY_CYPRESS_VERSION_PINNED); + } + obj.run_settings = JSON.stringify(runSettings); } // The only route by which a cypress session can name its TestHub build: every session @@ -223,6 +238,10 @@ const validate = (bsConfig, args) => { if (!bsConfig.run_settings) reject(Constants.validationMessages.EMPTY_RUN_SETTINGS); + if (bsConfig.run_settings && isAccessibilityOn(bsConfig) && isAboveAccessibilityCypressMajor(bsConfig.run_settings.cypress_version)) { + reject(Constants.validationMessages.ACCESSIBILITY_CYPRESS_VERSION_UNSUPPORTED); + } + if (!bsConfig.run_settings.cypressConfigFilePath && !bsConfig.run_settings.userProvidedCypessConfigFile) { reject(Constants.validationMessages.EMPTY_CYPRESS_CONFIG_FILE); } diff --git a/bin/helpers/constants.js b/bin/helpers/constants.js index c0bdd495..0d858178 100644 --- a/bin/helpers/constants.js +++ b/bin/helpers/constants.js @@ -86,6 +86,8 @@ const userMessages = { FATAL_NETWORK_ERROR: `fatal: unable to access '${config.buildUrl}': Could not resolve host: ${config.rails_host}`, RETRY_LIMIT_EXCEEDED: `Max retries exceeded trying to connect to the host (retries: ${config.retries})`, CHECK_DASHBOARD_AT: "Please check the build status at: ", + ACCESSIBILITY_CYPRESS_VERSION_PINNED: + "Accessibility Testing supports Cypress up to version 15, so this build runs on the latest Cypress 15.", CYPRESS_VERSION_CHANGED: "Your build will run using Cypress instead of Cypress . Read more about supported versions here: http://browserstack.com/docs/automate/cypress/supported-versions", LOCAL_START_FAILED: "Local Testing setup failed.", @@ -198,6 +200,8 @@ const validationMessages = { "You have specified '--record' flag but you've not provided the '--record-key' and we could not find any value in 'CYPRESS_RECORD_KEY' environment variable. Your record functionality on cypress.io dashboard might not work as it needs the key and projectId", NODE_VERSION_PARSING_ERROR: "We weren't able to successfully parse the specified nodeVersion. We will be using the default nodeVersion to run your tests.", + ACCESSIBILITY_CYPRESS_VERSION_UNSUPPORTED: + "Accessibility Testing supports Cypress up to version 15. Set cypress_version to 15 in browserstack.json, or turn off accessibility to run Cypress 16 or later.", AUTO_IMPORT_CONFLICT_ERROR: "Cannot use both 'auto_import_dev_dependencies' and manual npm dependency configuration. Please either set 'auto_import_dev_dependencies' to false or remove manual 'npm_dependencies', 'win_npm_dependencies', and 'mac_npm_dependencies' configurations.", AUTO_IMPORT_INVALID_TYPE: @@ -443,6 +447,9 @@ const REDACTED_AUTH = `auth: { "username": ${REDACTED}, "access_key": ${REDACTED const SPEC_TIMEOUT_LIMIT = 120; // IN MINS +// Accessibility does not support Cypress 16 yet (APS-22894). Raising this needs no Rails change. +const MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY = 15; + const CYPRESS_CUSTOM_ERRORS_TO_PRINT_KEY = "custom_errors_to_print"; const CYPRESS_V9_AND_OLDER_TYPE = "CYPRESS_V9_AND_OLDER_TYPE"; @@ -508,6 +515,7 @@ module.exports = Object.freeze({ REDACTED, BUILD_FAILED_EXIT_CODE, SPEC_TIMEOUT_LIMIT, + MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY, CYPRESS_CUSTOM_ERRORS_TO_PRINT_KEY, CYPRESS_V9_AND_OLDER_TYPE, CYPRESS_V10_AND_ABOVE_TYPE, diff --git a/bin/helpers/utils.js b/bin/helpers/utils.js index 2cc7f133..3e8229d9 100644 --- a/bin/helpers/utils.js +++ b/bin/helpers/utils.js @@ -102,6 +102,9 @@ exports.getErrorCodeFromMsg = (errMsg) => { case Constants.validationMessages.INVALID_GEO_LOCATION: errorCode = 'invalid_geo_location'; break; + case Constants.validationMessages.ACCESSIBILITY_CYPRESS_VERSION_UNSUPPORTED: + errorCode = 'accessibility_cypress_version_unsupported'; + break; case Constants.validationMessages.NOT_ALLOWED_GEO_LOCATION_AND_LOCAL_MODE: errorCode = 'not_allowed_geo_location_and_local_mode'; break; diff --git a/test/unit/bin/helpers/capabilityHelper.js b/test/unit/bin/helpers/capabilityHelper.js index 0f0846d2..15ec65be 100644 --- a/test/unit/bin/helpers/capabilityHelper.js +++ b/test/unit/bin/helpers/capabilityHelper.js @@ -109,6 +109,39 @@ describe("capabilityHelper.js", () => { }); }); + describe("cypress_version sent with accessibility", () => { + const sentRunSettings = (runSettings) => { + let bsConfig = { + auth: { username: "random", access_key: "random" }, + browsers: [{ browser: "chrome", os: "Windows 10", versions: ["78"] }], + run_settings: runSettings, + connection_settings: { local: false } + }; + return capabilityHelper + .caps(bsConfig, { zip_url: "bs://" }) + .then((data) => ({ sent: JSON.parse(JSON.parse(data).run_settings), bsConfig })); + }; + + it("asks for Cypress 15 when accessibility is on and no version is given", () => { + return sentRunSettings({ accessibility: true }).then(({ sent, bsConfig }) => { + chai.assert.equal(sent.cypress_version, "15"); + chai.assert.isUndefined(bsConfig.run_settings.cypress_version); + }); + }); + + it("keeps the user's version when accessibility is on", () => { + return sentRunSettings({ accessibility: true, cypress_version: "15.10.0" }).then(({ sent }) => { + chai.assert.equal(sent.cypress_version, "15.10.0"); + }); + }); + + it("sends no version when accessibility is off and none is given", () => { + return sentRunSettings({ accessibility: false }).then(({ sent }) => { + chai.assert.isUndefined(sent.cypress_version); + }); + }); + }); + it("handle empty test_suite", () => { let zip_url = undefined; let incorrectBsConfig = { @@ -755,6 +788,55 @@ describe("capabilityHelper.js", () => { describe("validate", () => { + describe("validate cypress_version when accessibility is on", () => { + let savedA11yEnv; + const a11yConfig = (runSettings) => ({ + auth: {}, + browsers: [{ browser: "chrome", os: "Windows 10", versions: ["78"] }], + run_settings: runSettings, + }); + const validateError = (bsConfig) => + capabilityHelper.validate(bsConfig, { parallels: undefined }).then(() => undefined, (error) => error); + + beforeEach(() => { + savedA11yEnv = process.env.BROWSERSTACK_TEST_ACCESSIBILITY; + delete process.env.BROWSERSTACK_TEST_ACCESSIBILITY; + }); + + afterEach(() => { + if (savedA11yEnv === undefined) delete process.env.BROWSERSTACK_TEST_ACCESSIBILITY; + else process.env.BROWSERSTACK_TEST_ACCESSIBILITY = savedA11yEnv; + }); + + ["16", "16.2.0", "16.latest", 17].forEach((version) => { + it(`rejects cypress_version ${version} with accessibility on`, () => { + return validateError(a11yConfig({ accessibility: true, cypress_version: version })).then((error) => { + chai.assert.equal(error, Constants.validationMessages.ACCESSIBILITY_CYPRESS_VERSION_UNSUPPORTED); + }); + }); + }); + + it("rejects cypress_version 16 when accessibility is on through BROWSERSTACK_TEST_ACCESSIBILITY", () => { + process.env.BROWSERSTACK_TEST_ACCESSIBILITY = 'true'; + return validateError(a11yConfig({ cypress_version: "16" })).then((error) => { + chai.assert.equal(error, Constants.validationMessages.ACCESSIBILITY_CYPRESS_VERSION_UNSUPPORTED); + }); + }); + + [ + ["cypress_version 15 with accessibility on", { accessibility: true, cypress_version: "15" }], + ["no cypress_version with accessibility on", { accessibility: "true" }], + ["cypress_version 16 with accessibility off", { accessibility: false, cypress_version: "16" }], + ["cypress_version 16 without accessibility", { cypress_version: "16" }], + ].forEach(([name, runSettings]) => { + it(`does not reject ${name} for accessibility`, () => { + return validateError(a11yConfig(runSettings)).then((error) => { + chai.assert.notEqual(error, Constants.validationMessages.ACCESSIBILITY_CYPRESS_VERSION_UNSUPPORTED); + }); + }); + }); + }); + describe("validate parallels specified in bsconfig and arguments", () => { beforeEach(() => { //Stub for cypress json validation diff --git a/test/unit/bin/helpers/utils.js b/test/unit/bin/helpers/utils.js index 480cb5f4..14c97264 100644 --- a/test/unit/bin/helpers/utils.js +++ b/test/unit/bin/helpers/utils.js @@ -41,6 +41,11 @@ describe('utils', () => { constant.validationMessages.EMPTY_BROWSERSTACK_JSON ) ).to.eq('bstack_json_invalid_empty'); + expect( + utils.getErrorCodeFromMsg( + constant.validationMessages.ACCESSIBILITY_CYPRESS_VERSION_UNSUPPORTED + ) + ).to.eq('accessibility_cypress_version_unsupported'); expect( utils.getErrorCodeFromMsg( constant.validationMessages.INCORRECT_AUTH_PARAMS From faff37372e2d1770c721f16f9b0e00ed734005e6 Mon Sep 17 00:00:00 2001 From: Aakash Hotchandani Date: Fri, 20 Nov 2026 18:06:17 +0530 Subject: [PATCH 5/7] SDK-8048: run accessibility on Cypress 16 with forceHttp1 Cypress 16.2.0's default network mode never starts the a11y extension's service worker (cypress-io/cypress#35127, fixed in 16.2.1), so every scan waits out the 25s timeout and the build still passes. forceHttp1 avoids it: on the same preprod Ventura pool, the scan step took 25.6s without it and 4.2s with it (15.21.1: 5.0s). - Accessibility builds on Cypress 16 get forceHttp1=true added to run_settings.config. Other config keys are kept, and a forceHttp1 the user already set (true or false) is left alone. - MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY 15 -> 16, so 16 is allowed and 17+ is still refused. - Builds with no cypress_version still ask for 15 (DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY), matching Rails' default. Co-Authored-By: Claude Opus 5.5 --- bin/helpers/capabilityHelper.js | 29 ++++++++++++-- bin/helpers/constants.js | 19 +++++++-- test/unit/bin/helpers/capabilityHelper.js | 48 ++++++++++++++++++++--- 3 files changed, 84 insertions(+), 12 deletions(-) diff --git a/bin/helpers/capabilityHelper.js b/bin/helpers/capabilityHelper.js index ad344639..c2c7a986 100644 --- a/bin/helpers/capabilityHelper.js +++ b/bin/helpers/capabilityHelper.js @@ -10,9 +10,22 @@ const logger = require("./logger").winstonLogger, const isAccessibilityOn = (bsConfig) => process.env.BROWSERSTACK_TEST_ACCESSIBILITY === 'true' || String(bsConfig.run_settings.accessibility) === 'true'; -const isAboveAccessibilityCypressMajor = (cypressVersion) => { +const cypressMajor = (cypressVersion) => { const major = String(cypressVersion).match(/^(\d+)/); - return !!major && Number(major[1]) > Constants.MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY; + return major ? Number(major[1]) : undefined; +}; + +const isAboveAccessibilityCypressMajor = (cypressVersion) => { + const major = cypressMajor(cypressVersion); + return major !== undefined && major > Constants.MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY; +}; + +// Adds forceHttp1=true to the run's Cypress config unless the user already set forceHttp1 +// (either way), keeping every other key they passed. +const withForceHttp1 = (config) => { + const current = Utils.isUndefined(config) ? '' : String(config).trim(); + if (/(^|,)\s*forceHttp1\s*=/.test(current)) return config; + return current ? `${current},forceHttp1=true` : 'forceHttp1=true'; }; const caps = (bsConfig, zip) => { @@ -144,9 +157,19 @@ const caps = (bsConfig, zip) => { // Rails defaults to its newest Cypress, which accessibility does not support yet, so an // accessibility build without a version asks for the newest major accessibility supports. if (isAccessibilityOn(bsConfig) && Utils.isUndefined(runSettings.cypress_version)) { - runSettings = Object.assign({}, runSettings, { cypress_version: String(Constants.MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY) }); + runSettings = Object.assign({}, runSettings, { cypress_version: String(Constants.DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY) }); logger.info(Constants.userMessages.ACCESSIBILITY_CYPRESS_VERSION_PINNED); } + // Accessibility scans on Cypress 16 only complete with forceHttp1 (see the constant). + const requestedMajor = cypressMajor(runSettings.cypress_version); + if (isAccessibilityOn(bsConfig) && requestedMajor !== undefined + && requestedMajor >= Constants.MIN_CYPRESS_MAJOR_NEEDING_FORCE_HTTP1_FOR_ACCESSIBILITY) { + const config = withForceHttp1(runSettings.config); + if (config !== runSettings.config) { + runSettings = Object.assign({}, runSettings, { config }); + logger.info(Constants.userMessages.ACCESSIBILITY_FORCE_HTTP1_SET); + } + } obj.run_settings = JSON.stringify(runSettings); } diff --git a/bin/helpers/constants.js b/bin/helpers/constants.js index 0d858178..c5575c7f 100644 --- a/bin/helpers/constants.js +++ b/bin/helpers/constants.js @@ -87,7 +87,9 @@ const userMessages = { RETRY_LIMIT_EXCEEDED: `Max retries exceeded trying to connect to the host (retries: ${config.retries})`, CHECK_DASHBOARD_AT: "Please check the build status at: ", ACCESSIBILITY_CYPRESS_VERSION_PINNED: - "Accessibility Testing supports Cypress up to version 15, so this build runs on the latest Cypress 15.", + "Accessibility builds without a cypress_version run on the latest Cypress 15.", + ACCESSIBILITY_FORCE_HTTP1_SET: + "Accessibility on Cypress 16 needs Cypress's HTTP/1.1 proxy, so this build runs with forceHttp1=true.", CYPRESS_VERSION_CHANGED: "Your build will run using Cypress instead of Cypress . Read more about supported versions here: http://browserstack.com/docs/automate/cypress/supported-versions", LOCAL_START_FAILED: "Local Testing setup failed.", @@ -201,7 +203,7 @@ const validationMessages = { NODE_VERSION_PARSING_ERROR: "We weren't able to successfully parse the specified nodeVersion. We will be using the default nodeVersion to run your tests.", ACCESSIBILITY_CYPRESS_VERSION_UNSUPPORTED: - "Accessibility Testing supports Cypress up to version 15. Set cypress_version to 15 in browserstack.json, or turn off accessibility to run Cypress 16 or later.", + "Accessibility Testing supports Cypress up to version 16. Set cypress_version to 16 or lower in browserstack.json, or turn off accessibility to run a later Cypress.", AUTO_IMPORT_CONFLICT_ERROR: "Cannot use both 'auto_import_dev_dependencies' and manual npm dependency configuration. Please either set 'auto_import_dev_dependencies' to false or remove manual 'npm_dependencies', 'win_npm_dependencies', and 'mac_npm_dependencies' configurations.", AUTO_IMPORT_INVALID_TYPE: @@ -447,8 +449,15 @@ const REDACTED_AUTH = `auth: { "username": ${REDACTED}, "access_key": ${REDACTED const SPEC_TIMEOUT_LIMIT = 120; // IN MINS -// Accessibility does not support Cypress 16 yet (APS-22894). Raising this needs no Rails change. -const MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY = 15; +// Newest Cypress major accessibility runs on (APS-22894). Raising this needs no Rails change. +const MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY = 16; +// Major an accessibility build asks for when it names no cypress_version. Stays on 15 while +// Rails' own default does, so an unpinned build keeps today's Cypress. +const DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY = 15; +// From this major the a11y extension's service worker never starts in Cypress's default network +// mode (cypress-io/cypress#35127, fixed in 16.2.1), so scans time out unless forceHttp1 is on. +// SDK-8048 preprod A/B on 16.2.0: scan step 25.6s without it, 4.2s with it. +const MIN_CYPRESS_MAJOR_NEEDING_FORCE_HTTP1_FOR_ACCESSIBILITY = 16; const CYPRESS_CUSTOM_ERRORS_TO_PRINT_KEY = "custom_errors_to_print"; @@ -516,6 +525,8 @@ module.exports = Object.freeze({ BUILD_FAILED_EXIT_CODE, SPEC_TIMEOUT_LIMIT, MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY, + DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY, + MIN_CYPRESS_MAJOR_NEEDING_FORCE_HTTP1_FOR_ACCESSIBILITY, CYPRESS_CUSTOM_ERRORS_TO_PRINT_KEY, CYPRESS_V9_AND_OLDER_TYPE, CYPRESS_V10_AND_ABOVE_TYPE, diff --git a/test/unit/bin/helpers/capabilityHelper.js b/test/unit/bin/helpers/capabilityHelper.js index 15ec65be..a153fca4 100644 --- a/test/unit/bin/helpers/capabilityHelper.js +++ b/test/unit/bin/helpers/capabilityHelper.js @@ -140,6 +140,42 @@ describe("capabilityHelper.js", () => { chai.assert.isUndefined(sent.cypress_version); }); }); + + ["16", "16.2.0", "16.latest"].forEach((version) => { + it(`adds forceHttp1=true for accessibility on cypress_version ${version}`, () => { + return sentRunSettings({ accessibility: true, cypress_version: version }).then(({ sent, bsConfig }) => { + chai.assert.equal(sent.config, "forceHttp1=true"); + chai.assert.isUndefined(bsConfig.run_settings.config); + }); + }); + }); + + it("keeps the user's other config keys when adding forceHttp1", () => { + return sentRunSettings({ accessibility: true, cypress_version: "16.2.0", config: "video=false,baseUrl=https://x.test" }).then(({ sent }) => { + chai.assert.equal(sent.config, "video=false,baseUrl=https://x.test,forceHttp1=true"); + }); + }); + + ["forceHttp1=false", "video=true, forceHttp1 = false"].forEach((config) => { + it(`does not override a forceHttp1 the user set (${config})`, () => { + return sentRunSettings({ accessibility: true, cypress_version: "16", config }).then(({ sent }) => { + chai.assert.equal(sent.config, config); + }); + }); + }); + + [ + ["accessibility on, Cypress 15", { accessibility: true, cypress_version: "15.21.1" }], + ["accessibility on, no version (pinned to 15)", { accessibility: true }], + ["accessibility off, Cypress 16", { accessibility: false, cypress_version: "16.2.0" }], + ["accessibility on, cypress_version latest", { accessibility: true, cypress_version: "latest" }], + ].forEach(([name, runSettings]) => { + it(`does not add forceHttp1 for ${name}`, () => { + return sentRunSettings(runSettings).then(({ sent }) => { + chai.assert.isUndefined(sent.config); + }); + }); + }); }); it("handle empty test_suite", () => { @@ -808,7 +844,7 @@ describe("capabilityHelper.js", () => { else process.env.BROWSERSTACK_TEST_ACCESSIBILITY = savedA11yEnv; }); - ["16", "16.2.0", "16.latest", 17].forEach((version) => { + ["17", "17.0.0", "17.latest", 18].forEach((version) => { it(`rejects cypress_version ${version} with accessibility on`, () => { return validateError(a11yConfig({ accessibility: true, cypress_version: version })).then((error) => { chai.assert.equal(error, Constants.validationMessages.ACCESSIBILITY_CYPRESS_VERSION_UNSUPPORTED); @@ -816,18 +852,20 @@ describe("capabilityHelper.js", () => { }); }); - it("rejects cypress_version 16 when accessibility is on through BROWSERSTACK_TEST_ACCESSIBILITY", () => { + it("rejects cypress_version 17 when accessibility is on through BROWSERSTACK_TEST_ACCESSIBILITY", () => { process.env.BROWSERSTACK_TEST_ACCESSIBILITY = 'true'; - return validateError(a11yConfig({ cypress_version: "16" })).then((error) => { + return validateError(a11yConfig({ cypress_version: "17" })).then((error) => { chai.assert.equal(error, Constants.validationMessages.ACCESSIBILITY_CYPRESS_VERSION_UNSUPPORTED); }); }); [ ["cypress_version 15 with accessibility on", { accessibility: true, cypress_version: "15" }], + ["cypress_version 16 with accessibility on", { accessibility: true, cypress_version: "16" }], + ["cypress_version 16.2.0 with accessibility on", { accessibility: true, cypress_version: "16.2.0" }], ["no cypress_version with accessibility on", { accessibility: "true" }], - ["cypress_version 16 with accessibility off", { accessibility: false, cypress_version: "16" }], - ["cypress_version 16 without accessibility", { cypress_version: "16" }], + ["cypress_version 17 with accessibility off", { accessibility: false, cypress_version: "17" }], + ["cypress_version 17 without accessibility", { cypress_version: "17" }], ].forEach(([name, runSettings]) => { it(`does not reject ${name} for accessibility`, () => { return validateError(a11yConfig(runSettings)).then((error) => { From 0cafced281b90c6226e1729b5cb33faed68719ea Mon Sep 17 00:00:00 2001 From: Aakash Hotchandani Date: Fri, 20 Nov 2026 18:17:08 +0530 Subject: [PATCH 6/7] SDK-8048: add forceHttp1 only for the affected Cypress versions (16.1.0 to 16.2.0) The extension service-worker bug is a regression from cypress-io/cypress#34762 (16.1.0), reported as #35127 and fixed by #34958 in 16.2.1. Builds asking for 16.2.1+ or 16.0.x no longer get forceHttp1. "16" and "16.latest" still do while 16.2.0 is the only Cypress 16 Rails offers. Co-Authored-By: Claude Opus 5.5 --- bin/helpers/capabilityHelper.js | 29 +++++++++++++++++++---- bin/helpers/constants.js | 13 +++++----- test/unit/bin/helpers/capabilityHelper.js | 5 +++- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/bin/helpers/capabilityHelper.js b/bin/helpers/capabilityHelper.js index c2c7a986..97266e5e 100644 --- a/bin/helpers/capabilityHelper.js +++ b/bin/helpers/capabilityHelper.js @@ -20,6 +20,28 @@ const isAboveAccessibilityCypressMajor = (cypressVersion) => { return major !== undefined && major > Constants.MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY; }; +const versionParts = (version) => String(version).split('.').map((n) => Number(n)); + +const isBefore = (version, other) => { + const a = versionParts(version), b = versionParts(other); + for (let i = 0; i < 3; i++) { + if ((a[i] || 0) !== (b[i] || 0)) return (a[i] || 0) < (b[i] || 0); + } + return false; +}; + +// True for an accessibility build whose Cypress has the extension service-worker bug. +// "16" and "16.latest" name no minor, so Rails picks it: they count while 16.2.0 is the only +// Cypress 16 Rails offers. Once Rails offers 16.2.1+, drop that branch. +const needsForceHttp1ForAccessibility = (cypressVersion) => { + const [firstAffected, firstFixed] = Constants.ACCESSIBILITY_FORCE_HTTP1_CYPRESS_RANGE; + const value = String(cypressVersion).trim().toLowerCase(); + const exact = value.match(/^(\d+)\.(\d+)\.(\d+)$/); + if (exact) return !isBefore(value, firstAffected) && isBefore(value, firstFixed); + const majorOnly = value.match(/^(\d+)(\.latest)?$/); + return !!majorOnly && Number(majorOnly[1]) === versionParts(firstAffected)[0]; +}; + // Adds forceHttp1=true to the run's Cypress config unless the user already set forceHttp1 // (either way), keeping every other key they passed. const withForceHttp1 = (config) => { @@ -160,10 +182,9 @@ const caps = (bsConfig, zip) => { runSettings = Object.assign({}, runSettings, { cypress_version: String(Constants.DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY) }); logger.info(Constants.userMessages.ACCESSIBILITY_CYPRESS_VERSION_PINNED); } - // Accessibility scans on Cypress 16 only complete with forceHttp1 (see the constant). - const requestedMajor = cypressMajor(runSettings.cypress_version); - if (isAccessibilityOn(bsConfig) && requestedMajor !== undefined - && requestedMajor >= Constants.MIN_CYPRESS_MAJOR_NEEDING_FORCE_HTTP1_FOR_ACCESSIBILITY) { + // Accessibility scans on the affected Cypress 16 versions only complete with forceHttp1. + if (isAccessibilityOn(bsConfig) && !Utils.isUndefined(runSettings.cypress_version) + && needsForceHttp1ForAccessibility(runSettings.cypress_version)) { const config = withForceHttp1(runSettings.config); if (config !== runSettings.config) { runSettings = Object.assign({}, runSettings, { config }); diff --git a/bin/helpers/constants.js b/bin/helpers/constants.js index c5575c7f..bc4362e1 100644 --- a/bin/helpers/constants.js +++ b/bin/helpers/constants.js @@ -89,7 +89,7 @@ const userMessages = { ACCESSIBILITY_CYPRESS_VERSION_PINNED: "Accessibility builds without a cypress_version run on the latest Cypress 15.", ACCESSIBILITY_FORCE_HTTP1_SET: - "Accessibility on Cypress 16 needs Cypress's HTTP/1.1 proxy, so this build runs with forceHttp1=true.", + "Accessibility on Cypress 16.1.0-16.2.0 needs Cypress's HTTP/1.1 proxy, so this build runs with forceHttp1=true.", CYPRESS_VERSION_CHANGED: "Your build will run using Cypress instead of Cypress . Read more about supported versions here: http://browserstack.com/docs/automate/cypress/supported-versions", LOCAL_START_FAILED: "Local Testing setup failed.", @@ -454,10 +454,11 @@ const MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY = 16; // Major an accessibility build asks for when it names no cypress_version. Stays on 15 while // Rails' own default does, so an unpinned build keeps today's Cypress. const DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY = 15; -// From this major the a11y extension's service worker never starts in Cypress's default network -// mode (cypress-io/cypress#35127, fixed in 16.2.1), so scans time out unless forceHttp1 is on. -// SDK-8048 preprod A/B on 16.2.0: scan step 25.6s without it, 4.2s with it. -const MIN_CYPRESS_MAJOR_NEEDING_FORCE_HTTP1_FOR_ACCESSIBILITY = 16; +// Cypress versions where the a11y extension's service worker never starts, so every scan times +// out unless forceHttp1 is on: [first affected, first fixed). Regression from cypress-io/cypress#34762 +// (16.1.0), reported as cypress-io/cypress#35127, fixed by #34958 in 16.2.1. +// SDK-8048 preprod A/B on 16.2.0: scan step 25.6s without forceHttp1, 4.2s with it. +const ACCESSIBILITY_FORCE_HTTP1_CYPRESS_RANGE = ['16.1.0', '16.2.1']; const CYPRESS_CUSTOM_ERRORS_TO_PRINT_KEY = "custom_errors_to_print"; @@ -526,7 +527,7 @@ module.exports = Object.freeze({ SPEC_TIMEOUT_LIMIT, MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY, DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY, - MIN_CYPRESS_MAJOR_NEEDING_FORCE_HTTP1_FOR_ACCESSIBILITY, + ACCESSIBILITY_FORCE_HTTP1_CYPRESS_RANGE, CYPRESS_CUSTOM_ERRORS_TO_PRINT_KEY, CYPRESS_V9_AND_OLDER_TYPE, CYPRESS_V10_AND_ABOVE_TYPE, diff --git a/test/unit/bin/helpers/capabilityHelper.js b/test/unit/bin/helpers/capabilityHelper.js index a153fca4..5eb3cb22 100644 --- a/test/unit/bin/helpers/capabilityHelper.js +++ b/test/unit/bin/helpers/capabilityHelper.js @@ -141,7 +141,7 @@ describe("capabilityHelper.js", () => { }); }); - ["16", "16.2.0", "16.latest"].forEach((version) => { + ["16", "16.latest", "16.1.0", "16.1.1", "16.2.0"].forEach((version) => { it(`adds forceHttp1=true for accessibility on cypress_version ${version}`, () => { return sentRunSettings({ accessibility: true, cypress_version: version }).then(({ sent, bsConfig }) => { chai.assert.equal(sent.config, "forceHttp1=true"); @@ -169,6 +169,9 @@ describe("capabilityHelper.js", () => { ["accessibility on, no version (pinned to 15)", { accessibility: true }], ["accessibility off, Cypress 16", { accessibility: false, cypress_version: "16.2.0" }], ["accessibility on, cypress_version latest", { accessibility: true, cypress_version: "latest" }], + ["accessibility on, Cypress 16.2.1 (fixed)", { accessibility: true, cypress_version: "16.2.1" }], + ["accessibility on, Cypress 16.3.0 (fixed)", { accessibility: true, cypress_version: "16.3.0" }], + ["accessibility on, Cypress 16.0.0 (before the regression)", { accessibility: true, cypress_version: "16.0.0" }], ].forEach(([name, runSettings]) => { it(`does not add forceHttp1 for ${name}`, () => { return sentRunSettings(runSettings).then(({ sent }) => { From 7ca0e7b18b8ad2f895d4817ec7bff3bdd4010039 Mon Sep 17 00:00:00 2001 From: Aakash Hotchandani Date: Mon, 23 Nov 2026 15:04:40 +0530 Subject: [PATCH 7/7] SDK-8048: address #1206 review (forceHttp1 on every Cypress 16 a11y build, comments, test env restore) - forceHttp1 keyed on major 16: Rails runs 16.2.0 for any 16.x it doesn't list (CypressFramework#evaluate_users_cypress_version_further), so 16.2.1/16.3.0/16.0.0/16.2 requests also run the affected version. - DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY / caps() comments give the real reason for 15. - accessibility plugin test restores BROWSERSTACK_LOGS and BROWSERSTACK_ACCESSIBILITY_PLUGIN_LOADED. Co-Authored-By: Claude Opus 5.5 --- bin/helpers/capabilityHelper.js | 34 ++++++------------- bin/helpers/constants.js | 18 +++++----- .../accessibility-automation/plugin/index.js | 9 +++-- test/unit/bin/helpers/capabilityHelper.js | 7 ++-- 4 files changed, 30 insertions(+), 38 deletions(-) diff --git a/bin/helpers/capabilityHelper.js b/bin/helpers/capabilityHelper.js index 97266e5e..b6068548 100644 --- a/bin/helpers/capabilityHelper.js +++ b/bin/helpers/capabilityHelper.js @@ -20,27 +20,13 @@ const isAboveAccessibilityCypressMajor = (cypressVersion) => { return major !== undefined && major > Constants.MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY; }; -const versionParts = (version) => String(version).split('.').map((n) => Number(n)); - -const isBefore = (version, other) => { - const a = versionParts(version), b = versionParts(other); - for (let i = 0; i < 3; i++) { - if ((a[i] || 0) !== (b[i] || 0)) return (a[i] || 0) < (b[i] || 0); - } - return false; -}; - -// True for an accessibility build whose Cypress has the extension service-worker bug. -// "16" and "16.latest" name no minor, so Rails picks it: they count while 16.2.0 is the only -// Cypress 16 Rails offers. Once Rails offers 16.2.1+, drop that branch. -const needsForceHttp1ForAccessibility = (cypressVersion) => { - const [firstAffected, firstFixed] = Constants.ACCESSIBILITY_FORCE_HTTP1_CYPRESS_RANGE; - const value = String(cypressVersion).trim().toLowerCase(); - const exact = value.match(/^(\d+)\.(\d+)\.(\d+)$/); - if (exact) return !isBefore(value, firstAffected) && isBefore(value, firstFixed); - const majorOnly = value.match(/^(\d+)(\.latest)?$/); - return !!majorOnly && Number(majorOnly[1]) === versionParts(firstAffected)[0]; -}; +// True for an accessibility build on Cypress 16. Keyed on the major, not the requested version: +// Rails runs the newest 16 it offers for any 16.x it doesn't list (e.g. 16.2.1, 16.3.0, "16.2"), +// and that is 16.2.0 today, which has the extension service-worker bug (fixed in 16.2.1). +// The version that actually runs is only known server-side, so this should move there +// (terminalDeploy, next to the Cypress 16 network-logs/Local forceHttp1 rule) and be removed here. +const needsForceHttp1ForAccessibility = (cypressVersion) => + cypressMajor(String(cypressVersion).trim()) === Constants.ACCESSIBILITY_FORCE_HTTP1_CYPRESS_MAJOR; // Adds forceHttp1=true to the run's Cypress config unless the user already set forceHttp1 // (either way), keeping every other key they passed. @@ -176,13 +162,13 @@ const caps = (bsConfig, zip) => { // send run_settings as is for other capabilities let runSettings = bsConfig.run_settings; - // Rails defaults to its newest Cypress, which accessibility does not support yet, so an - // accessibility build without a version asks for the newest major accessibility supports. + // An accessibility build without a version asks for DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY, + // which keeps unpinned builds off the Cypress 16 forceHttp1 path (see constants.js). if (isAccessibilityOn(bsConfig) && Utils.isUndefined(runSettings.cypress_version)) { runSettings = Object.assign({}, runSettings, { cypress_version: String(Constants.DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY) }); logger.info(Constants.userMessages.ACCESSIBILITY_CYPRESS_VERSION_PINNED); } - // Accessibility scans on the affected Cypress 16 versions only complete with forceHttp1. + // Accessibility scans on the Cypress 16 that Rails runs today (16.2.0) only complete with forceHttp1. if (isAccessibilityOn(bsConfig) && !Utils.isUndefined(runSettings.cypress_version) && needsForceHttp1ForAccessibility(runSettings.cypress_version)) { const config = withForceHttp1(runSettings.config); diff --git a/bin/helpers/constants.js b/bin/helpers/constants.js index bc4362e1..0882c07b 100644 --- a/bin/helpers/constants.js +++ b/bin/helpers/constants.js @@ -89,7 +89,7 @@ const userMessages = { ACCESSIBILITY_CYPRESS_VERSION_PINNED: "Accessibility builds without a cypress_version run on the latest Cypress 15.", ACCESSIBILITY_FORCE_HTTP1_SET: - "Accessibility on Cypress 16.1.0-16.2.0 needs Cypress's HTTP/1.1 proxy, so this build runs with forceHttp1=true.", + "Accessibility on Cypress 16 runs on Cypress 16.2.0, which needs Cypress's HTTP/1.1 proxy, so this build runs with forceHttp1=true.", CYPRESS_VERSION_CHANGED: "Your build will run using Cypress instead of Cypress . Read more about supported versions here: http://browserstack.com/docs/automate/cypress/supported-versions", LOCAL_START_FAILED: "Local Testing setup failed.", @@ -451,14 +451,16 @@ const SPEC_TIMEOUT_LIMIT = 120; // IN MINS // Newest Cypress major accessibility runs on (APS-22894). Raising this needs no Rails change. const MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY = 16; -// Major an accessibility build asks for when it names no cypress_version. Stays on 15 while -// Rails' own default does, so an unpinned build keeps today's Cypress. +// Major an accessibility build asks for when it names no cypress_version. This CLI's choice, not +// Rails': for a CLI that sends cypressExposeSupport, Rails defaults to its newest Cypress (16). +// Kept on 15 so unpinned accessibility builds stay off the Cypress 16 forceHttp1 path. const DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY = 15; -// Cypress versions where the a11y extension's service worker never starts, so every scan times -// out unless forceHttp1 is on: [first affected, first fixed). Regression from cypress-io/cypress#34762 -// (16.1.0), reported as cypress-io/cypress#35127, fixed by #34958 in 16.2.1. +// Cypress major whose accessibility builds get forceHttp1. On 16.1.0-16.2.0 the a11y extension's +// service worker never starts, so every scan times out unless forceHttp1 is on. Regression from +// cypress-io/cypress#34762 (16.1.0), reported as cypress-io/cypress#35127, fixed by #34958 in 16.2.1. +// Whole major, because Rails runs 16.2.0 for every 16.x request while it is the only 16 it offers. // SDK-8048 preprod A/B on 16.2.0: scan step 25.6s without forceHttp1, 4.2s with it. -const ACCESSIBILITY_FORCE_HTTP1_CYPRESS_RANGE = ['16.1.0', '16.2.1']; +const ACCESSIBILITY_FORCE_HTTP1_CYPRESS_MAJOR = 16; const CYPRESS_CUSTOM_ERRORS_TO_PRINT_KEY = "custom_errors_to_print"; @@ -527,7 +529,7 @@ module.exports = Object.freeze({ SPEC_TIMEOUT_LIMIT, MAX_CYPRESS_MAJOR_FOR_ACCESSIBILITY, DEFAULT_CYPRESS_MAJOR_FOR_ACCESSIBILITY, - ACCESSIBILITY_FORCE_HTTP1_CYPRESS_RANGE, + ACCESSIBILITY_FORCE_HTTP1_CYPRESS_MAJOR, CYPRESS_CUSTOM_ERRORS_TO_PRINT_KEY, CYPRESS_V9_AND_OLDER_TYPE, CYPRESS_V10_AND_ABOVE_TYPE, diff --git a/test/unit/bin/accessibility-automation/plugin/index.js b/test/unit/bin/accessibility-automation/plugin/index.js index ff774b5c..4a6d6d3e 100644 --- a/test/unit/bin/accessibility-automation/plugin/index.js +++ b/test/unit/bin/accessibility-automation/plugin/index.js @@ -19,11 +19,16 @@ describe('accessibility plugin exposes browser values', () => { BROWSERSTACK_ACCESSIBILITY_DEBUG: 'true', }; + // The plugin itself sets these, so they are restored too. + const SET_BY_PLUGIN = ['BROWSERSTACK_LOGS', 'BROWSERSTACK_ACCESSIBILITY_PLUGIN_LOADED']; + const RESTORED = Object.keys(ENV).concat(SET_BY_PLUGIN); + beforeEach(() => { - Object.keys(ENV).forEach((k) => { saved[k] = process.env[k]; process.env[k] = ENV[k]; }); + RESTORED.forEach((k) => { saved[k] = process.env[k]; }); + Object.keys(ENV).forEach((k) => { process.env[k] = ENV[k]; }); }); afterEach(() => { - Object.keys(ENV).forEach((k) => { if (saved[k] === undefined) delete process.env[k]; else process.env[k] = saved[k]; }); + RESTORED.forEach((k) => { if (saved[k] === undefined) delete process.env[k]; else process.env[k] = saved[k]; }); }); const run = (config) => { diff --git a/test/unit/bin/helpers/capabilityHelper.js b/test/unit/bin/helpers/capabilityHelper.js index 5eb3cb22..54ac40a1 100644 --- a/test/unit/bin/helpers/capabilityHelper.js +++ b/test/unit/bin/helpers/capabilityHelper.js @@ -141,7 +141,8 @@ describe("capabilityHelper.js", () => { }); }); - ["16", "16.latest", "16.1.0", "16.1.1", "16.2.0"].forEach((version) => { + // Rails runs 16.2.0 for any 16.x it doesn't list, so every Cypress 16 request needs it. + ["16", "16.latest", "16.latest-1", "16.2", "16.0.0", "16.1.0", "16.1.1", "16.2.0", "16.2.1", "16.3.0"].forEach((version) => { it(`adds forceHttp1=true for accessibility on cypress_version ${version}`, () => { return sentRunSettings({ accessibility: true, cypress_version: version }).then(({ sent, bsConfig }) => { chai.assert.equal(sent.config, "forceHttp1=true"); @@ -169,9 +170,7 @@ describe("capabilityHelper.js", () => { ["accessibility on, no version (pinned to 15)", { accessibility: true }], ["accessibility off, Cypress 16", { accessibility: false, cypress_version: "16.2.0" }], ["accessibility on, cypress_version latest", { accessibility: true, cypress_version: "latest" }], - ["accessibility on, Cypress 16.2.1 (fixed)", { accessibility: true, cypress_version: "16.2.1" }], - ["accessibility on, Cypress 16.3.0 (fixed)", { accessibility: true, cypress_version: "16.3.0" }], - ["accessibility on, Cypress 16.0.0 (before the regression)", { accessibility: true, cypress_version: "16.0.0" }], + ["accessibility on, Cypress 17", { accessibility: true, cypress_version: "17.0.0" }], ].forEach(([name, runSettings]) => { it(`does not add forceHttp1 for ${name}`, () => { return sentRunSettings(runSettings).then(({ sent }) => {