Methods
$$csstext(selectorString, text) → {Array.<Element>}
Get all element containing a class by their text.
Equivalent to Protractor's `element.all(by.cssContainingText(text))`
Parameters:
Name | Type | Description |
---|---|---|
selectorString |
string | The class to search |
text |
string | The text of the element |
- Source:
Returns:
- The elements wrapped by Protractor
- Type
- Array.<Element>
$$model(model) → {Array.<Element>}
Get all elements by their model.
Equivalent to Protractor's `element.all(by.model(model))`
Parameters:
Name | Type | Description |
---|---|---|
model |
string | The model to search |
- Source:
Returns:
- The elements wrapped by Protractor
- Type
- Array.<Element>
$csstext(selectorString, text) → {Element}
Get an element containing a class by its text.
Equivalent to Protractor's `element(by.cssContainingText(text))`
Parameters:
Name | Type | Description |
---|---|---|
selectorString |
string | The class to search |
text |
string | The text of the element |
- Source:
Returns:
- The element wrapped by Protractor
- Type
- Element
$lt(text) → {Element}
Get a link element by its text.
Equivalent to Protractor's `element(by.linkText(text))`
Parameters:
Name | Type | Description |
---|---|---|
text |
string | The text of the link |
- Source:
Returns:
- The link element wrapped by Protractor
- Type
- Element
$model(model) → {Element}
Get an element by its model.
Equivalent to Protractor's `element(by.model(model))`
Parameters:
Name | Type | Description |
---|---|---|
model |
string | The model to search |
- Source:
Returns:
- The element wrapped by Protractor
- Type
- Element
$options(descriptor) → {Array.<Element>}
Get all options of a select.
Equivalent to Protractor's `element.all(by.options(text))`
Parameters:
Name | Type | Description |
---|---|---|
descriptor |
string | The select to search |
- Source:
Returns:
- The elements wrapped by Protractor
- Type
- Array.<Element>
clearInput(input)
Circumvent Protractor/Selenium's bug when clearing an input doesn't update the model.
It seems to be linked to this issue: https://github.com/angular/protractor/issues/301
Parameters:
Name | Type | Description |
---|---|---|
input |
Element | The Protractor-wrapped input to clear. |
- Source:
clearLocalStorage()
Remove all local storage keys and values.
- Source:
clickAndWait(clickedElement, waitedElement, timeout)
Click on an element and wait for another element to be present.
Note that the element doesn't have to be visible on the page, it just has to be on the DOM.
Parameters:
Name | Type | Description |
---|---|---|
clickedElement |
Element | The element to click. |
waitedElement |
Element | The Protractor-wrapped element we are waiting for. |
timeout |
number | How much time we will wait the element before throwing an error. By default, it is 10 seconds. |
- Source:
closeLastOpenedTab()
Close the last opened tab.
- Source:
deleteAllCookies()
Delete all cookies.
- Source:
dragAndDrop(from, to)
Perform a drag and drop by providing two Protractor elements
Parameters:
Name | Type | Description |
---|---|---|
from |
Element | The Protractor-wrapped element to be moved |
to |
Element | The Protractor-wrapped element receiving `from` |
- Source:
executeInAlertAndDismiss(fn)
Execute a script in an alert.
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | The function to execute |
- Source:
executeInAngular(serviceName, fn)
Execute a function with an injected Angular service.
Parameters:
Name | Type | Description |
---|---|---|
serviceName |
string | Name of the service to retrieve |
fn |
function | The function to execute |
- Source:
Example
Destroy Angular cache
toolbox.actions.executeInAngular('$cacheFactory', function ($cacheFactory) {
$cacheFactory.destroy();
});
executeInIframe(iframeName, fn)
Execute a script in the context of a chosen iframe.
Parameters:
Name | Type | Description |
---|---|---|
iframeName |
string | The name of the iframe (id) |
fn |
function | The function to execute |
- Source:
executeInProtractor(command) → {Promise.<*>}
Execute a command in the WebDriver control flow.
The command must call `fulfill` or `reject` to allow protractor to continue test execution.
It is useful when you have external modules based on promises:
Protractor will wait the fulfilling/rejecting of the promise before continuing test execution.
Parameters:
Name | Type | Description |
---|---|---|
command |
function | The function to execute. It must call either fulfill or reject. |
- Source:
Returns:
- Type
- Promise.<*>
Example
<caption>Make an external request to some API</caption> *
toolbox.actions.executeInProtractor(function (fulfill, reject) {
let req = new XMLHttpRequest();
req.open('GET', 'http://contentsquare.github.io');
req.send();
req.onreadystatechange = (res) => {
if (req.readyState === 4 && req.status >= 200 && req.status < 300) {
fulfill();
} else {
reject();
}
};
});
getAndWait(url, element, timeout)
Open a new page and wait for an element to be present in the next page.
Note that the element doesn't have to be visible on the page, it just has to be on the DOM.
Parameters:
Name | Type | Description |
---|---|---|
url |
string | The URL to reach. |
element |
Element | The Protractor-wrapped element we are waiting for. |
timeout |
number | How much time we will wait the element before throwing an error. By default, it is 10 seconds. |
- Source:
getFocusedElement() → {Element}
Returns the currently focused element.
- Source:
Returns:
- The currently focused element.
- Type
- Element
getLocalStorageValue(key)
Retrieve a local storage value from its key.
Parameters:
Name | Type | Description |
---|---|---|
key |
string | The key used for storing the object. |
- Source:
getSelectedOption(select) → {Element}
Get the currently selected option of a select.
It has to be wrapped by Protractor.
Parameters:
Name | Type | Description |
---|---|---|
select |
Element | The Protractor-wrapped select |
- Source:
Returns:
- The option wrapped by Protractor
- Type
- Element
hasClass(element, className) → {Promise.<Boolean>}
Detect the presence of a class on a particular element.
Parameters:
Name | Type | Description |
---|---|---|
element |
Element | A Protractor-wrapped element. |
className |
string | The class we want to check. |
- Source:
Returns:
- Type
- Promise.<Boolean>
hasOption(select, optionText) → {Promise.<Boolean>}
Detect the presence of an option on a particular element.
Parameters:
Name | Type | Description |
---|---|---|
select |
Element | The Protractor-wrapped select |
optionText |
string | The text of the option |
- Source:
Returns:
- Type
- Promise.<Boolean>
mouseMoveTo(target)
Move the mouse to hover the specified target.
Parameters:
Name | Type | Description |
---|---|---|
target |
Element | The Protractor-wrapped element to hover |
- Source:
performClicks(selector, nbClicks)
Performs a provided number of clicks on an element.
Parameters:
Name | Type | Description |
---|---|---|
selector |
string | A CSS selector |
nbClicks |
number | The number of clicks |
- Source:
performScrolls(nbScrolls, pxToScroll)
Performs a provided number of scrolls on the page.
Parameters:
Name | Type | Description |
---|---|---|
nbScrolls |
number | The number of scrolls to perform |
pxToScroll |
number | The number of pixel to scroll |
- Source:
pressGlobalKey(key)
Press a key without focusing an input/textarea
Parameters:
Name | Type | Description |
---|---|---|
key |
number | Keycode of the key you want to press. |
- Source:
selectOption(select, value) → {Element}
Select a particular option of a select by its value.
Parameters:
Name | Type | Description |
---|---|---|
select |
Element | A Protractor-wrapped element |
value |
* | The value you want to select |
- Source:
Returns:
- The option wrapped by Protractor
- Type
- Element
setWindowSize(width, height)
Set browser's window size
Parameters:
Name | Type | Description |
---|---|---|
width |
number | The desired width for the browser |
height |
number | The desired height for the browser |
- Source:
waitElement(element, timeout)
Wait a provided amount of time for an element to be present on the page.
Note that the element doesn't have to be visible on the page, it just has to be on the DOM.
Parameters:
Name | Type | Description |
---|---|---|
element |
Element | The Protractor-wrapped element we are waiting for. |
timeout |
number | How much time we will wait the element before throwing an error. By default, it is 10 seconds. |
- Source:
waitToBeClickable(element, timeout)
Wait a provided amount of time for an element to be clickable.
Parameters:
Name | Type | Description |
---|---|---|
element |
Element | The Protractor-wrapped element we are waiting for. |
timeout |
number | How much time we will wait the element before throwing an error. By default, it is 10 seconds. |
- Source:
waitToBeDisplayed(element, timeout)
Wait a provided amount of time for an element be visible on the page.
Note that the element must be attached to the DOM AND visible.
Parameters:
Name | Type | Description |
---|---|---|
element |
Element | The Protractor-wrapped element we are waiting for. |
timeout |
number | How much time we will wait the element before throwing an error. By default, it is 10 seconds. |
- Source:
waitToBeHidden(element, timeout)
Wait a provided amount of time for an element to hidden.
Note that the element can be on the DOM, it just has to be hidden.
Parameters:
Name | Type | Description |
---|---|---|
element |
Element | The Protractor-wrapped element we are waiting for. |
timeout |
number | How much time we will wait the element before throwing an error. By default, it is 10 seconds. |
- Source:
waitToDisappear(element, timeout)
Wait a provided amount of time for an element to disappear.
Note that the element must have disappeared from the DOM.
Parameters:
Name | Type | Description |
---|---|---|
element |
Element | The Protractor-wrapped element we are waiting for. |
timeout |
number | How much time we will wait the element before throwing an error. By default, it is 10 seconds. |
- Source:
waitToHaveClass(element, cls, timeout)
Wait for a provided element to have certain class.
Parameters:
Name | Type | Description |
---|---|---|
element |
Element | The element we want to test. |
cls |
string | The class we are waiting for. |
timeout |
number | How much time we will wait the element before throwing an error. By default, it is 10 seconds. |
- Source:
waitToHaveText(element, timeout)
Wait for a provided element to have a text.
Parameters:
Name | Type | Description |
---|---|---|
element |
Element | The element we want to test. |
timeout |
number | How much time we will wait the element before throwing an error. By default, it is 10 seconds. |
- Source:
waitToResolve(promiseCall, resolver, timeout)
Wait a provided amount of time for a promise to be resolved.
Parameters:
Name | Type | Description |
---|---|---|
promiseCall |
Promise.<*> | The promise we want to wait for. |
resolver |
Element | The condition that will permit the fulfilling of the promise. |
timeout |
number | How much time we will wait the promise before throwing an error. By default, it is 10 seconds. |
- Source: