Muppeteer exposes the assert
module of Chai onto the Muppeteer
object. This means
you can use all the standard Chai assertions, such as equal, notEqual, isBelow, etc. See
Assert for the full API.
In addition, Muppeteer adds a visual
function is patched onto the module.
assert.visual(selector)
selector
<string> Selector of the element to compare
Compares the baseline visual of the element to a newly taken screenshot
You can access all the native Puppeteer page functions on the puppeteerPage
object. However, Muppeteer adds
convenience functions onto page
object, which is recommended for the majority of use cases.
down(key)
key
<string> The key to fire the down event on
Fire down event on a particular keyboard key (see: down)
up(key)
key
<string> The key to fire the up event on
Fire up event on a particular keyboard key (see: up)
press(key)
key
<string> The key to fire the press event on
Fire press event on a particular keyboard key (see: press)
type(text, options)
text
<string> The text to typeoptions
<object> Keyboard options
Type some text into an input field (see: type)
type(selector, text)
selector
<string> The selector of the element to type intotext
<string> The text to enter into the field
Type into a field on the page (see: type)
sendCharacter(char)
char
<char> The key to fire the up event on
Send a particular character to an input field (see: sendCharacter)
focus(selector)
selector
<string> The selector of the element to focus
Focus an element on the page (see: focus)
hover(selector)
selector
<string> The selector of the element to hover
Hover an element on the page (see: hover)
isElementFocused(selector)
selector
<string> The selector of the element to check for focus state- returns <boolean> Whether the element is focused or not
Check if element is focused
click(selector)
selector
<string> The selector of the element to click
Click on an element on the page (see: click)
waitForResource(resource, timeout=defaultTimeout)
resource
<string> The URL of the resource (or a substring of it)timeout
<number> Timeout for the check
Wait for a resource request to be responded to
waitForLoadedWebFontCountToBe(count, timeout=defaultTimeout)
count
<number> The number of web fonts to expecttimeout
<number> Timeout for the check
Wait for a specific number of web fonts to be loaded and ready on the page
waitForFunction(fn, options, ...args)
fn
<function> The function to execute on the pageoptions
<object> Optional waiting parametersargs
<...args> Arguments to be passed into the function
Wait for function to execute on the page (see waitForFunction)
waitForSelector(selector, timeout=defaultTimeout)
selector
<string> The selector for the element on the pagetimeout
<number> Timeout for the check
Wait for element with a given selector to exist on the page (see waitForSelector)
waitUntilExistsAndVisible(selector)
selector
<string> The selector for the element on the page
Wait until an element exists on the page and is visible (i.e. not transparent) (see waitForSelector)
waitWhileExistsAndVisible(selector)
selector
<string> The selector for the element on the page
Wait while an element still exists on the page and is visible (i.e. not transparent) (see waitForSelector)
waitUntilSelectorHasVisibleContent(selector)
selector
<string> The selector for the element on the page
Wait until the selector has visible content (i.e. the element takes up some width and height on the page) (i.e. not transparent)
waitWhileSelectorHasVisibleContent(selector)
selector
<string> The selector for the element on the page
Wait while the selector has visible content (i.e. the element takes up some width and height on the page) (i.e. not transparent)
waitForNthSelectorAttribute(selector, nth, attributeName)
selector
<string> The selector for the element on the pagenth
<number> The nth element found by the selectorattributeName
<string> The attribute name to look for
Wait for the nth element found from the selector has a particular attribute
waitForSelectorAttribute(selector, attributeName)
selector
<string> The selector for the element on the pageattributeName
<string> The attribute name to look for
Wait for the element found from the selector has a particular attribute
waitForNthSelectorAttributeValue(selector, nth, attributeName, attributeValue)
selector
<string> The selector for the element on the pagenth
<number> The nth element found by the selectorattributeName
<string> The attribute name to look forattributeValue
<string> The attribute value to match the attributeName
Wait for the nth element found from the selector has a particular attribute value pair
waitForSelectorAttributeValue(selector, attributeName, attributeValue)
selector
<string> The selector for the element on the pageattributeName
<string> The attribute name to look forattributeValue
<string> The attribute value to match the attributeName
Wait for the element found from the selector has a particular attribute value pair
waitForElementCount(selector, expectedCount)
selector
<string> The selector for the element on the pageexpectedCount
<number> The number of elements to expect
Wait for the element count to be a particular value
waitForUrl(regex)
regex
<RegExp> The regular expression to match the URL on
Wait for the current window location to match a particular regular expression
waitFor(milliseconds)
milliseconds
<number> The number of milliseconds to wait for
Wait for a given number of milliseconds
getValue(selector)
selector
<string> The selector for the element to get the value for- returns <string> The value property value for the element
Get the value property value for a particular element
getText(selector)
selector
<string> The selector for the element to get the text for- returns <string> The text property value for the element
Get the text property value for a particular element
getPropertyValue(selector, property)
selector
<string> The selector for the element to get the property value forproperty
<string> The property to look for- returns <string> The property value for the element
Get the value of a particular property for a particular element
screenshot(selector)
selector
<string> The selector for the element to take a screenshot of
Take a screenshot of a particular element on the page (see: screenshot)
turnOffAnimations()
Turn off CSS animations on the page to help avoid flaky visual comparisons
evaluate(fn, ...args)
fn
<function> The function to execute on the pageargs
<...args> Arguments to be passed into the function
Runs a function on the page
setViewport(viewport)
viewport
<object> The viewport config object
Set the view port of the page (see: setViewport)
addStyleTag(selector)
options
<object> The config options
Add style tag to the page (see: addStyleTag)