Crusher SDK Reference
This page contains API reference for the crusher SDK, which can be used while writing custom code.
Page Actions
Can be accessed through crusherSdk.page
.querySelector(elementSelector[, options]).url().navigate(url[, options]).screenshot([options]).evaluate(pageFunction[, arg, options]).waitForFunction(jsFunction[, options]).exposeFunction(functionName, callback).waitForNavigation(url[, options])
.querySelector(elementSelector[, options])
elementSelector<string> Element selector to locate the elementoptions<Object>timeoutTimeout in milliseconds, defaults to 30s
- returns: <Promise<Element>>
.url()
Returns the current page URL.
.navigate(url[, options])
url<string> URL to navigate tooptions<Object>timeoutTimeout in milliseconds, defaults to 30s
- returns: <Promise<void>>
Navigates to the provided url.
.screenshot([options])
Take screenshot of the page, and returns the path to the captured screenshot.
.evaluate(pageFunction[, arg, options])
pageFunction<function> Function to be evaluated in browser contextarg<any> Argument to pass to the pageFunction. To pass multiple arguments, use an array.options<Object>timeoutTimeout in milliseconds, defaults to 30s
- returns: <Promise<any>>
Runs the provided function in browser context, and returns the result if it json-serializable.
.waitForFunction(jsFunction[, options])
jsFunction<function> Function to be evaluated in browser contextoptions<Object>timeoutTimeout in milliseconds, defaults to 30s
- returns: <Promise<void>>
Waits until the provided js function evaluates to true in browser context.
.exposeFunction(functionName, callback)
functionName<string> Name of the function to exposecallback<function> Function to be called when this function is called from inside the webpage- returns: <Promise<void>>
Exposes a function to the webpage. When called from the page context, the callback in node environment will be invoked with the provided arguments.
.waitForNavigation(url[, options])
url<string> URL to keep waiting for to consider navigation is completedoptions<Object>timeoutTimeout in milliseconds, defaults to 30s
- returns: <Promise<void>>
Waits for the page to navigate to the provided url.
Element Actions
Operation over DOM element instances, i.e after crusherSdk.page.querySelector(selector):
.click([options]).hover([options]).screenshot([options]).evaluate(jsFunction[, arg]).scrollIntoView()
.click([options])
Perform click on the element and wait for navigation to finish.
.hover([options])
Perform hover on the element and wait for navigation to finish.
.screenshot([options])
options<Object>nameName of the screenshot, defaults to random 32-lengthtimeoutTimeout in milliseconds, defaults to 30s
.evaluate(jsFunction[, arg])
jsFunction<function> Function to be evaluated in browser contextarg<any> Argument to pass to the pageFunction. To pass multiple arguments, use an array.- returns: <Promise<any>>
Runs the provided function in browser context, and returns the result if it json-serializable.
Note: The pageFunction will be called with the element as the first argument. So the callback would look something like this,
await inputElement.evaluate(function(element, arg) {
return element.value;
});
.scrollIntoView()
Scrolls the element into view if it's not already.
Assertions
The assertions will follow the jest standard API’s, i.e expect(var).toContain(””).
Checkout the jest documentation for more details.
expect(var).toBe(value)- Equal object instanceexpect(var).not.toBe(value)- Negative assertionexpect(var).toMatchObject()- For matching objectexpect([]).toContain(”item”):- Assertion for array to check if it contains an item