Posted 28 February 2024, 7:45 pm EST
Hi Davide,
Please refer to the attached sample of Playwright Typescript testing of SpreadJS.
In the attached sample, “tests/SpreadJS_Tests.ts” contains the basic tests for SpreadJS e.g. changing the active cell, setting/getting the value of a cell from the sheet. The “wrappers” folder contains “Workbook.ts” and “Worksheet.ts” files that represent the Workbook and Worksheet element on a page. The tests are performed on SpreadJS Designer hosted at https://developer.mescius.com/spreadjs/designer/index.html.
You can run the command “npm run test” after unzipping the attached sample and installing all the dependencies. It is important to note that the sample only demonstrates simple test cases and, you would need to implement different functionalities to interact with SpreadJS controls/elements as per your use case/requirement.
Refer to the below test case snippet for changing the active cell in the sheet.
test('Change active cell', async ({ page }) => {
const workbook: Workbook = new Workbook(page);
const sheet: Worksheet = workbook.getActiveSheet();
const initialRow: number = await sheet.getActiveRowIndex(), initialCol: number = await sheet.getActiveColumnIndex();
// Click on cells
await sheet.clickCell(2, 2);
await sheet.clickCell(3, 3);
await sheet.clickCell(4, 4);
await sheet.clickCell(5, 5);
let row: number = await sheet.getActiveRowIndex(), col: number = await sheet.getActiveRowIndex();
const flag: boolean = (initialRow !== row && row === 5) || (initialCol !== col && col === 5) ? true : false;
expect(flag).toEqual(true);
});
sample: playwright_spreadjs_ts.zip
Regards,
Chandan