@fnando/playwright-video
v0.0.7
Published
Run Playwright scripts and generate videos
Readme
playwright-video
Run Playwright scripts and generate videos.
Installation
npm install -g @fnando/playwright-videoUsage
playwright-video export path/to/your/script.mjs \
--output-path path/to/output/video.mp4 \
--state-path path/to/state.json \
--color-scheme darkYour script must export a run(options) function. Here's an example:
/**
* @param {import("@fnando/playwright-video").Utils} options Utilities
*/
export async function run({ visit, sleep, clickLink }) {
await visit("https://nandovieira.com");
await sleep(1000);
await clickLink({ text: "Using PostgreSQL and jsonb with Ruby on Rails" });
await sleep(5000);
}Utility Functions
The options object passed to the run function includes several utility
functions:
sleep(duration)
Sleep for a specified duration.
duration(number): Duration in milliseconds
waitUntilSatisfied(callback, timeout = 2000)
Wait until a condition is satisfied or timeout occurs.
callback(Function): A function that must return a truthy/falsy valuetimeout(Number): Timeout in milliseconds (default: 2000ms)
setCursor(type)
Set the cursor type.
type(string): The cursor type ('default' or 'hand')
moveMouseTo(x, y, { speed = 10 })
Move mouse to specified coordinates with speed control.
x(number): The x-coordinate to move toy(number): The y-coordinate to move tospeed(number): Speed of mouse movement (pixels per step)
scrollToElement({ selector, text, locator, duration = 500 })
Scroll to an element with animation.
selector(string): The selector of the element to scroll totext(string): The text of the element to scroll tolocator(Locator): The locator of the element to scroll toduration(number): Duration of the scroll animation in milliseconds
moveMouseToElement({ selector, text, locator, speed = 10 })
Move mouse to an element specified by selector, text or locator.
selector(string): The selector of the element to move totext(string): The text of the element to move tolocator(Locator): The locator of the element to move tospeed(number): The speed of mouse movement (pixels per step)
clickLink({ selector, text, locator, delay, mouseSpeed = 10, scrollDuration = 500 })
Click a link specified by selector or text, scrolling to it if necessary.
selector(string): The selector of the element to clicktext(string): The text of the element to clicklocator(Locator): The locator of the element to clickdelay(number): The delay before clickingmouseSpeed(number): The speed of mouse movementscrollDuration(number): The duration of the scroll animation
fillIn({ selector, text, delay = 100 })
Fill in text into an input field specified by selector.
selector(string): The selector of the input fieldtext(string): The text to fill indelay(number): The speed of typing (delay between keystrokes)
visit(url, options)
Visit a URL with optional navigation options.
url(string): The URL to visitoptions(Object): The same options as inpage.goto(url, options)
exists(selector)
Check if an element exists on the page.
selector(string): The selector of the element to check
Returns: Promise<boolean>
Notes
- This package patches Playwright to enable .mp4 support,
- This package patches Playwright to enable
FFMPEG_BINandCHROME_BINenvironment variables.
Maintainer
- Nando Vieira - https://nandovieira.com
Contributors
- https://github.com/fnando/browser/contributors
License
(The MIT License)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
