Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getDiffImageAsJPEG error for jpg outputFormat #1456

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file added capture/resources/notFound.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added capture/resources/notVisible.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added capture/resources/unexpectedError.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added capture/resources/unexpectedErrorSm.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions core/command/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ module.exports = {
return new Promise(function (resolve, reject) {
const port = getRemotePort();
const commandStr = `node ${ssws} ${projectPath} ${MIDDLEWARE_PATH} --config=${config.backstopConfigFileName}`;
const env = {'SSWS_HTTP_PORT': port};
const env = { SSWS_HTTP_PORT: port };

logger.log(`Starting remote with: ${commandStr} with env ${JSON.stringify(env)}`);

const child = exec(commandStr, {env: env});
const child = exec(commandStr, { env });

child.stdout.on('data', logger.log);

Expand Down
23 changes: 22 additions & 1 deletion core/util/engineTools.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
function getUnexpectedErrorImagePath (filePath) {
return filePath.endsWith('.png')
? '/capture/resources/unexpectedErrorSm.png'
: '/capture/resources/unexpectedErrorSm.jpg';
}

function getNotVisibleImagePath (filePath) {
return filePath.endsWith('.png')
? '/capture/resources/notVisible.png'
: '/capture/resources/notVisible.jpg';
}

function getNotFoundImagePath (filePath) {
return filePath.endsWith('.png')
? '/capture/resources/notFound.png'
: '/capture/resources/notFound.jpg';
}

function getMisMatchThreshHold (scenario, config) {
if (typeof scenario.misMatchThreshold !== 'undefined') { return scenario.misMatchThreshold; }
if (typeof config.misMatchThreshold !== 'undefined') { return config.misMatchThreshold; }
Expand Down Expand Up @@ -159,5 +177,8 @@ module.exports = {
getFilename,
getEngineOption,
getSelectorName,
getScenarioExpect
getScenarioExpect,
getNotVisibleImagePath,
getNotFoundImagePath,
getUnexpectedErrorImagePath
};
13 changes: 5 additions & 8 deletions core/util/runPlaywright.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ const TEST_TIMEOUT = 60000;
const DEFAULT_FILENAME_TEMPLATE = '{configId}_{scenarioLabel}_{selectorIndex}_{selectorLabel}_{viewportIndex}_{viewportLabel}';
const DEFAULT_BITMAPS_TEST_DIR = 'bitmaps_test';
const DEFAULT_BITMAPS_REFERENCE_DIR = 'bitmaps_reference';
const SELECTOR_NOT_FOUND_PATH = '/capture/resources/notFound.png';
const HIDDEN_SELECTOR_PATH = '/capture/resources/notVisible.png';
const ERROR_SELECTOR_PATH = '/capture/resources/unexpectedErrorSm.png';
const BODY_SELECTOR = 'body';
const DOCUMENT_SELECTOR = 'document';
const NOCLIP_SELECTOR = 'body:noclip';
Expand Down Expand Up @@ -281,7 +278,7 @@ async function processScenarioView (scenario, variantOrScenarioLabelSafe, scenar
compareConfig = {
testPairs: [testPair]
};
await fs.copy(config.env.backstop + ERROR_SELECTOR_PATH, filePath);
await fs.copy(config.env.backstop + engineTools.getUnexpectedErrorImagePath(filePath), filePath);
}

return Promise.resolve(compareConfig);
Expand Down Expand Up @@ -378,7 +375,7 @@ async function captureScreenshot (page, browserContext, selector, selectorMap, c
});
} catch (e) {
console.log(chalk.red('Error capturing..'), e);
return fs.copy(config.env.backstop + ERROR_SELECTOR_PATH, filePath);
return fs.copy(config.env.backstop + engineTools.getUnexpectedErrorImagePath(filePath), filePath);
}
} else {
// OTHER-SELECTOR screenshot
Expand All @@ -404,11 +401,11 @@ async function captureScreenshot (page, browserContext, selector, selectorMap, c
await type.screenshot(params);
} else {
console.log(chalk.yellow(`Element not visible for capturing: ${s}`));
return fs.copy(config.env.backstop + HIDDEN_SELECTOR_PATH, path);
return fs.copy(config.env.backstop + engineTools.getNotVisibleImagePath(path), path);
}
} else {
console.log(chalk.magenta(`Element not found for capturing: ${s}`));
return fs.copy(config.env.backstop + SELECTOR_NOT_FOUND_PATH, path);
return fs.copy(config.env.backstop + engineTools.getNotFoundImagePath(path), path);
}
};

