Skip to content

Instantly share code, notes, and snippets.

@Xotabu4
Created February 7, 2020 11:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Xotabu4/1c3237662e0b20a34a7e23cba0a1dfd6 to your computer and use it in GitHub Desktop.
Save Xotabu4/1c3237662e0b20a34a7e23cba0a1dfd6 to your computer and use it in GitHub Desktop.
/**
* @experimental
* This function tries to highligh exact point at webpage where click was failed,
* by placing special red square into failed coordinate.
* So allure screenshots will show exact failing location
* @param error exception object
*/
async function drawClickPointAttempt(error: Error) {
try {
const text = error.message;
const regex = /Element.*is not clickable at point \((.*), (.*)\)/gm;
const res = regex.exec(text);
if (!res) {
return;
}
console.log(`[drawClickPoint] ${regex} matched ${text}`);
const x = Number(res[1]);
const y = Number(res[2]);
console.log(`[drawClickPoint] Coordinates extracted from error x: ${x} y: ${y}`);
// noinspection CssInvalidPropertyValue
const drawScript = `document.body.insertAdjacentHTML('beforeend', ` +
`'<webdriver-unclickable-point style="position: absolute;` +
`background: #ff00003b;width: 30px;height: 30px;` +
`left: ${x}px;top: ${y}px;z-index: 99999999;` +
`transform:translateX(-50%) translateY(-50%);">` +
`</webdriver-unclickable-point>');`;
await browser.executeScript(drawScript);
} catch (err) {
console.log('[drawClickPoint] Cannot draw click point for screenshot: ', JSON.stringify(err));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment