recorder-to-wpt-script
Advanced tools
Comparing version 1.1.0 to 1.6.1
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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
473752
15
1061
81