Expand All @@ -421,7 +418,7 @@ async function captureScreenshot (page, browserContext, selector, selectorMap, c
await selectorShot(selector, filePath);
} catch (e) {
console.log(chalk.red(`Error capturing Element ${selector}`), e);
return fs.copy(config.env.backstop + ERROR_SELECTOR_PATH, filePath);
return fs.copy(config.env.backstop + engineTools.getUnexpectedErrorImagePath(filePath), filePath);
}
}
};
Expand Down
13 changes: 5 additions & 8 deletions core/util/runPuppet.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ const TEST_TIMEOUT = 60000;
const DEFAULT_FILENAME_TEMPLATE = '{configId}_{scenarioLabel}_{selectorIndex}_{selectorLabel}_{viewportIndex}_{viewportLabel}';
const DEFAULT_BITMAPS_TEST_DIR = 'bitmaps_test';
const DEFAULT_BITMAPS_REFERENCE_DIR = 'bitmaps_reference';
const SELECTOR_NOT_FOUND_PATH = '/capture/resources/notFound.png';
const HIDDEN_SELECTOR_PATH = '/capture/resources/notVisible.png';
const ERROR_SELECTOR_PATH = '/capture/resources/unexpectedErrorSm.png';
const BODY_SELECTOR = 'body';
const DOCUMENT_SELECTOR = 'document';
const NOCLIP_SELECTOR = 'body:noclip';
Expand Down Expand Up @@ -288,7 +285,7 @@ async function processScenarioView (scenario, variantOrScenarioLabelSafe, scenar
testPairs: [testPair]
};
await writeScenarioLogs(config, logFilePath, logger);
await fs.copy(config.env.backstop + ERROR_SELECTOR_PATH, filePath);
await fs.copy(config.env.backstop + engineTools.getUnexpectedErrorImagePath(filePath), filePath);
}

return Promise.resolve(compareConfig);
Expand Down Expand Up @@ -391,7 +388,7 @@ async function captureScreenshot (page, browser, selector, selectorMap, config,
} catch (e) {
logger.log('red', 'Error capturing..', e);
await writeScenarioLogs(config, logFilePath, logger);
return fs.copy(config.env.backstop + ERROR_SELECTOR_PATH, filePath);
return fs.copy(config.env.backstop + engineTools.getUnexpectedErrorImagePath(filePath), filePath);
}
} else {
// OTHER-SELECTOR screenshot
Expand Down Expand Up @@ -425,12 +422,12 @@ async function captureScreenshot (page, browser, selector, selectorMap, config,
} else {
logger.log('yellow', `Element not visible for capturing: ${s}`);
await writeScenarioLogs(config, logFilePath, logger);
return fs.copy(config.env.backstop + HIDDEN_SELECTOR_PATH, path);
return fs.copy(config.env.backstop + engineTools.getNotVisibleImagePath(path), path);
}
} else {
logger.log('magenta', `Element not found for capturing: ${s}`);
await writeScenarioLogs(config, logFilePath, logger);
return fs.copy(config.env.backstop + SELECTOR_NOT_FOUND_PATH, path);
return fs.copy(config.env.backstop + engineTools.getNotFoundImagePath(path), path);
}
};

Expand All @@ -445,7 +442,7 @@ async function captureScreenshot (page, browser, selector, selectorMap, config,
} catch (e) {
logger.log('red', `Error capturing Element ${selector}`, e);
await writeScenarioLogs(config, logFilePath, logger);
return fs.copy(config.env.backstop + ERROR_SELECTOR_PATH, filePath);
return fs.copy(config.env.backstop + engineTools.getUnexpectedErrorImagePath(filePath), filePath);
}
}
};
Expand Down