Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
b6d6e761eThis file is pinned to the selected release. Download the original to open it in your design tool.
// ***********************************************
// cypress/support/commands.js
// Custom commands for Gsender
//2.Load UI
//3.Connect to CNC machine grbl
//4.Auto unlock
// 5.Connect to CNC - GrblHAL
// 6.Disconnect if Idle
// 7.Upload G-code file
//8.Go to location grbl
//9.Go to location grblHal
//10.Unlock Machine if Needed
//11.Verify Specific Console Line Contains Text
//12.Zero X Axis
//13.Zero Y Axis
//14.Zero Z Axis
//15.Zero All Axes
//16.Force input into a field
//17.Send Console Command
//18.Clear Console Command
//19.Verify axes for expected values (flexible with decimals)
//20.Homing enabling and perform homing
//21.Axis Homing Z< Y & X
//22.Go to URLS
//23. Checking probing pin is active
//24.Jogging every axes
//25.Stop Job and get details
//26. Verify machine status
//27. Search items in settings
// ***********************************************
//=======//
//2.Load UI// cy.loadUI(`${Cypress.config('baseUrl')}/#/configuration`, {
//=======//
Cypress.Commands.add('loadUI', (options = {}) => {
const {
viewport = [1920, 1080],
visitTimeout = 30000,
elementTimeout = 15000,
expectedTitle = 'gSender 1.6.0',
} = options;
cy.viewport(...viewport);
cy.visit('/', { timeout: visitTimeout });
cy.title({ timeout: elementTimeout }).should('eq', expectedTitle);
cy.get('body', { timeout: elementTimeout }).should('be.visible');
});
// ----------------------
//3.Connect to CNC machine grbl cy.connectMachine();
// ----------------------
Cypress.Commands.add('connectMachine', () => {
// Step 1: Click "Connect to CNC" button
cy.contains('span', 'Connect to CNC', { timeout: 10000 })
.should('be.visible')
.click({ force: true });
// Step 2: Wait for the radix popper div to appear
cy.get('div[data-radix-popper-content-wrapper]', { timeout: 10000 })
.should('exist')
.and('be.visible')
.within(() => {
// Step 3: Get the first port button inside the popper
cy.get('button.m-0')
.should('have.length.greaterThan', 0)
.first()
.then(($btn) => {
// Step 4: Read and log the port label — no assertion on name
const $label = $btn.find('span.font-bold');
const portName =
$label.length > 0
? $label.text().trim()
: $btn.text().trim();
cy.log(`Selecting first available port: "${portName}"`);
// Step 5: Click whatever port is listed first
cy.wrap($btn).click({ force: true });
});
});
// Step 6: Confirm machine reaches Idle state after connecting
cy.contains(/^Idle$/i, { timeout: 30000 })
.should('be.visible')
.then(() => cy.log('CNC machine connected and in Idle state'));
});
//-----------------------
//21.Axis Homing Z< Y & X
//-----------------------
Cypress.Commands.add('enableAxisHomingAndHome', () => {
cy.log('Starting axis homing configuration and execution...');
// Step 1: Navigate to Config page
cy.log('Navigating to Config page...');
cy.get('a:nth-of-type(4) span').click();
cy.wait(1000);
// Step 2: Navigate to Homing section
cy.log('Opening Homing settings...');
cy.get('button:nth-of-type(6) > span:nth-of-type(2)').click();
cy.wait(500);
// Step 3: Check and enable all required homing settings if disabled
cy.log('Checking axis homing conditions...');
const settingsToCheck = [
{ id: '$22-0-key', name: 'Enable Homing' },
{ id: '$22-1-key', name: 'Enable single axis commands' },
{ id: '$22-2-key', name: 'Homing on startup required' },
{ id: '$22-3-key', name: 'Set Machine origin to 0' },
{ id: '$22-5-key', name: 'Allow Manual' },
{ id: '$22-6-key', name: 'Override locks' },
];
let changesDetected = false;
settingsToCheck.forEach((setting) => {
cy.get(`button#\\${setting.id}`).then(($toggle) => {
if ($toggle.attr('aria-checked') === 'false') {
cy.log(`Enabling: ${setting.name}`);
cy.wrap($toggle).click();
cy.wait(300);
changesDetected = true;
} else {
cy.log(`${setting.name} already enabled - ignoring`);
}
});
});
// Step 4: Apply Settings only if changes were made
cy.log('Checking if settings need to be applied...');
cy.contains('button', 'Apply Settings').then(($button) => {
if ($button.is(':disabled')) {
cy.log('No changes detected - ignoring Apply Settings');
} else {
cy.log('Applying settings...');
cy.wrap($button).click();
cy.wait(2000);
cy.unlockMachineIfNeeded();
cy.wait(1000);
}
});
// Step 5: Navigate back to main page
cy.log('Returning to main view...');
cy.get('#app > div > div.h-full > div.flex img').click();
cy.wait(1000);
cy.unlockMachineIfNeeded();
cy.wait(1000);
// Step 6: Enable Homing Toggle
cy.log('Enabling homing toggle button...');
cy.get(
'div.flex-shrink-0 > div > div > div > div > div.relative div.flex > button',
).click();
cy.wait(1000);
// Step 7: Verify axes changed to homing mode
cy.log('Verifying homing mode activated...');
cy.get(
'div.flex-shrink-0 > div > div > div > div > div.relative > div.flex-col > div:nth-of-type(1) > div:nth-of-type(1) span',
).should('contain.text', 'HX');
cy.get(
'div.h-\\[75\\%\\] div.flex-col > div:nth-of-type(2) > div:nth-of-type(1) span',
).should('contain.text', 'HY');
cy.get(
'div.flex-shrink-0 > div > div > div > div > div.relative div:nth-of-type(3) > div:nth-of-type(1) span',
).should('contain.text', 'HZ');
// Step 8: Execute Z-axis homing
cy.log('Homing Z-axis...');
cy.get(
'div.flex-shrink-0 > div > div > div > div > div.relative div:nth-of-type(3) > div:nth-of-type(1) span',
)
.contains('HZ')
.click();
cy.wait(2000);
cy.contains(/^idle$/i, { timeout: 30000 }).should('be.visible');
cy.log('Z-axis homing completed');
cy.wait(1000);
// Step 9: Execute Y-axis homing
cy.log('Homing Y-axis...');
cy.get(
'div.h-\\[75\\%\\] div.flex-col > div:nth-of-type(2) > div:nth-of-type(1) span',
)
.contains('HY')
.click();
cy.wait(2000);
cy.contains(/^idle$/i, { timeout: 30000 }).should('be.visible');
cy.log('Y-axis homing completed');
cy.wait(1000);
// Step 10: Execute X-axis homing
cy.log('Homing X-axis...');
cy.get(
'div.flex-shrink-0 > div > div > div > div > div.relative > div.flex-col > div:nth-of-type(1) > div:nth-of-type(1) span',
)
.contains('HX')
.click();
cy.wait(2000);
cy.contains(/^idle$/i, { timeout: 30000 }).should('be.visible');
cy.log('X-axis homing completed');
cy.wait(1000);
cy.log('Axis homing sequence completed successfully!');
});
// ----------------------
// 17. Check Homing, Enable if Needed, and Perform Homing
// ----------------------
Cypress.Commands.add('ensureHomingEnabledAndHome', (options = {}) => {
const {
verifyHomingStatus = true,
verifyFinalPosition = true,
timeout = 60000,
} = options;
cy.log('Checking homing configuration...');
// Navigate to Config page
cy.get('a:nth-of-type(4) svg').click();
cy.wait(1000);
cy.log('Config page opened');
// Navigate to Homing section
cy.contains('button', /homing/i).click();
cy.wait(500);
cy.log('Homing settings section opened');
// Check if Enable Homing ($22-0-key) is enabled
cy.get('button#\\$22-0-key').then(($toggle) => {
const isEnabled = $toggle.attr('aria-checked') === 'true';
if (isEnabled) {
cy.log('Homing is already enabled');
} else {
cy.log('Homing is disabled - enabling now...');
// Enable all required homing settings
const settingsToEnable = [
{ id: '$22-0-key', name: 'Enable Homing' },
{ id: '$22-2-key', name: 'Homing on startup required' },
{ id: '$22-3-key', name: 'Set Machine origin to 0' },
{ id: '$22-5-key', name: 'Allow Manual' },
{ id: '$22-6-key', name: 'Override locks' },
];
settingsToEnable.forEach((setting) => {
cy.get(`button#\\${setting.id}`).then(($btn) => {
if ($btn.attr('aria-checked') === 'false') {
cy.log(` Enabling: ${setting.name}`);
cy.wrap($btn).click();
cy.wait(300);
}
});
});
// Apply Settings
cy.log('Applying homing settings...');
cy.contains('button', 'Apply Settings').then(($button) => {
if (!$button.is(':disabled')) {
cy.wrap($button).click();
cy.wait(2000);
cy.unlockMachineIfNeeded();
cy.wait(1000);
cy.log('Settings applied successfully');
}
});
}
// Navigate back to Carve page
cy.log('Returning to Carve page...');
cy.get('a:nth-of-type(1) img').click();
cy.wait(1000);
cy.unlockMachineIfNeeded();
cy.wait(1000);
cy.log('Returned to Carve page');
// Wait for machine to be ready
cy.log('Waiting for machine ready state...');
cy.contains(/^Idle$/i, { timeout: 30000 }).should('be.visible');
cy.wait(1000);
cy.log('Machine is ready');
// Perform homing sequence
cy.log('Performing homing sequence...');
// Open homing menu
cy.get('div.flex-shrink-0 > div > div > div > div').click();
cy.wait(500);
// Click Home button
cy.contains('button', 'Home').click();
cy.wait(1000);
cy.log('Homing command sent');
if (verifyHomingStatus) {
// Verify homing in progress
cy.log('Verifying homing process...');
cy.contains('span', 'Homing', { timeout: 10000 }).should(
'be.visible',
);
cy.log('Homing status displayed');
}
// Wait for homing to complete
cy.log('Waiting for homing to complete...');
cy.contains(/^Idle$/i, { timeout: timeout }).should('be.visible');
cy.wait(2000);
// Handle unlock if needed
cy.unlockMachineIfNeeded();
cy.wait(1000);
cy.log('Homing completed successfully');
});
});
//4.Auto unlock
// -----------------------
Cypress.Commands.add('autoUnlock', () => {
cy.get('body', { log: false, timeout: 1000 }).then(
{ timeout: 1000 },
($body) => {
const bodyText = $body.text().toLowerCase();
if (bodyText.includes('unlock')) {
cy.log('Unlock popup detected');
// Find and click unlock button
cy.get('button', { log: false }).then(($buttons) => {
let unlocked = false;
$buttons.each((index, btn) => {
const $btn = Cypress.$(btn);
if (
$btn.text().toLowerCase().includes('unlock') &&
$btn.is(':visible')
) {
$btn.click();
cy.log('Auto-unlocked');
unlocked = true;
return false; // break loop
}
});
if (!unlocked) {
cy.log('Unlock button not found or not visible');
}
});
} else {
cy.log('No unlock needed');
}
},
);
});
// ------------------------
// 5. Connect to CNC - GrblHAL (Cross-platform compatible)
// ----------------------
Cypress.Commands.add('connectToGrblHAL', () => {
cy.log('Starting connection check...');
cy.wait(2000);
cy.get('body').then(($body) => {
const bodyText = $body.text();
// Already Idle
if (/\bIdle\b/i.test(bodyText)) {
cy.log(' Machine is already connected and in Idle state');
return;
}
// Connected but not Idle yet
if (/\bDisconnect\b/i.test(bodyText)) {
cy.log(' Machine connected — waiting for Idle...');
cy.contains(/^Idle$/i, { timeout: 30000 }).should('be.visible');
return;
}
// Not connected — initiate connection
cy.log(' Machine not connected. Initiating connection...');
cy.contains(/^connect to CNC$/i, { timeout: 20000 })
.should('exist')
.scrollIntoView()
.should('be.visible')
.click({ force: true });
cy.wait(1000);
// Select first available port (works on Windows/Linux/macOS)
cy.get('div[data-radix-popper-content-wrapper]', { timeout: 10000 })
.should('exist')
.within(() => {
cy.get('button.m-0')
.should('have.length.greaterThan', 0)
.first()
.then(($btn) => {
const portName = ($btn.text() || '').trim();
cy.log(` Selecting port: "${portName}"`);
cy.wrap($btn).click({ force: true });
});
});
cy.unlockMachineIfNeeded();
cy.log('Waiting for Idle state...');
cy.contains(/^Idle$/i, { timeout: 30000 })
.should('be.visible')
.then(() => cy.log(' CNC machine connected and in Idle state'));
});
});
// ----------------------
// 6.Disconnect if Idle
// ----------------------
Cypress.Commands.add('disconnectIfIdle', () => {
cy.wait(5000);
cy.contains(/^Idle$/i, { timeout: 20000 }).then((status) => {
const machineStatus = status.text().trim();
cy.log(`Machine status: "${machineStatus}"`);
if (machineStatus.toLowerCase() === 'idle') {
cy.log('Machine is Idle — disconnecting...');
cy.get('div.group').first().trigger('mouseover', { force: true });
cy.get('div.group div.w-full')
.contains(/^disconnect$/i)
.click({ force: true });
cy.contains(/Connect to CNC/i, { timeout: 30000 })
.should('be.visible')
.then(() =>
cy.log('Machine disconnect verified successfully.'),
);
} else {
cy.log('Machine is not Idle — skipping disconnect.');
}
});
});
// ----------------------
//7.Upload G-code file
// ----------------------
Cypress.Commands.add('uploadGcodeFile', (fileName = 'sample.gcode') => {
cy.wait(5000);
cy.contains('Load File').should('be.visible').click({ force: true });
cy.get('#fileInput').selectFile(`cypress/fixtures/${fileName}`, {
force: true,
});
cy.wait(5000);
cy.log(`G-code file ${fileName} uploaded successfully`);
});
-(
// ----------------------
//9.Go to location grblHal
// ----------------------
Cypress.Commands.add('goToLocation', (options = {}) => {
const x = options.x ?? 0;
const y = options.y ?? 0;
const z = options.z ?? 0;
const waitTime = options.waitTime ?? 5000;
cy.log(`Going to location: X=${x}, Y=${y}, Z=${z}`);
// Step 1: Open Go To Location dialog
cy.log('Opening Go To Location popup...');
cy.get('div.min-h-10 > div:nth-of-type(1) > button', { timeout: 10000 })
.filter(':visible')
.first()
.click({ force: true });
cy.wait(1500);
cy.log('"Go to Location" button clicked');
// Step 2: Enter coordinates inside the Radix dialog
cy.get('[id^="radix-"]', { timeout: 10000 })
.should('exist')
.last()
.within(() => {
// X axis
cy.get('div:nth-of-type(2) input')
.filter(':visible')
.clear({ force: true })
.type(String(x), { force: true })
.trigger('change', { force: true });
cy.log(`X coordinate: ${x}`);
// Y axis
cy.get('div:nth-of-type(3) input')
.filter(':visible')
.clear({ force: true })
.type(String(y), { force: true })
.trigger('change', { force: true });
cy.log(`Y coordinate: ${y}`);
// Z axis — force value with multiple triggers
cy.get('div:nth-of-type(4) input')
.filter(':visible')
.focus()
.clear({ force: true })
.type('{selectall}', { force: true })
.type(String(z), { force: true })
.trigger('input', { force: true })
.trigger('change', { force: true })
.blur();
cy.log(`Z coordinate: ${z}`);
// Step 3: Click Go button
cy.log('Clicking Go button...');
cy.contains('button', 'Go!').click({ force: true });
cy.log('Go button clicked');
});
cy.wait(2000);
// Step 4: Close popup
cy.log('Closing popup...');
cy.get('body').click(50, 50, { force: true });
cy.wait(500);
// Step 5: Wait for machine to return to Idle
cy.log('Waiting for machine to reach position...');
cy.contains(/^Idle$/i, { timeout: waitTime }).should('be.visible');
cy.wait(2000);
cy.log(` Moved to X=${x}, Y=${y}, Z=${z}`);
})
);
// ----------------------
//10.Unlock Machine if Needed
// ----------------------
Cypress.Commands.add('unlockMachineIfNeeded', () => {
cy.get('body').then(($body) => {
if ($body.find('svg.hidden').length > 0) {
cy.log('Machine locked - unlocking...');
cy.get('svg.hidden').parent('button').click({ force: true });
cy.wait(1000);
cy.log('Machine unlocked');
} else {
cy.log('Machine already unlocked');
}
});
});
// ----------------------
//11.Verify Specific Console Line Contains Text
// ----------------------
Cypress.Commands.add('verifyConsoleContains', (text) => {
cy.log(`Checking if console contains: "${text}"`);
cy.get('div.xterm-rows')
.should('be.visible')
.invoke('text')
.should('include', text)
.then(() => {
cy.log(`Console contains: "${text}"`);
});
});
//-----------------------
// Zero X axis
//-----------------------
Cypress.Commands.add('zeroXAxis', () => {
cy.log('Zeroing X axis...');
cy.get(
'div.h-\\[75\\%\\] div.flex-col > div:nth-of-type(1) > div:nth-of-type(1) button',
)
.contains('X0')
.click();
cy.wait(500);
cy.log('X axis zeroed');
});
//-----------------------
// Zero Y axis
//-----------------------
Cypress.Commands.add('zeroYAxis', () => {
cy.log('Zeroing Y axis...');
cy.get(
'div.h-\\[75\\%\\] div.flex-col > div:nth-of-type(2) > div:nth-of-type(1) button',
)
.contains('Y0')
.click();
cy.wait(500);
cy.log('Y axis zeroed');
});
//-----------------------
// Zero Z axis
//-----------------------
Cypress.Commands.add('zeroZAxis', () => {
cy.log('Zeroing Z axis...');
cy.get(
'div.h-\\[75\\%\\] div.flex-col > div:nth-of-type(3) > div:nth-of-type(1) button',
)
.contains('Z0')
.click();
cy.wait(500);
cy.log('Z axis zeroed');
});
//-----------------------
// Zero A axis
Cypress.Commands.add('zeroAAxis', () => {
cy.log('Zeroing A axis');
cy.contains('button', 'A0').click();
cy.log('A axis zeroed');
});
// ----------------------
//15.Zero All Axes
// ----------------------
Cypress.Commands.add('zeroAllAxes', () => {
cy.log('Resetting all axes to zero...');
cy.zeroXAxis();
cy.zeroYAxis();
cy.zeroZAxis();
cy.log('All axes zeroed');
});
// ----------------------
//16.Force input into a field
// ----------------------
Cypress.Commands.add('forceInput', (selector, value) => {
cy.get(selector)
.clear({ force: true })
.type(value, { force: true })
.blur({ force: true })
.then(($el) => {
expect($el.val()).to.equal(value);
});
});
// ----------------------
//17.Send Console Command
// ----------------------
Cypress.Commands.add('sendConsoleCommand', (command) => {
cy.log(`Sending console command: ${command}`);
// Find the visible console input field
cy.get('div.block input')
.filter(':visible')
.first()
.clear({ force: true })
.type(command, { force: true });
// Click the Run button
cy.get('div.block button')
.contains(/Run/i)
.should('be.visible')
.click({ force: true });
cy.wait(1000);
cy.log(` Command sent: ${command}`);
});
// ----------------------
//18.Clear Console Command
// ----------------------
Cypress.Commands.add('clearConsole', () => {
cy.log('Clearing console...');
// Step 1: Click on Console tab to ensure it's active
cy.get('div.h-\\[25\\%\\] button:nth-of-type(4)')
.contains(/Console/i)
.click({ force: true });
cy.wait(500);
cy.log('Console tab activated');
// Step 2: Click the console options button (three dots icon)
cy.get('div.block > div.grid > div.flex svg')
.should('be.visible')
.click({ force: true });
cy.wait(500);
cy.log('Console options menu opened');
// Step 3: Click "Clear Console" from the dropdown
cy.get('body > div:nth-of-type(2) div > div:nth-of-type(2) span')
.contains(/Clear Console/i)
.should('be.visible')
.click({ force: true });
cy.wait(500);
cy.log('Console cleared successfully');
});
// ----------------------
//19.Verify axes for expected values (flexible with decimals)
// ----------------------
Cypress.Commands.add(
'verifyAxes',
(expectedX = 0, expectedY = 0, expectedZ = 0) => {
cy.log(
`Verifying axes positions: X=${expectedX}, Y=${expectedY}, Z=${expectedZ}...`,
);
// Convert expected values to strings with proper formatting
const formatValue = (val) => {
const num = parseFloat(val);
return num % 1 === 0 ? num.toFixed(0) : num.toString();
};
const expectedXStr = formatValue(expectedX);
const expectedYStr = formatValue(expectedY);
const expectedZStr = formatValue(expectedZ);
// Get the position input fields that display current coordinates
cy.get('input[type="number"].text-xl.font-bold.text-blue-500.font-mono')
.should('have.length', 3)
.then(($inputs) => {
const xValue = $inputs.eq(0).val();
const yValue = $inputs.eq(1).val();
const zValue = $inputs.eq(2).val();
cy.log(
`Current positions - X: ${xValue}, Y: ${yValue}, Z: ${zValue}`,
);
cy.log(
`Expected positions - X: ${expectedXStr}, Y: ${expectedYStr}, Z: ${expectedZStr}`,
);
// Verify X axis
expect(parseFloat(xValue)).to.be.closeTo(
parseFloat(expectedXStr),
0.01,
);
// Verify Y axis
expect(parseFloat(yValue)).to.be.closeTo(
parseFloat(expectedYStr),
0.01,
);
// Verify Z axis
expect(parseFloat(zValue)).to.be.closeTo(
parseFloat(expectedZStr),
0.01,
);
});
cy.log('Axes verified successfully');
},
);
//23. Checking probing pin is active
Cypress.Commands.add('checkProbingIsActive', (options = {}) => {
const { maxAttempts = 30, waitTime = 1000 } = options;
cy.log(' Checking if Probe/TLS is active (green)...');
const checkGreen = () => {
return cy.get('body').then(($body) => {
const $probeTLS = $body.find(
'div.text-gray-500:contains("Probe/TLS")',
);
if ($probeTLS.length === 0) {
return false;
}
const $parent = $probeTLS.closest('.relative');
return $parent.find('.bg-green-500').length > 0;
});
};
const clickZMinusUntilGreen = (attempt = 1) => {
if (attempt > maxAttempts) {
throw new Error(
` Probe/TLS did not turn green after ${maxAttempts} attempts`,
);
}
cy.log(` Attempt ${attempt}/${maxAttempts}: Clicking Z-`);
cy.get(
'path[d="M0.5 98.5H49.5V177C49.5 182.247 45.2467 186.5 40 186.5H10C4.75329 186.5 0.5 182.247 0.5 177V98.5Z"]',
)
.should('exist')
.click({ force: true });
cy.wait(waitTime);
checkGreen().then((isGreen) => {
if (isGreen) {
cy.log(' Probe/TLS is GREEN');
} else {
cy.log(' Probe/TLS not active yet, retrying...');
clickZMinusUntilGreen(attempt + 1);
}
});
};
// Start the process
clickZMinusUntilGreen();
// Final assertion (safety check)
cy.contains('div.text-gray-500', 'Probe/TLS')
.should('be.visible')
.closest('.relative')
.find('.bg-green-500')
.should('exist');
cy.log(' Probing is ACTIVE and verified');
});
// 24.Jogging every axes
// -------- X axis jogging --------
Cypress.Commands.add('jogXPlusTimes', (times = 1, waitTime = 2000) => {
cy.log(`Jogging X+ ${times} time(s)...`);
for (let i = 1; i <= times; i++) {
cy.get('path#xPlus').should('exist').click({ force: true });
cy.wait(waitTime);
cy.log(`X+ jog ${i}/${times} completed`);
}
});
Cypress.Commands.add('jogXMinusTimes', (times = 1, waitTime = 2000) => {
cy.log(`Jogging X- ${times} time(s)...`);
for (let i = 1; i <= times; i++) {
cy.get('path#xMinus').should('exist').click({ force: true });
cy.wait(waitTime);
cy.log(`X- jog ${i}/${times} completed`);
}
});
// -------- Y axis jogging --------
Cypress.Commands.add('jogYPlusTimes', (times = 1, waitTime = 2000) => {
cy.log(`Jogging Y+ ${times} time(s)...`);
for (let i = 1; i <= times; i++) {
cy.get('path#yPlus').should('exist').click({ force: true });
cy.wait(waitTime);
cy.log(`Y+ jog ${i}/${times} completed`);
}
});
Cypress.Commands.add('jogYMinusTimes', (times = 1, waitTime = 2000) => {
cy.log(`Jogging Y- ${times} time(s)...`);
for (let i = 1; i <= times; i++) {
cy.get('path#yMinus').should('exist').click({ force: true });
cy.wait(waitTime);
cy.log(`Y- jog ${i}/${times} completed`);
}
});
// -------- Z axis jogging --------
Cypress.Commands.add('jogZPlusTimes', (times = 1, waitTime = 2000) => {
cy.log(`Jogging Z+ ${times} time(s)...`);
for (let i = 1; i <= times; i++) {
cy.get(
'path[d="M0.5 10C0.5 4.75329 4.75329 0.5 10 0.5H40C45.2467 0.5 49.5 4.7533 49.5 10V88.5H0.5V10Z"]',
)
.should('exist')
.click({ force: true });
cy.wait(waitTime);
cy.log(`Z+ jog ${i}/${times} completed`);
}
});
Cypress.Commands.add('jogZMinusTimes', (times = 1, waitTime = 2000) => {
cy.log(`Jogging Z- ${times} time(s)...`);
for (let i = 1; i <= times; i++) {
cy.get(
'path[d="M0.5 98.5H49.5V177C49.5 182.247 45.2467 186.5 40 186.5H10C4.75329 186.5 0.5 182.247 0.5 177V98.5Z"]',
)
.should('exist')
.click({ force: true });
cy.wait(waitTime);
cy.log(`Z- jog ${i}/${times} completed`);
}
});
// -------- XY combined jogging --------
Cypress.Commands.add('jogXYPlusPlusTimes', (times = 1, waitTime = 2000) => {
cy.log(`Jogging X+Y+ ${times} time(s)...`);
for (let i = 1; i <= times; i++) {
cy.get('path#xPlusYPlus').should('exist').click({ force: true });
cy.wait(waitTime);
cy.log(`X+Y+ jog ${i}/${times} completed`);
}
});
Cypress.Commands.add('jogXYPlusMinusTimes', (times = 1, waitTime = 2000) => {
cy.log(`Jogging X+Y- ${times} time(s)...`);
for (let i = 1; i <= times; i++) {
cy.get('path#xPlusYMinus').should('exist').click({ force: true });
cy.wait(waitTime);
cy.log(`X+Y- jog ${i}/${times} completed`);
}
});
Cypress.Commands.add('jogXYMinusMinusTimes', (times = 1, waitTime = 2000) => {
cy.log(`Jogging X-Y- ${times} time(s)...`);
for (let i = 1; i <= times; i++) {
cy.get('path#xMinusYMinus').should('exist').click({ force: true });
cy.wait(waitTime);
cy.log(` X-Y- jog ${i}/${times} completed`);
}
});
Cypress.Commands.add('jogXYMinusPlusTimes', (times = 1, waitTime = 2000) => {
cy.log(`Jogging X-Y+ ${times} time(s)...`);
for (let i = 1; i <= times; i++) {
cy.get('path#xMinusYPlus').should('exist').click({ force: true });
cy.wait(waitTime);
cy.log(`X-Y+ jog ${i}/${times} completed`);
}
});
//25.Stop Job and get details
Cypress.Commands.add('stopJobAndGetDetails', () => {
cy.log('Stopping job and collecting job details');
// Step 1: Stop the job
cy.get('div.top-\\[-30px\\] > div:nth-of-type(3) > button', {
timeout: 10000,
})
.contains('Stop')
.should('be.visible')
.click({ force: true });
// Step 2: Wait for Job End popup
cy.contains('h2', 'Job End', { timeout: 20000 })
.should('be.visible')
.closest('div')
.as('jobPopup');
const jobDetails = {};
// Step 3: Extract Status
cy.get('@jobPopup')
.contains('strong', 'Status:')
.parent()
.invoke('text')
.then((text) => {
jobDetails.status = text.replace('Status:', '').trim();
});
// Step 4: Extract Time
cy.get('@jobPopup')
.contains('strong', 'Time:')
.parent()
.invoke('text')
.then((text) => {
jobDetails.time = text.replace('Time:', '').trim();
});
// Step 5: Extract Errors
cy.get('@jobPopup')
.contains('strong', 'Errors:')
.parent()
.invoke('text')
.then((text) => {
jobDetails.errors = text.replace('Errors:', '').trim();
});
// Step 6: Return all details as a single object
cy.then(() => {
cy.wrap(jobDetails).as('jobDetails');
});
});
//26. Verify machine status
Cypress.Commands.add('verifyMachineStatus', (expectedStatus, options = {}) => {
const { timeout = 30000, exact = true } = options;
cy.log(`Verifying machine status: ${expectedStatus}`);
const statusRegex = exact
? new RegExp(`^${expectedStatus}$`, 'i')
: new RegExp(expectedStatus, 'i');
cy.contains(statusRegex, { timeout })
.should('be.visible')
.then(($el) => {
const actualStatus = $el.text().trim();
cy.log(`Machine status: "${actualStatus}"`);
expect(actualStatus.toLowerCase()).to.eq(
expectedStatus.toLowerCase(),
);
});
});
//cy.verifyMachineStatus('Idle'); cy.verifyMachineStatus('Running'); cy.verifyMachineStatus('Disconnected'); cy.verifyMachineStatus('Hold');
Cypress.Commands.add('verifyMachineStatus', (expectedStatus, options = {}) => {
const { timeout = 30000 } = options;
const allowedStatuses = [
'Idle',
'Disconnected',
'Running',
'Jogging',
'Hold',
];
cy.log(`Verifying machine status: ${expectedStatus}`);
// Validate input
expect(
allowedStatuses,
`Allowed statuses are: ${allowedStatuses.join(', ')}`,
).to.include(expectedStatus);
const statusRegex = new RegExp(`^${expectedStatus}$`, 'i');
cy.contains(statusRegex, { timeout })
.should('be.visible')
.then(($status) => {
const actualStatus = $status.text().trim();
cy.log(`Machine status: "${actualStatus}"`);
expect(actualStatus.toLowerCase()).to.eq(
expectedStatus.toLowerCase(),
);
});
});
//------------------------------//
// Search Elements in Config page
//------------------------------//
Cypress.Commands.add('searchInSettings', (searchText, options = {}) => {
const { timeout = 10000 } = options;
cy.log(`Searching for: ${searchText}`);
cy.get('#simple-search', { timeout })
.should('be.visible')
.click({ force: true })
.invoke('val', '') // force-clear React controlled input
.type(searchText, { force: true, delay: 50 });
cy.wait(500);
});
// Apply settings { cy.applySettings(); }
Cypress.Commands.add('applySettings', (options = {}) => {
const { timeout = 10000, waitAfterApply = 3000 } = options;
cy.log('Applying settings (if changes exist)...');
cy.contains('button', 'Apply Settings', { timeout })
.should('exist')
.then(($button) => {
if ($button.is(':disabled')) {
cy.log('No settings changes detected');
return;
}
cy.log('Applying settings...');
cy.wrap($button).click();
cy.wait(waitAfterApply);
// Unlock machine if prompted
cy.unlockMachineIfNeeded();
cy.log('Settings applied successfully');
});
});
// Simple URL Navigation Commands
// ==============================
// URL Definitions
Cypress.Commands.add('loadUI', (options = {}) => {
const { timeout = 20000, viewport = { width: 1920, height: 1080 } } =
options;
let startTime;
cy.viewport(viewport.width, viewport.height);
cy.then(() => {
startTime = performance.now();
cy.log(`Load started at: ${new Date().toISOString()}`);
});
// Uses baseUrl from cypress.config.js — no hardcoded URL
cy.visit('/', {
failOnStatusCode: false,
timeout: 30000,
});
// Wait for real document readiness
cy.document().its('readyState').should('eq', 'complete');
// Cypress retries this block automatically until timeout
cy.get('body', { timeout }).should(($body) => {
const hasButton = $body.find('button').length > 0;
const hasConnection =
$body.text().includes('Connect') ||
$body.text().includes('Connection');
expect(hasButton, 'buttons should exist').to.be.true;
expect(hasConnection, 'connection text should exist').to.be.true;
});
// Log load time after UI confirmed ready
cy.then(() => {
const endTime = performance.now();
const loadTime = ((endTime - startTime) / 1000).toFixed(2);
const status =
loadTime < 5 ? 'FAST' : loadTime < 10 ? 'ACCEPTABLE' : 'SLOW';
cy.log(`[${status}] UI load time: ${loadTime}s`);
cy.task('log', `[${status}] UI Load Time: ${loadTime}s`);
});
cy.waitUntilIdle();
});
Cypress.Commands.add('waitUntilIdle', () => {
cy.get('body').then(($body) => {
if ($body.find('[data-cy="loading-spinner"]').length > 0) {
cy.get('[data-cy="loading-spinner"]', { timeout: 10000 }).should(
'not.exist',
);
}
// If spinner never existed, skip silently
});
});
// Page URLs
Cypress.Commands.add('goToCarve', () => {
cy.visit('http://localhost:8000/#/');
});
Cypress.Commands.add('goToStats', () => {
cy.visit('http://localhost:8000/#/stats');
});
Cypress.Commands.add('goToTools', () => {
cy.visit('http://localhost:8000/#/tools');
});
Cypress.Commands.add('goToConfig', () => {
cy.visit('http://localhost:8000/#/configuration');
});