Fix bug when slide number >= 10

This commit is contained in:
Thomas Forgione 2023-03-13 14:00:38 +01:00
parent 87b0111915
commit 51a0f26d97
1 changed files with 30 additions and 14 deletions

View File

@ -235,7 +235,14 @@ async function main() {
for (let pageIndex = 1;; pageIndex++) {
let root = await page.$('#\\3' + pageIndex);
let pageIndexStr = "" + pageIndex;
let pageId = "";
for (let c of pageIndexStr) {
pageId += "\\3" + c;
}
let root = await page.$('#' + pageId);
if (root === null) {
break;
}
@ -264,16 +271,19 @@ async function main() {
await page.screenshot({path: (outputDir === null ? __dirname : outputDir) + '/' + 'screenshot2.png'});
// Compare both screenshots
let file1 = await fs.readFile(__dirname + '/' + 'screenshot1.png');
let file2 = await fs.readFile(__dirname + '/' + 'screenshot2.png');
let file1 = await fs.readFile((outputDir === null ? __dirname : outputDir) + '/' + 'screenshot1.png');
let file2 = await fs.readFile((outputDir === null ? __dirname : outputDir) + '/' + 'screenshot2.png');
let filesAreSame = file1.map((x, i) => x === file2[i]).reduce((a, b) => a && b, true);
if (!filesAreSame) {
// Check psnr
let psnr = await image.psnr(__dirname + '/' + 'screenshot1.png', __dirname + '/' + 'screenshot2.png');
let psnr = await image.psnr(
(outputDir === null ? __dirname : outputDir) + '/' + 'screenshot1.png',
(outputDir === null ? __dirname : outputDir) + '/' + 'screenshot2.png'
);
// Crash if they're different
if (psnr > 70) {
if (psnr > 0) {
warning(filename + " produced slight diff: psnr = " + psnr);
} else {
await error("page edit changed the layout: psnr = " + psnr);
@ -370,10 +380,12 @@ async function analyseElement(element, page, outputDir = null, threshold = undef
analyse.class = className;
analyse.box = box;
box.x /= size.width;
box.width /= size.width;
box.y /= size.height;
box.height /= size.height;
if (box !== null) {
box.x /= size.width;
box.width /= size.width;
box.y /= size.height;
box.height /= size.height;
}
if (outputDir !== null) {
analyse.uuid = uuid();
@ -412,12 +424,16 @@ async function analyseElement(element, page, outputDir = null, threshold = undef
analyse.text = textContent;
}
// Select the children of this HTML element.
let children = await element.$$('> *');
if (tagName !== "svg") {
// Select the children of this HTML element.
let children = await element.$$('> *');
for (let child of children) {
// Recursively analyse the children
analyse.children.push(await analyseElement(child, page, outputDir, threshold));
}
for (let child of children) {
// Recursively analyse the children
analyse.children.push(await analyseElement(child, page, outputDir, threshold));
}
return analyse;