Back to Top

sulfide 0.3.0

Sulfide is a Selenide inspired library that can be used to simplify testing with Puppeteer.

new LengthCondition()

Condition to test if an element collection has a certain number of elements on the page.

Returns

Void

LengthCondition.getFailureMessage(element)

Returns the message that will be passed to Jasmine when the condition is not met.

Parameters

Name Type Description
element SulfideElement

The element for which the condition will be tested

Returns

String

The failure message for this condition

new Condition()

Base class for conditions.

Returns

Void

new CssClassCondition()

Condition to test if an element has the given CSS class.

Returns

Void

CssClassCondition.getFailureMessage(element)

Returns the message that will be passed to Jasmine when the condition is not met.

Parameters

Name Type Description
element SulfideElement

The element for which the condition will be tested

Returns

String

The failure message for this condition

new ExistCondition()

Condition to test if an element exists on the page.

Returns

Void

ExistCondition.getFailureMessage(element)

Returns the message that will be passed to Jasmine when the condition is not met.

Parameters

Name Type Description
element SulfideElement

The element for which the condition will be tested

Returns

String

The failure message for this condition

new VisibleCondition()

Condition to test if an element exists on the page.

Returns

Void

VisibleCondition.getFailureMessage(element)

Returns the message that will be passed to Jasmine when the condition is not met.

Parameters

Name Type Description
element SulfideElement

The element for which the condition will be tested

Returns

String

The failure message for this condition

byText(text)

Selects an element with the full text given

Parameters

Name Type Description
text String

The entire text of the element that should be selected.

Returns

SulfideElement

SulfideElement wrapper of the element.

withText(text)

Selects an element that contains the text given

Parameters

Name Type Description
text String

The text that should be part of the text in the element that should be selected.

Returns

SulfideElement

SulfideElement wrapper of the element.

byTextCaseInsensitive(text)

Selects an element with the full text given

Parameters

Name Type Description
text String

The entire text of the element that should be selected.

Returns

SulfideElement

SulfideElement wrapper of the element.

withTextCaseInsensitive(text)

Selects an element that contains the text given

Parameters

Name Type Description
text String

The text that should be part of the text in the element that should be selected.

Returns

SulfideElement

SulfideElement wrapper of the element.

byValue(text)

Selects an element with the full text given

Parameters

Name Type Description
text String

The entire text of the element that should be selected.

Returns

SulfideElement

SulfideElement wrapper of the element.

launchUrl()

The url that will be used when launching the browser Note: This variable will not be updated when opening another page.

Returns

Void

_pages()

Will keep references to the pages that are opened. The last one in this array will be the active page (i.e. the page on which actions are performed)

Returns

Void

NWJS_PUPPETEER_OPTIONS()

The options used for NWJS apps. These are the default options of puppeteer without the --disable-extensions options because NWJS runs as an extension.

Returns

Void

Sulfide(selector)

Main function of Sulfide. Acts as an SulfideElement creator.

Parameters

Name Type Description
selector String SulfideElement

CSS selector or xpath, used to create the SulfideElement, or a SulfideElement

Returns

SulfideElement

the SulfideElement based on the passed selector or xpath

Sulfide.configure(config)

Set the configuration that Sulfide will use when launching a browser

Parameters

Name Type Description
config Object

The configuration object

Returns

Object

The full configuration of Sulfide after adding the new config.

Sulfide.sleep(timeout)

Can be used to sleep the execution of a async function. Usage:

await $.sleep(5000); // Sleep for 5 seconds

Parameters

Name Type Description
timeout number

The sleep time in milliseconds

Returns

Promise

Resolves after timeout milliseconds

Sulfide.getBrowserLaunchOptions()

Creates the options object that is used to launch Chromium

Returns

Object

The options that are used to launch Chromium through Puppeteer

Sulfide.open(url)

Opens a browser if necessary and navigates to the given URL.

Parameters

Name Type Description
url String

Url of the page that will be navigated to, or (for NWJS apps) the location (full path) of nw.

Returns

Void

Sulfide.close()

Closes the browser

Returns

Promise

Promise that will be resolved when the browser is closed

Sulfide.getBrowser()

Returns the reference to the launched browser or null if no browser exists.

Returns

Browser

A reference to the browser instance

Sulfide.getPage()

Gets the current page. Will create a new page if there are no pages and the browser has been launched.

Returns

Promise

Promise will resolve with a reference to the page.

Sulfide.newPage()

Creates a new page when the browser has been launched

Returns

Promise

Resolves to a reference to the new page, or to null when no browser exists.

Sulfide.getPages()

Returns all the pages opened in the browser.

Returns

Promise

Will resolve with an array of all opened pages

Sulfide.setPage(page)

Sets the active page.

Parameters

Name Type Description
page Page string

The page that should be activated. Can be a Page instance or the url of the page that should be activated.

Returns

Page

The new page or null if the given page is not found.

Sulfide.switchTo()

Returns

Void

new SulfideElement()

A SulfideElement represents a DOM Element by a selector or an xpath. It can be used to run checks on DOM Element, e.g. if it exists.

Returns

Void

SulfideElement.constructor(selectorOrXPath, selectorDescription)

Constructor

Parameters

Name Type Description
selectorOrXPath String

A CSS selector or an xpath

selectorDescription String

The description of the selector. This should be set by selectors when creating a SulfideElement

Returns

Void

find(selector, The)

Finds the child of a SulfideElement. The child can be specified with a selector, an xpath, or a SulfideElement (created by a selector function)

Parameters

Name Type Description
selector string SulfideElement

A css selector, an xpath or a SulfideElement created by a selector function.

The string

name of the function that was called. This name will be used in the error message when an assertion fails. (Remember that there are aliases for this function)

Returns

SulfideElement

A SulfideElement that represents the child.

$(selector)

Alias for the find method

Parameters

Name Type Description
selector string SulfideElement

A css selector, and xpath or a SulfideElement created by a selector function.

Returns

SulfideElement

A SulfideElement that represents the child.

new SulfideElementCollection()

A SulfideElementCollection represents a list of DOM Elements specified by a selector. It can be used to run checks on DOM Elements, e.g. if there exist a certain number of those elements.

Returns

Void