Skip to main content

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])

  • elementSelector <string> Element selector to locate the element
  • options <Object>
    • timeout Timeout in milliseconds, defaults to 30s
  • returns: <Promise<Element>>

.url()

Returns the current page URL.

  • url <string> URL to navigate to
  • options <Object>
    • timeout Timeout 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 context
  • arg <any> Argument to pass to the pageFunction. To pass multiple arguments, use an array.
  • options <Object>
    • timeout Timeout 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 context
  • options <Object>
    • timeout Timeout 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 expose
  • callback <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 completed
  • options <Object>
    • timeout Timeout 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])

  • options <Object>
    • timeout Timeout in milliseconds, defaults to 30s
  • returns: <Promise<void>>

Perform click on the element and wait for navigation to finish.

.hover([options])

  • options <Object>
    • timeout Timeout in milliseconds, defaults to 30s
  • returns: <Promise<void>>

Perform hover on the element and wait for navigation to finish.

.screenshot([options])

  • options <Object>
    • name Name of the screenshot, defaults to random 32-length
    • timeout Timeout in milliseconds, defaults to 30s

.evaluate(jsFunction[, arg])

  • jsFunction <function> Function to be evaluated in browser context
  • arg <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 instance
  • expect(var).not.toBe(value) - Negative assertion
  • expect(var).toMatchObject() - For matching object
  • expect([]).toContain(”item”) :- Assertion for array to check if it contains an item
Was this doc helpful?
yes
could be better
by