Fix bug when slide number >= 10
This commit is contained in:
parent
87b0111915
commit
51a0f26d97
26
index.js
26
index.js
|
@ -235,7 +235,14 @@ async function main() {
|
||||||
|
|
||||||
for (let pageIndex = 1;; pageIndex++) {
|
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) {
|
if (root === null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -264,16 +271,19 @@ async function main() {
|
||||||
await page.screenshot({path: (outputDir === null ? __dirname : outputDir) + '/' + 'screenshot2.png'});
|
await page.screenshot({path: (outputDir === null ? __dirname : outputDir) + '/' + 'screenshot2.png'});
|
||||||
|
|
||||||
// Compare both screenshots
|
// Compare both screenshots
|
||||||
let file1 = await fs.readFile(__dirname + '/' + 'screenshot1.png');
|
let file1 = await fs.readFile((outputDir === null ? __dirname : outputDir) + '/' + 'screenshot1.png');
|
||||||
let file2 = await fs.readFile(__dirname + '/' + 'screenshot2.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);
|
let filesAreSame = file1.map((x, i) => x === file2[i]).reduce((a, b) => a && b, true);
|
||||||
|
|
||||||
if (!filesAreSame) {
|
if (!filesAreSame) {
|
||||||
// Check psnr
|
// 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
|
// Crash if they're different
|
||||||
if (psnr > 70) {
|
if (psnr > 0) {
|
||||||
warning(filename + " produced slight diff: psnr = " + psnr);
|
warning(filename + " produced slight diff: psnr = " + psnr);
|
||||||
} else {
|
} else {
|
||||||
await error("page edit changed the layout: psnr = " + psnr);
|
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.class = className;
|
||||||
|
|
||||||
analyse.box = box;
|
analyse.box = box;
|
||||||
|
if (box !== null) {
|
||||||
box.x /= size.width;
|
box.x /= size.width;
|
||||||
box.width /= size.width;
|
box.width /= size.width;
|
||||||
box.y /= size.height;
|
box.y /= size.height;
|
||||||
box.height /= size.height;
|
box.height /= size.height;
|
||||||
|
}
|
||||||
|
|
||||||
if (outputDir !== null) {
|
if (outputDir !== null) {
|
||||||
analyse.uuid = uuid();
|
analyse.uuid = uuid();
|
||||||
|
@ -412,6 +424,8 @@ async function analyseElement(element, page, outputDir = null, threshold = undef
|
||||||
analyse.text = textContent;
|
analyse.text = textContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tagName !== "svg") {
|
||||||
|
|
||||||
// Select the children of this HTML element.
|
// Select the children of this HTML element.
|
||||||
let children = await element.$$('> *');
|
let children = await element.$$('> *');
|
||||||
|
|
||||||
|
@ -420,6 +434,8 @@ async function analyseElement(element, page, outputDir = null, threshold = undef
|
||||||
analyse.children.push(await analyseElement(child, page, outputDir, threshold));
|
analyse.children.push(await analyseElement(child, page, outputDir, threshold));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return analyse;
|
return analyse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue