Skip to content

Commit

Permalink
Notify user about recorded user interaction (#67)
Browse files Browse the repository at this point in the history
* added notify feature

Signed-off-by: aryangupta701 <[email protected]>
  • Loading branch information
aryangupta701 authored Sep 8, 2023
1 parent 3ca9737 commit fc17a63
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/ContentScript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ Browser.runtime.onMessage.addListener(
(message: MessageEvent, _sender: Runtime.MessageSender) => {
if (message.type === ZAP_START_RECORDING) {
configureExtension();
recorder.initializationScript();
recorder.recordUserInteractions();
recorder.initializationScript();
} else if (message.type === ZAP_STOP_RECORDING) {
recorder.stopRecordingUserInteractions();
}
Expand Down
66 changes: 66 additions & 0 deletions source/ContentScript/recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ class Recorder {

floatingWindowInserted = false;

isNotificationRaised = false;

async sendZestScriptToZAP(zestStatement: ZestStatement): Promise<number> {
this.notify(zestStatement);
return Browser.runtime.sendMessage({
type: ZEST_SCRIPT,
data: zestStatement.toJSON(),
Expand Down Expand Up @@ -351,6 +354,69 @@ class Recorder {
isDragging = false;
});
}

async notify(stmt: ZestStatement): Promise<void> {
const notifyMessage = {
title: '',
message: '',
};

if (stmt instanceof ZestStatementElementClick) {
notifyMessage.title = 'Click';
notifyMessage.message = stmt.elementLocator.element;
} else if (stmt instanceof ZestStatementElementSendKeys) {
notifyMessage.title = 'Send Keys';
notifyMessage.message = `${stmt.elementLocator.element}: ${stmt.keys}`;
} else if (stmt instanceof ZestStatementLaunchBrowser) {
notifyMessage.title = 'Launch Browser';
notifyMessage.message = stmt.browserType;
} else if (stmt instanceof ZestStatementSwitchToFrame) {
notifyMessage.title = 'Switch To Frame';
notifyMessage.message = stmt.frameIndex.toString();
}

// wait for previous notification to be removed
if (this.isNotificationRaised) {
await this.waitForNotificationToClear();
}
const floatingDiv = document.getElementById('ZapfloatingDiv');
if (!floatingDiv) {
console.log('Floating Div Not Found !');
return;
}

this.isNotificationRaised = true;
const messageElement = document.createElement('p');
messageElement.className = 'ZapfloatingDivElements';
messageElement.textContent = `${notifyMessage.title}: ${notifyMessage.message}`;
messageElement.style.all = 'initial';
messageElement.style.fontSize = '20px';
messageElement.style.zIndex = '999999';
messageElement.style.fontFamily = 'Roboto';

const existingChildElements = Array.from(floatingDiv.children || []);

floatingDiv.innerHTML = '';

floatingDiv.appendChild(messageElement);

setTimeout(() => {
floatingDiv.removeChild(messageElement);
existingChildElements.forEach((child) => floatingDiv.appendChild(child));
this.isNotificationRaised = false;
}, 1000);
}

waitForNotificationToClear(): Promise<number> {
return new Promise((resolve) => {
const checkInterval = setInterval(() => {
if (!this.isNotificationRaised) {
clearInterval(checkInterval);
resolve(1);
}
}, 100);
});
}
}

export default Recorder;

0 comments on commit fc17a63

Please sign in to comment.