Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
71e28b7
TRA changes
Bhargavi-BS Nov 9, 2025
94fbd89
changes for testMap implementation
Bhargavi-BS Nov 11, 2025
c9e6862
added EOF lines
Bhargavi-BS Nov 11, 2025
8ab63b8
TRA changes
Bhargavi-BS Nov 14, 2025
506dd0b
TRA changes pt.3
Bhargavi-BS Nov 17, 2025
c876a42
fix: lint error
Bhargavi-BS Nov 17, 2025
c107fa1
accessibility changes
Bhargavi-BS Nov 17, 2025
9ada09f
fix: lint error
Bhargavi-BS Nov 17, 2025
ff58a6a
minor change
Bhargavi-BS Nov 18, 2025
7344585
minor change
Bhargavi-BS Nov 19, 2025
3a3910a
fix:lint errors
Bhargavi-BS Nov 19, 2025
04a4ab0
added null checks
Bhargavi-BS Nov 19, 2025
04f5edb
review changes pt.1
Bhargavi-BS Nov 19, 2025
dc47ae8
minor change
Bhargavi-BS Nov 19, 2025
1d9431f
fix: static testMap added
Bhargavi-BS Nov 20, 2025
2f0befb
minor change
Bhargavi-BS Nov 20, 2025
b31cdc9
minor change in try-catch
Bhargavi-BS Nov 20, 2025
bc916ed
temp: fallback for old core version
Bhargavi-BS Nov 20, 2025
4893c7a
eslintrc change
Bhargavi-BS Nov 20, 2025
1f5138f
fix for double test events in cucumber runner
Bhargavi-BS Nov 20, 2025
e932fab
env var name changed
Bhargavi-BS Nov 20, 2025
6e0a90a
minor changes
Bhargavi-BS Nov 24, 2025
724033d
removed the fallback and added alternative
Bhargavi-BS Nov 24, 2025
a25e71e
review changes pt.2
Bhargavi-BS Nov 25, 2025
e4aac46
Update src/utils/testMap.js
Bhargavi-BS Nov 26, 2025
bb86129
review changes pt.3
Bhargavi-BS Nov 26, 2025
8539ae8
review changes pt.4
Bhargavi-BS Nov 26, 2025
75a5ec9
minor change
Bhargavi-BS Nov 26, 2025
9ca5ff5
fix: lint issues
Bhargavi-BS Nov 27, 2025
73d96ba
fixed the UTs
Bhargavi-BS Nov 27, 2025
b42efb4
minor change
Bhargavi-BS Nov 27, 2025
5627070
review changes pt.5
Bhargavi-BS Nov 27, 2025
5220e0a
fixed lint issues
Bhargavi-BS Nov 27, 2025
adda0be
minor log change
Bhargavi-BS Nov 28, 2025
990102c
minor change
Bhargavi-BS Nov 28, 2025
7d99495
fix for wrong product map
Bhargavi-BS Dec 1, 2025
e3d9c59
minor change
Bhargavi-BS Dec 1, 2025
c68ae0b
fix for handling a edge case
Bhargavi-BS Dec 5, 2025
a7f66fd
fix for the timeout issue
Bhargavi-BS Dec 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"Promise": true,
"Proxy": true,
"Set": true,
"Map": true,
"Reflect": true,
"element": "readonly",
"by": "readonly",
Expand Down
107 changes: 67 additions & 40 deletions nightwatch/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const path = require('path');
const AccessibilityAutomation = require('../src/accessibilityAutomation');
const eventHelper = require('../src/utils/eventHelper');
const OrchestrationUtils = require('../src/testorchestration/orchestrationUtils');
const TestMap = require('../src/utils/testMap');
const localTunnel = new LocalTunnel();
const testObservability = new TestObservability();
const accessibilityAutomation = new AccessibilityAutomation();
Expand All @@ -19,6 +20,8 @@ const _tests = {};
const _testCasesData = {};
let currentTestUUID = '';
let workerList = {};
let testRunner = '';
let testEventPromises = [];

eventHelper.eventEmitter.on(EVENTS.LOG_INIT, (loggingData) => {
const testCaseStartedId = loggingData.message.replace('TEST-OBSERVABILITY-PID-TESTCASE-MAPPING-', '').slice(1, -1);
Expand Down Expand Up @@ -65,8 +68,8 @@ module.exports = {
promises.push(testObservability.processTestReportFile(JSON.parse(JSON.stringify(modulesWithEnv[testSetting][testFile]))));
}
}

await Promise.all(promises);

done();
} catch (error) {
CrashReporter.uploadCrashReport(error.message, error.stack);
Expand All @@ -92,7 +95,7 @@ module.exports = {
const gherkinDocument = reportData?.gherkinDocument.find((document) => document.uri === pickleData.uri);
const featureData = gherkinDocument.feature;
const uniqueId = uuidv4();
process.env.TEST_OPS_TEST_UUID = uniqueId;
process.env.TEST_RUN_UUID = uniqueId;

Object.values(workerList).forEach((worker) => {
worker.process.on('message', async (data) => {
Expand Down Expand Up @@ -253,15 +256,37 @@ module.exports = {

eventBroadcaster.on('ScreenshotCreated', async (args) => {
if (!helper.isTestObservabilitySession()) {return}
handleScreenshotUpload({args: args, uuid: process.env.TEST_OPS_TEST_UUID});
handleScreenshotUpload({args: args, uuid: process.env.TEST_RUN_UUID});
});

eventBroadcaster.on('TestRunStarted', async (test) => {
process.env.VALID_ALLY_PLATFORM = accessibilityAutomation.validateA11yCaps(browser);
await accessibilityAutomation.beforeEachExecution(test);
if (testRunner !== 'cucumber'){
const uuid = TestMap.storeTestDetails(test);
process.env.TEST_RUN_UUID = uuid;
testEventPromises.push(testObservability.sendTestRunEvent('TestRunStarted', test, uuid));
}
});

eventBroadcaster.on('TestRunFinished', async (test) => {
await accessibilityAutomation.afterEachExecution(test);
const uuid = process.env.TEST_RUN_UUID || TestMap.getUUID(test);
if (TestMap.hasTestFinished(uuid)) {
Logger.debug(`Test with UUID ${uuid} already marked as finished, skipping duplicate TestRunFinished event`);

return;
}
try {
await accessibilityAutomation.afterEachExecution(test, uuid);
if (testRunner !== 'cucumber'){
testEventPromises.push(testObservability.sendTestRunEvent('TestRunFinished', test, uuid));
TestMap.markTestFinished(uuid);
}

} catch (error) {
Logger.error(`Error in TestRunFinished event: ${error.message}`);
TestMap.markTestFinished(uuid);
}
});
},

Expand All @@ -272,10 +297,12 @@ module.exports = {
},

async before(settings, testEnvSettings) {
testRunner = settings.test_runner.type;
const pluginSettings = settings['@nightwatch/browserstack'];
if (!settings.desiredCapabilities['bstack:options']) {
settings.desiredCapabilities['bstack:options'] = {};
}

process.env.BROWSERSTACK_APP_AUTOMATE = helper.checkTestEnvironmentForAppAutomate(testEnvSettings);
// Plugin identifier
settings.desiredCapabilities['bstack:options']['browserstackSDK'] = `nightwatch-plugin/${helper.getAgentVersion()}`;

Expand All @@ -295,6 +322,7 @@ module.exports = {

try {
testObservability.configure(settings);
accessibilityAutomation.configure(settings);
if (helper.isTestObservabilitySession()) {
if (settings.reporter_options) {
if (settings.reporter_options['save_command_result_value'] !== true){
Expand All @@ -312,7 +340,7 @@ module.exports = {
settings.test_runner.options['require'] = path.resolve(__dirname, 'observabilityLogPatcherHook.js');
}
settings.globals['customReporterCallbackTimeout'] = CUSTOM_REPORTER_CALLBACK_TIMEOUT;
if (testObservability._user && testObservability._key) {
if (helper.isTestHubBuild(pluginSettings, true)) {
await testObservability.launchTestSession();
}
if (process.env.BROWSERSTACK_RERUN === 'true' && process.env.BROWSERSTACK_RERUN_TESTS && process.env.BROWSERSTACK_RERUN_TESTS!=='null') {
Expand All @@ -323,7 +351,17 @@ module.exports = {
} catch (error) {
Logger.error(`Could not configure or launch test reporting and analytics - ${error}`);
}


try {
// In parallel mode, env-specific settings are passed to beforeChildProcess hook instead of before hook,
if (helper.isAccessibilitySession() && !settings.parallel_mode) {
accessibilityAutomation.setAccessibilityCapabilities(settings);
accessibilityAutomation.commandWrapper();
helper.patchBrowserTerminateCommand();
}
} catch (err){
Logger.debug(`Exception while setting Accessibility Automation capabilities. Error ${err}`);
}
// Initialize and configure test orchestration
try {
if (helper.isTestObservabilitySession()) {
Expand Down Expand Up @@ -408,22 +446,6 @@ module.exports = {
Logger.error(`Could not configure test orchestration - ${error}`);
}

try {
accessibilityAutomation.configure(settings);
if (helper.isAccessibilitySession()) {
if (accessibilityAutomation._user && accessibilityAutomation._key) {
const [jwtToken, testRunId] = await accessibilityAutomation.createAccessibilityTestRun();
process.env.BS_A11Y_JWT = jwtToken;
process.env.BS_A11Y_TEST_RUN_ID = testRunId;
if (helper.isAccessibilitySession()) {
accessibilityAutomation.setAccessibilityCapabilities(settings);
}
}
}
} catch (error) {
Logger.error(`Could not configure or launch accessibility automation - ${error}`);
}

addProductMapAndbuildUuidCapability(settings);
},

Expand All @@ -443,46 +465,40 @@ module.exports = {
} catch (error) {
Logger.error(`Error collecting build data for test orchestration: ${error}`);
}
if (helper.isTestObservabilitySession()) {

if (helper.isTestHubBuild()) {
process.env.NIGHTWATCH_RERUN_FAILED = nightwatchRerun;
process.env.NIGHTWATCH_RERUN_REPORT_FILE = nightwatchRerunFile;
if (process.env.BROWSERSTACK_RERUN === 'true' && process.env.BROWSERSTACK_RERUN_TESTS) {
await helper.deleteRerunFile();
}
try {
if (testEventPromises.length > 0) {
await Promise.all(testEventPromises);
testEventPromises.length = 0; // Clear the array
}
await testObservability.stopBuildUpstream();
if (process.env.BS_TESTOPS_BUILD_HASHED_ID) {
Logger.info(`\nVisit https://automation.browserstack.com/builds/${process.env.BS_TESTOPS_BUILD_HASHED_ID} to view build report, insights, and many more debugging information all at one place!\n`);
if (process.env.BROWSERSTACK_TESTHUB_UUID) {
Logger.info(`\nVisit https://automation.browserstack.com/builds/${process.env.BROWSERSTACK_TESTHUB_UUID} to view build report, insights, and many more debugging information all at one place!\n`);
}
} catch (error) {
Logger.error(`Something went wrong in stopping build session for test reporting and analytics - ${error}`);
}
process.exit();
}
if (helper.isAccessibilitySession()){
try {
await accessibilityAutomation.stopAccessibilityTestRun();
} catch (error) {
Logger.error(`Exception in stop accessibility test run: ${error}`);
}

}
},

async beforeEach(settings) {
browser.getAccessibilityResults = () => { return accessibilityAutomation.getAccessibilityResults() };
browser.getAccessibilityResultsSummary = () => { return accessibilityAutomation.getAccessibilityResultsSummary() };
// await accessibilityAutomation.beforeEachExecution(browser);
},

// This will be run after each test suite is finished
async afterEach(settings) {
// await accessibilityAutomation.afterEachExecution(browser);
},

beforeChildProcess(settings) {

if (!settings.desiredCapabilities['bstack:options']) {
settings.desiredCapabilities['bstack:options'] = {};
}
Expand Down Expand Up @@ -514,12 +530,23 @@ module.exports = {
try {
if (helper.isAccessibilitySession()) {
accessibilityAutomation.setAccessibilityCapabilities(settings);
accessibilityAutomation.commandWrapper();
helper.patchBrowserTerminateCommand();
}
} catch (err){
Logger.debug(`Exception while setting Accessibility Automation capabilities. Error ${err}`);
}
addProductMapAndbuildUuidCapability(settings);

},

async afterChildProcess() {

await helper.shutDownRequestHandler();
if (testEventPromises.length > 0) {
await Promise.all(testEventPromises);
testEventPromises.length = 0; // Clear the array
}
}
};

Expand Down Expand Up @@ -569,10 +596,10 @@ const addProductMapAndbuildUuidCapability = (settings) => {

if (settings.desiredCapabilities['bstack:options']) {
settings.desiredCapabilities['bstack:options']['buildProductMap'] = buildProductMap;
settings.desiredCapabilities['bstack:options']['testhubBuildUuid'] = process.env.BS_TESTOPS_BUILD_HASHED_ID ? process.env.BS_TESTOPS_BUILD_HASHED_ID : '' ;
settings.desiredCapabilities['bstack:options']['testhubBuildUuid'] = process.env.BROWSERSTACK_TESTHUB_UUID ? process.env.BROWSERSTACK_TESTHUB_UUID : '' ;
} else {
settings.desiredCapabilities['browserstack.buildProductMap'] = buildProductMap;
settings.desiredCapabilities['browserstack.testhubBuildUuid'] = process.env.BS_TESTOPS_BUILD_HASHED_ID ? process.env.BS_TESTOPS_BUILD_HASHED_ID : '' ;
settings.desiredCapabilities['browserstack.testhubBuildUuid'] = process.env.BROWSERSTACK_TESTHUB_UUID ? process.env.BROWSERSTACK_TESTHUB_UUID : '' ;
}
} catch (error) {
Logger.debug(`Error while sending productmap and build capabilities ${error}`);
Expand Down
Loading