Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

recorder-to-wpt-script

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

recorder-to-wpt-script - npm Package Compare versions

Comparing version 1.1.0 to 1.6.1

sample-recordings/simple-recording-new-format.json

107

index.js

@@ -35,10 +35,6 @@ let jsonPath, flow;

//first, is it a valid step?
function isValid(stepType) {
if (stepMap[stepType]) {
return true;
} else {
return false;
}
function addViewport(step) {
wptScript += `setViewportSize ${step.width} ${step.height}\n`;
}
function addNavigate(url) {

@@ -48,43 +44,34 @@ wptScript += "setEventName Navigate\n";

}
function addClick(selectors) {
wptScript += "setEventName Click\n";
//for now, let's skip any aria/ until we figure somethign out there
for (let index = 0; index < selectors.length; index++) {
const selector = selectors[index];
if (!selector[0].startsWith("aria/")) {
wptScript +=
'execAndWait document.querySelector("' + selector + '").click();\n';
break;
selectors.forEach((selector) => {
if (!selector[0].startsWith("aria/") && !selector[0].startsWith("xpath/") && !selector[0].startsWith("text/")) {
wptScript += 'execAndWait document.querySelector("' + selector + '").click();\n';
}
}
});
}
function addChange(selectors, value) {
if (isKeyDown) {
wptScript += "setEventName KeyDown\n";
for (let index = 0; index < selectors.length; index++) {
const selector = selectors[index];
if (!selector[0].startsWith("aria/")) {
wptScript +=
'execAndWait document.querySelector("' + selector + '").click();\n';
break;
selectors.forEach((selector) => {
if (!selector[0].startsWith("aria/") && !selector[0].startsWith("xpath/") && !selector[0].startsWith("text/")) {
wptScript += 'execAndWait document.querySelector("' + selector + '").click();\n';
}
}
});
} else {
wptScript += "setEventName Change\n";
//for now, let's skip any aria/ until we figure somethign out there
for (let index = 0; index < selectors.length; index++) {
const selector = selectors[index];
if (!selector[0].startsWith("aria/")) {
wptScript +=
'execAndWait document.querySelector("' +
selector +
'").value = "' +
value +
'";\n';
break;
selectors.forEach((selector) => {
if (!selector[0].startsWith("aria/") && !selector[0].startsWith("xpath/") && !selector[0].startsWith("text/")) {
//wptScript += 'execAndWait document.querySelector("' + selector + '").value = "' + value + '";\n';
// This will also handle React's Synthetic Event Listeners
wptScript += `execAndWait el = document.querySelector('${selector}'); proto = Object.getPrototypeOf(el); set = Object.getOwnPropertyDescriptor(proto, 'value').set; set.call(el, '${value}'); el.dispatchEvent(new Event('input', { bubbles: true }))\n`;
}
}
});
}
}
function addKeyDown(assertedEvents) {

@@ -102,7 +89,39 @@ //Because some keydown events are returning url's as assertedEvents

}
function addKeyUp() {
isKeyDown = false;
}
function addWaitForElement(selectors) {
selectors.forEach((selector) => {
wptScript += "setEventName WaitForElement\n";
wptScript += `waitFor document.querySelector("${selector}")\n`;
});
}
function addWaitFor(step) {
wptScript += "setEventName WaitForExpression\n";
wptScript += "waitFor " + step.expression + "\n";
}
function doubleClick(selectors) {
wptScript += "setEventName doubleClick\n";
//for now, let's skip any aria/ until we figure somethign out there
selectors.forEach((selector) => {
if (!selector[0].startsWith("aria/") && !selector[0].startsWith("xpath/") && !selector[0].startsWith("text/")) {
wptScript += `execAndWait document.querySelector('${selector}').dispatchEvent(new MouseEvent('dblclick'))\n`;
}
});
}
function scroll(step) {
wptScript += "setEventName Scroll\n";
wptScript += `execAndWait window.scrollBy(${step.x},${step.y})\n`;
}
function addScriptLine(step) {
switch (step.type) {
case "setViewport":
addViewport(step);
break;
case "navigate":

@@ -123,8 +142,24 @@ addNavigate(step.url);

break;
case "waitForElement":
addWaitForElement(step.selectors);
break;
case "waitForExpression":
addWaitFor(step);
break;
case "doubleClick":
doubleClick(step.selectors);
break;
case "scroll":
scroll(step);
break;
}
}
flow.steps.forEach((step) => {
addScriptLine(step);
});
if (flow.steps) {
flow.steps.forEach((step) => {
addScriptLine(step);
});
} else {
addScriptLine(flow);
}

@@ -131,0 +166,0 @@ return wptScript;

{
"name": "recorder-to-wpt-script",
"version": "1.1.0",
"version": "1.6.1",
"description": "Script to convert Chrome user flow recordings to WPT Custom Scripts",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -63,2 +63,6 @@ <p align="center"><img src="https://docs.webpagetest.org/img/wpt-navy-logo.png" alt="WebPageTest Logo" /></p>

- `keyup` (maps to `execAndWait`)
- `waitForElement` (maps to `waitFor`)
- `waitForExpression` (maps to `waitFor`)
- `doubleClick` (maps to `execAndWait`)
- `scroll` (maps to `execAndWait`)

@@ -65,0 +69,0 @@ ## Resources

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc