protractor
- Version 7.0.0
- Published
- 715 kB
- 15 dependencies
- MIT license
Install
npm i protractor
yarn add protractor
pnpm add protractor
Overview
Webdriver E2E test wrapper for Angular.
Index
Variables
Functions
Classes
ProtractorBrowser
- $
- $$
- addMockModule()
- allScriptsTimeout
- angularAppRoot()
- baseUrl
- bpClient
- By
- clearMockModules()
- controlFlowIsEnabled()
- debuggerServerPort
- driver
- element
- executeScriptWithDescription()
- ExpectedConditions
- findElement()
- findElements()
- forkNewDriverInstance()
- get()
- getLocationAbsUrl()
- getPageTimeout
- getProcessedConfig()
- getRegisteredMockModules()
- ignoreSynchronization
- isElementPresent()
- mockModules_
- navigate()
- ng12Hybrid
- params
- plugins_
- ready
- refresh()
- removeMockModule()
- resetUrl
- restart()
- restartSync()
- rootEl
- setLocation()
- trackOutstandingTimeouts_
- useAllAngular2AppRoots()
- waitForAngular()
- waitForAngularEnabled()
Ptor
- $
- $$
- ActionSequence
- browser
- Browser
- Builder
- Button
- by
- By
- Capabilities
- Capability
- Command
- CommandName
- element
- ElementArrayFinder
- ElementFinder
- error
- EventEmitter
- ExpectedConditions
- FileDetector
- Key
- logging
- promise
- ProtractorBrowser
- ProtractorBy
- ProtractorExpectedConditions
- Session
- until
- utils
- WebDriver
- WebElement
- WebElementPromise
- wrapDriver
Interfaces
Config
- afterLaunch
- allScriptsTimeout
- baseUrl
- beforeLaunch
- blockingProxyUrl
- browserstackKey
- browserstackProxy
- browserstackUser
- capabilities
- chromeDriver
- configDir
- debug
- debuggerServerPort
- directConnect
- disableChecks
- disableEnvironmentOverrides
- elementExplorer
- exclude
- firefoxPath
- framework
- frameworkPath
- geckoDriver
- getMultiCapabilities
- getPageTimeout
- highlightDelay
- ignoreUncaughtExceptions
- jasmineNodeOpts
- jvmArgs
- kobitonKey
- kobitonUser
- localSeleniumStandaloneOpts
- logLevel
- maxSessions
- mochaOpts
- mockSelenium
- multiCapabilities
- ng12Hybrid
- nodeDebug
- noGlobals
- onCleanUp
- onComplete
- onPrepare
- params
- plugins
- restartBrowserBetweenTests
- resultJsonOutputFile
- rootElement
- sauceAgent
- sauceBuild
- sauceKey
- sauceProxy
- sauceRegion
- sauceSeleniumAddress
- sauceSeleniumUseHttp
- sauceUser
- SELENIUM_PROMISE_MANAGER
- seleniumAddress
- seleniumArgs
- seleniumPort
- seleniumServerJar
- seleniumServerStartTimeout
- seleniumSessionId
- seleniumWebDriver
- skipSourceMapSupport
- specs
- suite
- suites
- testobjectKey
- testobjectUser
- troubleshoot
- unknownFlags_
- untrackOutstandingTimeouts
- useBlockingProxy
- v8Debug
- verboseMultiSessions
- webDriverLogDir
- webDriverProxy
Type Aliases
Variables
variable browser
let browser: ProtractorBrowser;
variable by
let by: ProtractorBy;
variable By
let By: ProtractorBy;
variable Command
let Command: any;
variable CommandName
let CommandName: any;
variable element
let element: ElementHelper;
variable ExpectedConditions
let ExpectedConditions: ProtractorExpectedConditions;
variable protractor
let protractor: Ptor;
variable utils
let utils: { firefox: any; http: any; remote: any };
Functions
Classes
class ElementArrayFinder
class ElementArrayFinder extends WebdriverWebElement {}
ElementArrayFinder is used for operations on an array of elements (as opposed to a single element).
The ElementArrayFinder is used to set up a chain of conditions that identify an array of elements. In particular, you can call all(locator) and filter(filterFn) to return a new ElementArrayFinder modified by the conditions, and you can call get(index) to return a single ElementFinder at position 'index'.
Similar to jquery, ElementArrayFinder will search all branches of the DOM to find the elements that satisfy the conditions (i.e. all, filter, get). However, an ElementArrayFinder will not actually retrieve the elements until an action is called, which means it can be set up in helper files (i.e. page objects) before the page is available, and reused as the page changes.
You can treat an ElementArrayFinder as an array of WebElements for most purposes, in particular, you may perform actions (i.e. click, getText) on them as you would an array of WebElements. The action will apply to every element identified by the ElementArrayFinder. ElementArrayFinder extends Promise, and once an action is performed on an ElementArrayFinder, the latest result can be accessed using then, and will be returned as an array of the results; the array has length equal to the length of the elements found by the ElementArrayFinder and each result represents the result of performing the action on the element. Unlike a WebElement, an ElementArrayFinder will wait for the angular app to settle before performing finds or actions.
element.all(locator) First Second Third
Parameter browser
A browser instance.
Parameter getWebElements
A function that returns a list of the underlying Web Elements.
Parameter locator
The most relevant locator. It is only used for error reporting and ElementArrayFinder.locator.
Parameter opt_actionResults
An array of promises which will be retrieved with then. Resolves to the latest action result, or null if no action has been called.
Returns
{ElementArrayFinder}
Example 1
element.all(by.css('.items li')).then(function(items) { expect(items.length).toBe(3); expect(items[0].getText()).toBe('First'); });
// Or using the shortcut $$() notation instead of element.all(by.css()):
$$('.items li').then(function(items) { expect(items.length).toBe(3); expect(items[0].getText()).toBe('First'); });
constructor
constructor( browser_: ProtractorBrowser, getWebElements?: () => wdpromise.Promise<WebElement[]>, locator_?: any, actionResults_?: wdpromise.Promise<any>);
property actionResults_
actionResults_: wdpromise.Promise<any>;
property browser_
browser_: ProtractorBrowser;
property getWebElements
getWebElements: () => wdpromise.Promise<WebElement[]>;
property locator_
locator_: any;
method $$
$$: (selector: string) => ElementArrayFinder;
Shorthand function for finding arrays of elements by css.
element.all(by.css('.abc'))
is equivalent to$$('.abc')
$$(cssSelector) First Second
Parameter selector
a css selector
Returns
{ElementArrayFinder} which identifies the array of the located webdriver.WebElements.
Example 1
// The following two blocks of code are equivalent. let list = element.all(by.css('.count span')); expect(list.count()).toBe(2); expect(list.get(0).getText()).toBe('First'); expect(list.get(1).getText()).toBe('Second');
// Or using the shortcut $$() notation instead of element.all(by.css()):
let list = $$('.count span'); expect(list.count()).toBe(2); expect(list.get(0).getText()).toBe('First'); expect(list.get(1).getText()).toBe('Second');
method all
all: (locator: Locator) => ElementArrayFinder;
Calls to ElementArrayFinder may be chained to find an array of elements using the current elements in this ElementArrayFinder as the starting point. This function returns a new ElementArrayFinder which would contain the children elements found (and could also be empty).
element.all(locator).all(locator) 1a 1b 2a 2b
Parameter subLocator
Returns
{ElementArrayFinder}
Example 1
let foo = element.all(by.css('.parent')).all(by.css('.foo')); expect(foo.getText()).toEqual(['1a', '2a']); let baz = element.all(by.css('.parent')).all(by.css('.baz')); expect(baz.getText()).toEqual(['1b']); let nonexistent = element.all(by.css('.parent')) .all(by.css('.NONEXISTENT')); expect(nonexistent.getText()).toEqual(['']);
// Or using the shortcut $$() notation instead of element.all(by.css()):
let foo = $$('.parent').$$('.foo'); expect(foo.getText()).toEqual(['1a', '2a']); let baz = $$('.parent').$$('.baz'); expect(baz.getText()).toEqual(['1b']); let nonexistent = $$('.parent').$$('.NONEXISTENT'); expect(nonexistent.getText()).toEqual(['']);
method allowAnimations
allowAnimations: (value: boolean) => ElementArrayFinder;
Determine if animation is allowed on the current underlying elements.
Parameter value
Returns
{ElementArrayFinder} which resolves to whether animation is allowed.
Example 1
// Turns off ng-animate animations for all elements in the element(by.css('body')).allowAnimations(false);
// Or using the shortcut $() notation instead of element(by.css()):
$('body').allowAnimations(false);
method asElementFinders_
asElementFinders_: () => wdpromise.Promise<ElementFinder[]>;
Represents the ElementArrayFinder as an array of ElementFinders.
Returns
{Array.} Return a promise, which resolves to a list of ElementFinders specified by the locator.
method clone
clone: () => ElementArrayFinder;
Create a shallow copy of ElementArrayFinder.
Returns
{!ElementArrayFinder} A shallow copy of this.
method count
count: () => wdpromise.Promise<number>;
Count the number of elements represented by the ElementArrayFinder.
element.all(locator).count() First Second Third
Returns
{!webdriver.promise.Promise} A promise which resolves to the number of elements matching the locator.
Example 1
let list = element.all(by.css('.items li')); expect(list.count()).toBe(3);
// Or using the shortcut $$() notation instead of element.all(by.css()):
let list = $$('.items li'); expect(list.count()).toBe(3);
method each
each: ( fn: (elementFinder?: ElementFinder, index?: number) => any) => wdpromise.Promise<any>;
Calls the input function on each ElementFinder represented by the ElementArrayFinder.
element.all(locator).each(eachFunction) First Second Third
Parameter fn
Input function
Returns
{!webdriver.promise.Promise} A promise that will resolve when the function has been called on all the ElementFinders. The promise will resolve to null.
Example 1
element.all(by.css('.items li')).each(function(element, index) { // Will print 0 First, 1 Second, 2 Third. element.getText().then(function (text) { console.log(index, text); }); });
// Or using the shortcut $$() notation instead of element.all(by.css()):
$$('.items li').each(function(element, index) { // Will print 0 First, 1 Second, 2 Third. element.getText().then(function (text) { console.log(index, text); }); });
method evaluate
evaluate: (expression: string) => ElementArrayFinder;
Evaluates the input as if it were on the scope of the current underlying elements.
{{letiableInScope}}
Parameter expression
Returns
{ElementArrayFinder} which resolves to the evaluated expression for each underlying element. The result will be resolved as in webdriver.WebDriver.executeScript. In summary - primitives will be resolved as is, functions will be converted to string, and elements will be returned as a WebElement.
Example 1
let value = element.all(by.css('.foo')).evaluate('letiableInScope');
// Or using the shortcut $$() notation instead of element.all(by.css()):
let value = $$('.foo').evaluate('letiableInScope');
method filter
filter: ( filterFn: ( element: ElementFinder, index?: number ) => boolean | wdpromise.Promise<boolean>) => ElementArrayFinder;
Apply a filter function to each element within the ElementArrayFinder. Returns a new ElementArrayFinder with all elements that pass the filter function. The filter function receives the ElementFinder as the first argument and the index as a second arg. This does not actually retrieve the underlying list of elements, so it can be used in page objects.
element.all(locator).filter(filterFn) First Second Third
Parameter filterFn
Filter function that will test if an element should be returned. filterFn can either return a boolean or a promise that resolves to a boolean
Returns
{!ElementArrayFinder} A ElementArrayFinder that represents an array of element that satisfy the filter function.
Example 1
element.all(by.css('.items li')).filter(function(elem, index) { return elem.getText().then(function(text) { return text === 'Third'; }); }).first().click();
// Or using the shortcut $$() notation instead of element.all(by.css()):
$$('.items li').filter(function(elem, index) { return elem.getText().then(function(text) { return text === 'Third'; }); }).first().click();
method first
first: () => ElementFinder;
Get the first matching element for the ElementArrayFinder. This does not actually retrieve the underlying element.
element.all(locator).first() First Second Third
Returns
{ElementFinder} finder representing the first matching element
Example 1
let first = element.all(by.css('.items li')).first(); expect(first.getText()).toBe('First');
// Or using the shortcut $$() notation instead of element.all(by.css()):
let first = $$('.items li').first(); expect(first.getText()).toBe('First');
method get
get: (index: number | wdpromise.Promise<number>) => ElementFinder;
Get an element within the ElementArrayFinder by index. The index starts at 0. Negative indices are wrapped (i.e. -i means ith element from last) This does not actually retrieve the underlying element.
element.all(locator).get(index) First Second Third
Parameter index
Element index.
Returns
{ElementFinder} finder representing element at the given index.
Example 1
let list = element.all(by.css('.items li')); expect(list.get(0).getText()).toBe('First'); expect(list.get(1).getText()).toBe('Second');
// Or using the shortcut $$() notation instead of element.all(by.css()):
let list = $$('.items li'); expect(list.get(0).getText()).toBe('First'); expect(list.get(1).getText()).toBe('Second');
method isPresent
isPresent: () => wdpromise.Promise<boolean>;
Returns true if there are any elements present that match the finder.
element.all(locator).isPresent()
Returns
{Promise}
Example 1
expect($('.item').isPresent()).toBeTruthy();
method last
last: () => ElementFinder;
Get the last matching element for the ElementArrayFinder. This does not actually retrieve the underlying element.
element.all(locator).last() First Second Third
Returns
{ElementFinder} finder representing the last matching element
Example 1
let last = element.all(by.css('.items li')).last(); expect(last.getText()).toBe('Third');
// Or using the shortcut $$() notation instead of element.all(by.css()):
let last = $$('.items li').last(); expect(last.getText()).toBe('Third');
method locator
locator: () => Locator;
Returns the most relevant locator.
Returns
{webdriver.Locator}
Example 1
// returns by.css('#ID1') $('#ID1').locator();
// returns by.css('#ID2') $('#ID1').$('#ID2').locator();
// returns by.css('#ID1') $$('#ID1').filter(filterFn).get(0).click().locator();
method map
map: <T>( mapFn: (elementFinder?: ElementFinder, index?: number) => T | any) => wdpromise.Promise<T[]>;
Apply a map function to each element within the ElementArrayFinder. The callback receives the ElementFinder as the first argument and the index as a second arg.
element.all(locator).map(mapFunction) First Second Third
Parameter mapFn
Map function that will be applied to each element.
Returns
{!webdriver.promise.Promise} A promise that resolves to an array of values returned by the map function.
Example 1
let items = element.all(by.css('.items li')).map(function(elm, index) { return { index: index, text: elm.getText(), class: elm.getAttribute('class') }; }); expect(items).toEqual([ {index: 0, text: 'First', class: 'one'}, {index: 1, text: 'Second', class: 'two'}, {index: 2, text: 'Third', class: 'three'} ]);
// Or using the shortcut $$() notation instead of element.all(by.css()):
let items = $$('.items li').map(function(elm, index) { return { index: index, text: elm.getText(), class: elm.getAttribute('class') }; }); expect(items).toEqual([ {index: 0, text: 'First', class: 'one'}, {index: 1, text: 'Second', class: 'two'}, {index: 2, text: 'Third', class: 'three'} ]);
method reduce
reduce: (reduceFn: Function, initialValue: any) => wdpromise.Promise<any>;
Apply a reduce function against an accumulator and every element found using the locator (from left-to-right). The reduce function has to reduce every element into a single value (the accumulator). Returns promise of the accumulator. The reduce function receives the accumulator, current ElementFinder, the index, and the entire array of ElementFinders, respectively.
element.all(locator).reduce(reduceFn) First Second Third
Parameter reduceFn
Reduce function that reduces every element into a single value.
Parameter initialValue
Initial value of the accumulator.
Returns
{!webdriver.promise.Promise} A promise that resolves to the final value of the accumulator.
Example 1
let value = element.all(by.css('.items li')).reduce(function(acc, elem) { return elem.getText().then(function(text) { return acc + text + ' '; }); }, '');
expect(value).toEqual('First Second Third ');
// Or using the shortcut $$() notation instead of element.all(by.css()):
let value = $$('.items li').reduce(function(acc, elem) { return elem.getText().then(function(text) { return acc + text + ' '; }); }, '');
expect(value).toEqual('First Second Third ');
method then
then: <T>( fn?: (value: ElementFinder[] | any[]) => T | wdpromise.IThenable<T>, errorFn?: (error: any) => any) => wdpromise.Promise<T>;
Retrieve the elements represented by the ElementArrayFinder. The input function is passed to the resulting promise, which resolves to an array of ElementFinders.
element.all(locator).then(thenFunction) First Second Third
Parameter fn
Parameter errorFn
Returns
{!webdriver.promise.Promise} A promise which will resolve to an array of ElementFinders represented by the ElementArrayFinder.
Example 1
element.all(by.css('.items li')).then(function(arr) { expect(arr.length).toEqual(3); });
// Or using the shortcut $$() notation instead of element.all(by.css()):
$$('.items li').then(function(arr) { expect(arr.length).toEqual(3); });
method toElementFinder_
toElementFinder_: () => ElementFinder;
Returns an ElementFinder representation of ElementArrayFinder. It ensures that the ElementArrayFinder resolves to one and only one underlying element.
Returns
{ElementFinder} An ElementFinder representation
class ElementFinder
class ElementFinder extends WebdriverWebElement {}
The ElementFinder simply represents a single element of an ElementArrayFinder (and is more like a convenience object). As a result, anything that can be done with an ElementFinder, can also be done using an ElementArrayFinder.
The ElementFinder can be treated as a WebElement for most purposes, in particular, you may perform actions (i.e. click, getText) on them as you would a WebElement. Once an action is performed on an ElementFinder, the latest result from the chain can be accessed using the then method. Unlike a WebElement, an ElementFinder will wait for angular to settle before performing finds or actions.
ElementFinder can be used to build a chain of locators that is used to find an element. An ElementFinder does not actually attempt to find the element until an action is called, which means they can be set up in helper files before the page is available.
element(locator) {{person.name}}
Parameter browser_
A browser instance.
Parameter elementArrayFinder
The ElementArrayFinder that this is branched from.
Returns
{ElementFinder}
Example 1
// Find element with {{scopelet}} syntax. element(by.binding('person.name')).getText().then(function(name) { expect(name).toBe('Foo'); });
// Find element with ng-bind="scopelet" syntax. expect(element(by.binding('person.email')).getText()).toBe('foo@bar.com');
// Find by model. let input = element(by.model('person.name')); input.sendKeys('123'); expect(input.getAttribute('value')).toBe('Foo123');
{webdriver.WebElement}
constructor
constructor(browser_: ProtractorBrowser, elementArrayFinder: ElementArrayFinder);
property browser_
browser_: ProtractorBrowser;
property elementArrayFinder_
elementArrayFinder_: ElementArrayFinder;
property parentElementArrayFinder
parentElementArrayFinder: ElementArrayFinder;
property then
then?: ( fn: (value: any) => any | wdpromise.IThenable<any>, errorFn?: (error: any) => any) => wdpromise.Promise<any>;
method $
$: (selector: string) => ElementFinder;
Calls to may be chained to find elements within a parent.
element(locator).$(selector) Child text {{person.phone}}
Parameter selector
A css selector
Returns
{ElementFinder}
Example 1
// Chain 2 element calls. let child = element(by.css('.parent')). $('.child'); expect(child.getText()).toBe('Child text\n555-123-4567');
// Chain 3 element calls. let triple = element(by.css('.parent')). $('.child'). element(by.binding('person.phone')); expect(triple.getText()).toBe('555-123-4567');
// Or using the shortcut $() notation instead of element(by.css()):
// Chain 2 element calls. let child = $('.parent').$('.child'); expect(child.getText()).toBe('Child text\n555-123-4567');
// Chain 3 element calls. let triple = $('.parent').$('.child'). element(by.binding('person.phone')); expect(triple.getText()).toBe('555-123-4567');
method $$
$$: (selector: string) => ElementArrayFinder;
Calls to may be chained to find an array of elements within a parent.
element(locator).all(selector) First Second Third
Parameter selector
a css selector
Returns
{ElementArrayFinder}
Example 1
let items = element(by.css('.parent')).$$('li');
// Or using the shortcut $() notation instead of element(by.css()):
let items = $('.parent').$$('li');
method all
all: (subLocator: Locator) => ElementArrayFinder;
Calls to may be chained to find an array of elements within a parent.
element(locator).all(locator) First Second Third
Parameter subLocator
Returns
{ElementArrayFinder}
Example 1
let items = element(by.css('.parent')).all(by.tagName('li'));
// Or using the shortcut $() notation instead of element(by.css()):
let items = $('.parent').all(by.tagName('li'));
method allowAnimations
allowAnimations: (value: boolean) => ElementFinder;
Parameter value
Returns
{ElementFinder} which resolves to whether animation is allowed.
See Also
ElementArrayFinder.prototype.allowAnimations.
method clone
clone: () => ElementFinder;
Create a shallow copy of ElementFinder.
Returns
{!ElementFinder} A shallow copy of this.
method element
element: (subLocator: Locator) => ElementFinder;
Calls to may be chained to find elements within a parent.
element(locator).element(locator) Child text {{person.phone}}
Parameter subLocator
Returns
{ElementFinder}
Example 1
// Chain 2 element calls. let child = element(by.css('.parent')). element(by.css('.child')); expect(child.getText()).toBe('Child text\n555-123-4567');
// Chain 3 element calls. let triple = element(by.css('.parent')). element(by.css('.child')). element(by.binding('person.phone')); expect(triple.getText()).toBe('555-123-4567');
// Or using the shortcut $() notation instead of element(by.css()):
// Chain 2 element calls. let child = $('.parent').$('.child'); expect(child.getText()).toBe('Child text\n555-123-4567');
// Chain 3 element calls. let triple = $('.parent').$('.child'). element(by.binding('person.phone')); expect(triple.getText()).toBe('555-123-4567');
method equals
equals: (element: ElementFinder | WebElement) => wdpromise.Promise<any>;
Compares an element to this one for equality.
Parameter The
element to compare to.
Returns
{!webdriver.promise.Promise.} A promise that will be resolved to whether the two WebElements are equal.
method evaluate
evaluate: (expression: string) => ElementFinder;
Evaluates the input as if it were on the scope of the current element.
Parameter expression
Returns
{ElementFinder} which resolves to the evaluated expression.
Example 1
let value = element(by.id('foo')).evaluate('letiableInScope');
See Also
ElementArrayFinder.prototype.evaluate
{{letiableInScope}}
method fromWebElement_
static fromWebElement_: ( browser: ProtractorBrowser, webElem: WebElement, locator?: Locator) => ElementFinder;
method getWebElement
getWebElement: () => WebElementPromise;
Returns the WebElement represented by this ElementFinder. Throws the WebDriver error if the element doesn't exist.
element(locator).getWebElement() some text
Returns
{webdriver.WebElementPromise}
Example 1
// The following four expressions are equivalent. $('.parent').getWebElement(); element(by.css('.parent')).getWebElement(); browser.driver.findElement(by.css('.parent')); browser.findElement(by.css('.parent'));
method isElementPresent
isElementPresent: (subLocator: Locator) => wdpromise.Promise<boolean>;
Same as ElementFinder.isPresent(), except this checks whether the element identified by the subLocator is present, rather than the current element finder, i.e.:
element(by.css('#abc')).element(by.css('#def')).isPresent()
is identical toelement(by.css('#abc')).isElementPresent(by.css('#def'))
.// Or using the shortcut $() notation instead of element(by.css()):
$('#abc').$('#def').isPresent()
is identical to$('#abc').isElementPresent($('#def'))
.Parameter subLocator
Locator for element to look for.
Returns
{webdriver.promise.Promise} which resolves to whether the subelement is present on the page.
See Also
ElementFinder.isPresent
method isPresent
isPresent: () => wdpromise.Promise<boolean>;
Determine whether the element is present on the page.
{{person.name}}
Returns
{webdriver.promise.Promise} which resolves to whether the element is present on the page.
Example 1
// Element exists. expect(element(by.binding('person.name')).isPresent()).toBe(true);
// Element not present. expect(element(by.binding('notPresent')).isPresent()).toBe(false);
method locator
locator: () => any;
Returns
{webdriver.Locator}
See Also
ElementArrayFinder.prototype.locator
class ProtractorBrowser
class ProtractorBrowser extends AbstractExtendedWebDriver {}
browser {webdriver_extensions.ExtendedWebDriver}
Parameter webdriver
Parameter opt_baseUrl
A base URL to run get requests against.
Parameter opt_rootElement
Selector element that has an ng-app in scope.
Parameter opt_untrackOutstandingTimeouts
Whether Protractor should stop tracking outstanding $timeouts.
constructor
constructor( webdriverInstance: WebDriver, opt_baseUrl?: string, opt_rootElement?: any, opt_untrackOutstandingTimeouts?: boolean, opt_blockingProxyUrl?: string);
property $
$: (query: string) => ElementFinder;
Shorthand function for finding elements by css.
{function(string): ElementFinder}
property $$
$$: (query: string) => ElementArrayFinder;
Shorthand function for finding arrays of elements by css.
{function(string): ElementArrayFinder}
property allScriptsTimeout
allScriptsTimeout: number;
property baseUrl
baseUrl: string;
All get methods will be resolved against this base URL. Relative URLs are = resolved the way anchor tags resolve.
{string}
property bpClient
bpClient: BPClient;
The client used to control the BlockingProxy. If unset, BlockingProxy is not being used and Protractor will handle client-side synchronization.
property By
static By: ProtractorBy;
{ProtractorBy}
property debuggerServerPort
debuggerServerPort: number;
If specified, start a debugger server at specified port instead of repl when running element explorer. {number}
Modifiers
@public
property driver
driver: ExtendedWebDriver;
The wrapped webdriver instance. Use this to interact with pages that do not contain Angular (such as a log-in screen).
{webdriver_extensions.ExtendedWebDriver}
property element
element: ElementHelper;
Helper function for finding elements.
{function(webdriver.Locator): ElementFinder}
property ExpectedConditions
ExpectedConditions: ProtractorExpectedConditions;
{ExpectedConditions}
property getPageTimeout
getPageTimeout: number;
Timeout in milliseconds to wait for pages to load when calling
get
.{number}
property ignoreSynchronization
ignoreSynchronization: boolean;
If true, Protractor will not attempt to synchronize with the page before performing actions. This can be harmful because Protractor will not wait until $timeouts and $http calls have been processed, which can cause tests to become flaky. This should be used only when necessary, such as when a page continuously polls an API using $timeout.
Initialized to
false
by the runner.This property is deprecated - please use waitForAngularEnabled instead.
Deprecated
{boolean}
property mockModules_
mockModules_: { name: string; script: string | Function; args: any[] }[];
Information about mock modules that will be installed during every get().
{Array<{name: string, script: function|string, args: Array.}>}
property ng12Hybrid
ng12Hybrid: boolean;
If true, Protractor will interpret any angular apps it comes across as hybrid angular1/angular2 apps.
{boolean}
property params
params: any;
An object that holds custom test parameters.
{Object}
property plugins_
plugins_: Plugins;
property ready
ready: wdpromise.Promise<ProtractorBrowser>;
Resolved when the browser is ready for use. Resolves to the browser, so you can do:
forkedBrowser = await browser.forkNewDriverInstance().ready;
Set by the runner.
{webdriver.promise.Promise.}
property resetUrl
resetUrl: string;
The reset URL to use between page loads.
{string}
property rootEl
rootEl: string;
The css selector for an element on which to find Angular. This is usually 'body' but if your ng-app is on a subsection of the page it may be a subelement.
This property is deprecated - please use angularAppRoot() instead.
Deprecated
{string}
property trackOutstandingTimeouts_
trackOutstandingTimeouts_: boolean;
If true, Protractor will track outstanding $timeouts and report them in the error message if Protractor fails to synchronize with Angular in time. {boolean}
method addMockModule
addMockModule: ( name: string, script: string | Function, ...moduleArgs: any[]) => void;
Add a module to load before Angular whenever Protractor.get is called. Modules will be registered after existing modules already on the page, so any module registered here will override preexisting modules with the same name.
Parameter name
The name of the module to load or override.
Parameter script
The JavaScript to load the module. Note that this will be executed in the browser context, so it cannot access variables from outside its scope.
Parameter varArgs
Any additional arguments will be provided to the script and may be referenced using the
arguments
object.Example 1
browser.addMockModule('modName', function() { angular.module('modName', []).value('foo', 'bar'); });
method angularAppRoot
angularAppRoot: ( value?: string | wdpromise.Promise<string>) => wdpromise.Promise<string>;
Set the css selector for an element on which to find Angular. This is usually 'body' but if your ng-app is on a subsection of the page it may be a subelement.
The change will be made within WebDriver's control flow, so that commands after this method is called use the new app root. Pass nothing to get a promise that resolves to the value of the selector.
Parameter value
The new selector.
Returns
A promise that resolves with the value of the selector.
method clearMockModules
clearMockModules: () => void;
Clear the list of registered mock modules.
method controlFlowIsEnabled
controlFlowIsEnabled: () => any;
Determine if the control flow is enabled.
Returns
true if the control flow is enabled, false otherwise.
method executeScriptWithDescription
executeScriptWithDescription: ( script: string | Function, description: string, ...scriptArgs: any[]) => wdpromise.Promise<any>;
The same as , but with a customized description for debugging.
Parameter script
The script to execute.
Parameter description
A description of the command for debugging.
Parameter var_args
The arguments to pass to the script.
Returns
{!webdriver.promise.Promise.} A promise that will resolve to the scripts return value. T
method findElement
findElement: (locator: Locator) => WebElementPromise;
Waits for Angular to finish rendering before searching for elements.
Returns
{!webdriver.WebElementPromise} A promise that will be resolved to the located webdriver.WebElement.
See Also
webdriver.WebDriver.findElement
method findElements
findElements: (locator: Locator) => wdpromise.Promise<WebElement[]>;
Waits for Angular to finish rendering before searching for elements.
Returns
{!webdriver.promise.Promise} A promise that will be resolved to an array of the located webdriver.WebElements.
See Also
webdriver.WebDriver.findElements
method forkNewDriverInstance
forkNewDriverInstance: ( useSameUrl?: boolean, copyMockModules?: boolean, copyConfigUpdates?: boolean) => ProtractorBrowser;
Fork another instance of browser for use in interactive tests.
Parameter useSameUrl
Whether to navigate to current url on creation
Parameter copyMockModules
Whether to apply same mock modules on creation
Parameter copyConfigUpdates
Whether to copy over changes to
baseUrl
and similar properties initialized to values in the the config. Defaults totrue
Returns
{ProtractorBrowser} A browser instance.
Example 1
// Running with control flow enabled var fork = browser.forkNewDriverInstance(); fork.get('page1'); // 'page1' gotten by forked browser
// Running with control flow disabled var forked = await browser.forkNewDriverInstance().ready; await forked.get('page1'); // 'page1' gotten by forked browser
method get
get: (destination: string, timeout?: number) => wdpromise.Promise<any>;
Parameter destination
Destination URL.
Parameter opt_timeout
Number of milliseconds to wait for Angular to start.
Example 1
browser.get('https://angularjs.org/'); expect(browser.getCurrentUrl()).toBe('https://angularjs.org/');
See Also
webdriver.WebDriver.get
Navigate to the given destination and loads mock modules before Angular. Assumes that the page being loaded uses Angular. If you need to access a page which does not have Angular on load, use the wrapped webdriver directly.
method getLocationAbsUrl
getLocationAbsUrl: () => wdpromise.Promise<any>;
Deprecated, use
browser.getCurrentUrl()
instead.Despite its name, this function will generally return
$location.url()
, though in some cases it will return$location.absUrl()
instead. This function is only here for legacy users, and will probably be removed in Protractor 6.0.Returns
{webdriver.promise.Promise} The current absolute url from AngularJS.
Example 1
browser.get('http://angular.github.io/protractor/#/api'); expect(browser.getLocationAbsUrl()) .toBe('http://angular.github.io/protractor/#/api');
Deprecated
Please use
browser.getCurrentUrl()
method getProcessedConfig
getProcessedConfig: () => wdpromise.Promise<any>;
Get the processed configuration object that is currently being run. This will contain the specs and capabilities properties of the current runner instance.
Set by the runner.
Returns
{webdriver.promise.Promise} A promise which resolves to the capabilities object.
method getRegisteredMockModules
getRegisteredMockModules: () => Array<string | Function>;
Get a list of the current mock modules.
Returns
{Array.<!string|Function>} The list of mock modules.
method isElementPresent
isElementPresent: ( locatorOrElement: Locator | WebElement | ElementFinder) => wdpromise.Promise<any>;
Tests if an element is present on the page.
Returns
{!webdriver.promise.Promise} A promise that will resolve to whether the element is present on the page.
See Also
webdriver.WebDriver.isElementPresent
method navigate
navigate: () => Navigation;
Mixin navigation methods back into the navigation object so that they are invoked as before, i.e. driver.navigate().refresh()
method refresh
refresh: (opt_timeout?: number) => wdpromise.Promise<any>;
Parameter opt_timeout
Number of milliseconds to wait for Angular to start.
See Also
webdriver.WebDriver.refresh
Makes a full reload of the current page and loads mock modules before Angular. Assumes that the page being loaded uses Angular. If you need to access a page which does not have Angular on load, use the wrapped webdriver directly.
method removeMockModule
removeMockModule: (name: string) => void;
Remove a registered mock module.
Parameter name
The name of the module to remove.
Example 1
browser.removeMockModule('modName');
method restart
restart: () => wdpromise.Promise<ProtractorBrowser>;
Restart the browser. This is done by closing this browser instance and creating a new one. A promise resolving to the new instance is returned, and if this function was called on the global
browser
instance then Protractor will automatically overwrite the globalbrowser
variable.When restarting a forked browser, it is the caller's job to overwrite references to the old instance.
This function behaves slightly differently depending on if the webdriver control flow is enabled. If the control flow is enabled, the global
browser
object is synchronously replaced. If the control flow is disabled, the globalbrowser
is replaced asynchronously after the old driver quits.Set by the runner.
Returns
{webdriver.promise.Promise} A promise resolving to the restarted browser
Example 1
// Running against global browser, with control flow enabled browser.get('page1'); browser.restart(); browser.get('page2'); // 'page2' gotten by restarted browser
// Running against global browser, with control flow disabled await browser.get('page1'); await browser.restart(); await browser.get('page2'); // 'page2' gotten by restarted browser
// Running against forked browsers, with the control flow enabled // In this case, you may prefer
restartSync
(documented below) var forked = browser.forkNewDriverInstance(); fork.get('page1'); fork.restart().then(function(fork) { fork.get('page2'); // 'page2' gotten by restarted fork });// Running against forked browsers, with the control flow disabled var forked = await browser.forkNewDriverInstance().ready; await fork.get('page1'); fork = await fork.restart(); await fork.get('page2'); // 'page2' gotten by restarted fork
// Unexpected behavior can occur if you save references to the global
browser
var savedBrowser = browser; browser.get('foo').then(function() { console.log(browser === savedBrowser); // false }); browser.restart();
method restartSync
restartSync: () => ProtractorBrowser;
Like
restart
, but instead of returning a promise resolving to the new browser instance, returns the new browser instance directly. Can only be used when the control flow is enabled.Returns
{ProtractorBrowser} The restarted browser
Throws
{TypeError} Will throw an error if the control flow is not enabled
Example 1
// Running against global browser browser.get('page1'); browser.restartSync(); browser.get('page2'); // 'page2' gotten by restarted browser
// Running against forked browsers var forked = browser.forkNewDriverInstance(); fork.get('page1'); fork = fork.restartSync(); fork.get('page2'); // 'page2' gotten by restarted fork
method setLocation
setLocation: (url: string) => wdpromise.Promise<any>;
Browse to another page using in-page navigation.
Parameter url
In page URL using the same syntax as $location.url()
Returns
{!webdriver.promise.Promise} A promise that will resolve once page has been changed.
Example 1
browser.get('http://angular.github.io/protractor/#/tutorial'); browser.setLocation('api'); expect(browser.getCurrentUrl()) .toBe('http://angular.github.io/protractor/#/api');
method useAllAngular2AppRoots
useAllAngular2AppRoots: () => void;
Instead of using a single root element, search through all angular apps available on the page when finding elements or waiting for stability. Only compatible with Angular2.
method waitForAngular
waitForAngular: (opt_description?: string) => wdpromise.Promise<any>;
Instruct webdriver to wait until Angular has finished rendering and has no outstanding $http or $timeout calls before continuing. Note that Protractor automatically applies this command before every WebDriver action.
Parameter opt_description
An optional description to be added to webdriver logs.
Returns
{!webdriver.promise.Promise} A promise that will resolve to the scripts return value.
method waitForAngularEnabled
waitForAngularEnabled: ( enabled?: boolean | wdpromise.Promise<boolean>) => wdpromise.Promise<boolean>;
If set to false, Protractor will not wait for Angular $http and $timeout tasks to complete before interacting with the browser. This can cause flaky tests, but should be used if, for instance, your app continuously polls an API with $timeout.
Call waitForAngularEnabled() without passing a value to read the current state without changing it.
class ProtractorBy
class ProtractorBy extends WebdriverBy {}
The Protractor Locators. These provide ways of finding elements in Angular applications by binding, model, etc.
by {webdriver.By}
method addLocator
addLocator: (name: string, script: Function | string) => void;
Add a locator to this instance of ProtractorBy. This locator can then be used with element(by.locatorName(args)).
Go!
Parameter name
The name of the new locator.
Parameter script
A script to be run in the context of the browser. This script will be passed an array of arguments that contains any args passed into the locator followed by the element scoping the search and the css selector for the root angular element. It should return an array of elements.
Example 1
// Add the custom locator. by.addLocator('buttonTextSimple', function(buttonText, opt_parentElement, opt_rootSelector) { // This function will be serialized as a string and will execute in the // browser. The first argument is the text for the button. The second // argument is the parent element, if any. var using = opt_parentElement || document, buttons = using.querySelectorAll('button');
// Return an array of buttons with the text. return Array.prototype.filter.call(buttons, function(button) { return button.textContent === buttonText; }); });
// Use the custom locator. element(by.buttonTextSimple('Go!')).click();
by.addLocator(locatorName, functionOrScript)
method binding
binding: (bindingDescriptor: string) => ProtractorLocator;
Find an element by text binding. Does a partial match, so any elements bound to variables containing the input string will be returned.
Note: For AngularJS version 1.2, the interpolation brackets, (usually {{}}), are optionally allowed in the binding description string. For Angular version 1.3+, they are not allowed, and no elements will be found if they are used.
{{person.name}}
Parameter bindingDescriptor
Returns
{ProtractorLocator} location strategy
Example 1
var span1 = element(by.binding('person.name')); expect(span1.getText()).toBe('Foo');
var span2 = element(by.binding('person.email')); expect(span2.getText()).toBe('foo@bar.com');
// You can also use a substring for a partial match var span1alt = element(by.binding('name')); expect(span1alt.getText()).toBe('Foo');
// This works for sites using Angular 1.2 but NOT 1.3 var deprecatedSyntax = element(by.binding('{{person.name}}'));
method buttonText
buttonText: (searchText: string) => ProtractorLocator;
Find a button by text.
Save
Parameter searchText
Returns
{ProtractorLocator} location strategy
Example 1
element(by.buttonText('Save'));
method cssContainingText
cssContainingText: ( cssSelector: string, searchText: string | RegExp) => ProtractorLocator;
Find elements by CSS which contain a certain string.
Dog Cat
Parameter cssSelector
css selector
Parameter searchString
text search
Returns
{ProtractorLocator} location strategy
Example 1
// Returns the li for the dog, but not cat. var dog = element(by.cssContainingText('.pet', 'Dog'));
method deepCss
deepCss: (selector: string) => Locator;
Find an element by css selector within the Shadow DOM.
by.deepCss(selector) <"shadow tree"> <"shadow tree"> </> </>
Parameter selector
a css selector within the Shadow DOM.
Returns
{Locator} location strategy
Example 1
var spans = element.all(by.deepCss('span')); expect(spans.count()).toEqual(3);
method exactBinding
exactBinding: (bindingDescriptor: string) => ProtractorLocator;
Find an element by exact binding.
{{ person.name }} {{person_phone|uppercase}}
Parameter bindingDescriptor
Returns
{ProtractorLocator} location strategy
Example 1
expect(element(by.exactBinding('person.name')).isPresent()).toBe(true); expect(element(by.exactBinding('person-email')).isPresent()).toBe(true); expect(element(by.exactBinding('person')).isPresent()).toBe(false); expect(element(by.exactBinding('person_phone')).isPresent()).toBe(true); expect(element(by.exactBinding('person_phone|uppercase')).isPresent()).toBe(true); expect(element(by.exactBinding('phone')).isPresent()).toBe(false);
method exactRepeater
exactRepeater: (repeatDescriptor: string) => ProtractorLocator;
Find an element by exact repeater.
Parameter repeatDescriptor
Returns
{ProtractorLocator} location strategy
Example 1
expect(element(by.exactRepeater('person in peopleWithRedHair')).isPresent()) .toBe(true); expect(element(by.exactRepeater('person in people')).isPresent()).toBe(false); expect(element(by.exactRepeater('car in cars')).isPresent()).toBe(true);
method model
model: (model: string) => ProtractorLocator;
Find an element by ng-model expression.
by.model(modelName)
Parameter model
ng-model expression.
Returns
{ProtractorLocator} location strategy
Example 1
var input = element(by.model('person.name')); input.sendKeys('123'); expect(input.getAttribute('value')).toBe('Foo123');
method options
options: (optionsDescriptor: string) => ProtractorLocator;
Find an element by ng-options expression.
by.options(optionsDescriptor) red green
Parameter optionsDescriptor
ng-options expression.
Returns
{ProtractorLocator} location strategy
Example 1
var allOptions = element.all(by.options('c for c in colors')); expect(allOptions.count()).toEqual(2); var firstOption = allOptions.first(); expect(firstOption.getText()).toEqual('red');
method partialButtonText
partialButtonText: (searchText: string) => ProtractorLocator;
Find a button by partial text.
Save my file
Parameter searchText
Returns
{ProtractorLocator} location strategy
Example 1
element(by.partialButtonText('Save'));
method repeater
repeater: (repeatDescriptor: string) => ProtractorLocator;
Find elements inside an ng-repeat.
{{cat.name}} {{cat.age}}
{{$index}} <div class="book-info" ng-repeat-end> {{book.name}} {{book.blurb}}
Parameter repeatDescriptor
Returns
{ProtractorLocator} location strategy
Example 1
// Returns the DIV for the second cat. var secondCat = element(by.repeater('cat in pets').row(1));
// Returns the SPAN for the first cat's name. var firstCatName = element(by.repeater('cat in pets'). row(0).column('cat.name'));
// Returns a promise that resolves to an array of WebElements from a column var ages = element.all( by.repeater('cat in pets').column('cat.age'));
// Returns a promise that resolves to an array of WebElements containing // all top level elements repeated by the repeater. For 2 pets rows // resolves to an array of 2 elements. var rows = element.all(by.repeater('cat in pets'));
// Returns a promise that resolves to an array of WebElements containing // all the elements with a binding to the book's name. var divs = element.all(by.repeater('book in library').column('book.name'));
// Returns a promise that resolves to an array of WebElements containing // the DIVs for the second book. var bookInfo = element.all(by.repeater('book in library').row(1));
// Returns the H4 for the first book's name. var firstBookName = element(by.repeater('book in library'). row(0).column('book.name'));
// Returns a promise that resolves to an array of WebElements containing // all top level elements repeated by the repeater. For 2 books divs // resolves to an array of 4 elements. var divs = element.all(by.repeater('book in library'));
class ProtractorExpectedConditions
class ProtractorExpectedConditions {}
Represents a library of canned expected conditions that are useful for protractor, especially when dealing with non-angular apps.
Each condition returns a function that evaluates to a promise. You may mix multiple conditions using
and
,or
, and/ornot
. You may also mix these conditions with any other conditions that you write.See ExpectedCondition Class in Selenium WebDriver codebase. http://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html
Example 1
var EC = protractor.ExpectedConditions; var button = $('#xyz'); var isClickable = EC.elementToBeClickable(button);
browser.get(URL); browser.wait(isClickable, 5000); //wait for an element to become clickable button.click();
// You can define your own expected condition, which is a function that // takes no parameter and evaluates to a promise of a boolean. var urlChanged = function() { return browser.getCurrentUrl().then(function(url) { return url === 'http://www.angularjs.org'; }); };
// You can customize the conditions with EC.and, EC.or, and EC.not. // Here's a condition to wait for url to change, $('abc') element to contain // text 'bar', and button becomes clickable. var condition = EC.and(urlChanged, EC.textToBePresentInElement($('abc'), 'bar'), isClickable); browser.get(URL); browser.wait(condition, 5000); //wait for condition to be true. button.click();
ExpectedConditions
constructor
constructor(browser: ProtractorBrowser);
property browser
browser: ProtractorBrowser;
method alertIsPresent
alertIsPresent: () => Function;
Expect an alert to be present.
Returns
{!function} An expected condition that returns a promise representing whether an alert is present.
Example 1
var EC = protractor.ExpectedConditions; // Waits for an alert pops up. browser.wait(EC.alertIsPresent(), 5000);
ExpectedConditions.alertIsPresent
method and
and: (...args: Function[]) => Function;
Chain a number of expected conditions using logical_and, short circuiting at the first expected condition that evaluates to false.
Parameter fns
An array of expected conditions to 'and' together.
Returns
{!function} An expected condition that returns a promise which evaluates to the result of the logical and.
Example 1
var EC = protractor.ExpectedConditions; var titleContainsFoo = EC.titleContains('Foo'); var titleIsNotFooBar = EC.not(EC.titleIs('FooBar')); // Waits for title to contain 'Foo', but is not 'FooBar' browser.wait(EC.and(titleContainsFoo, titleIsNotFooBar), 5000);
ExpectedConditions.and
method elementToBeClickable
elementToBeClickable: (elementFinder: ElementFinder) => Function;
An Expectation for checking an element is visible and enabled such that you can click it.
Parameter elementFinder
The element to check
Returns
{!function} An expected condition that returns a promise representing whether the element is clickable.
Example 1
var EC = protractor.ExpectedConditions; // Waits for the element with id 'abc' to be clickable. browser.wait(EC.elementToBeClickable($('#abc')), 5000);
ExpectedConditions.elementToBeClickable
method elementToBeSelected
elementToBeSelected: (elementFinder: ElementFinder) => Function;
An expectation for checking the selection is selected.
Parameter elementFinder
The element to check
Returns
{!function} An expected condition that returns a promise representing whether the element is selected.
Example 1
var EC = protractor.ExpectedConditions; // Waits for the element with id 'myCheckbox' to be selected. browser.wait(EC.elementToBeSelected($('#myCheckbox')), 5000);
ExpectedConditions.elementToBeSelected
method invisibilityOf
invisibilityOf: (elementFinder: ElementFinder) => Function;
An expectation for checking that an element is either invisible or not present on the DOM. This is the opposite of 'visibilityOf'.
Parameter elementFinder
The element to check
Returns
{!function} An expected condition that returns a promise representing whether the element is invisible.
Example 1
var EC = protractor.ExpectedConditions; // Waits for the element with id 'abc' to be no longer visible on the dom. browser.wait(EC.invisibilityOf($('#abc')), 5000);
ExpectedConditions.invisibilityOf
method logicalChain_
logicalChain_: (defaultRet: boolean, fns: Array<Function>) => Function;
Helper function that is equivalent to the logical_and if defaultRet==true, or logical_or if defaultRet==false
Parameter defaultRet
Parameter fns
An array of expected conditions to chain.
Returns
{!function} An expected condition that returns a promise which evaluates to the result of the logical chain.
method not
not: (expectedCondition: Function) => Function;
Negates the result of a promise.
Parameter expectedCondition
Returns
{!function} An expected condition that returns the negated value.
Example 1
var EC = protractor.ExpectedConditions; var titleIsNotFoo = EC.not(EC.titleIs('Foo')); // Waits for title to become something besides 'foo'. browser.wait(titleIsNotFoo, 5000);
ExpectedConditions.not
method or
or: (...args: Function[]) => Function;
Chain a number of expected conditions using logical_or, short circuiting at the first expected condition that evaluates to true.
ExpectedConditions.or
Parameter fns
An array of expected conditions to 'or' together.
Returns
{!function} An expected condition that returns a promise which evaluates to the result of the logical or.
Example 1
var EC = protractor.ExpectedConditions; var titleContainsFoo = EC.titleContains('Foo'); var titleContainsBar = EC.titleContains('Bar'); // Waits for title to contain either 'Foo' or 'Bar' browser.wait(EC.or(titleContainsFoo, titleContainsBar), 5000);
method presenceOf
presenceOf: (elementFinder: ElementFinder) => Function;
An expectation for checking that an element is present on the DOM of a page. This does not necessarily mean that the element is visible. This is the opposite of 'stalenessOf'.
Parameter elementFinder
The element to check
Returns
{!function} An expected condition that returns a promise representing whether the element is present.
Example 1
var EC = protractor.ExpectedConditions; // Waits for the element with id 'abc' to be present on the dom. browser.wait(EC.presenceOf($('#abc')), 5000);
ExpectedConditions.presenceOf
method stalenessOf
stalenessOf: (elementFinder: ElementFinder) => Function;
An expectation for checking that an element is not attached to the DOM of a page. This is the opposite of 'presenceOf'.
Parameter elementFinder
The element to check
Returns
{!function} An expected condition that returns a promise representing whether the element is stale.
Example 1
var EC = protractor.ExpectedConditions; // Waits for the element with id 'abc' to be no longer present on the dom. browser.wait(EC.stalenessOf($('#abc')), 5000);
ExpectedConditions.stalenessOf
method textToBePresentInElement
textToBePresentInElement: ( elementFinder: ElementFinder, text: string) => Function;
An expectation for checking if the given text is present in the element. Returns false if the elementFinder does not find an element.
Parameter elementFinder
The element to check
Parameter text
The text to verify against
Returns
{!function} An expected condition that returns a promise representing whether the text is present in the element.
Example 1
var EC = protractor.ExpectedConditions; // Waits for the element with id 'abc' to contain the text 'foo'. browser.wait(EC.textToBePresentInElement($('#abc'), 'foo'), 5000);
ExpectedConditions.textToBePresentInElement
method textToBePresentInElementValue
textToBePresentInElementValue: ( elementFinder: ElementFinder, text: string) => Function;
An expectation for checking if the given text is present in the element’s value. Returns false if the elementFinder does not find an element.
Parameter elementFinder
The element to check
Parameter text
The text to verify against
Returns
{!function} An expected condition that returns a promise representing whether the text is present in the element's value.
Example 1
var EC = protractor.ExpectedConditions; // Waits for the element with id 'myInput' to contain the input 'foo'. browser.wait(EC.textToBePresentInElementValue($('#myInput'), 'foo'), 5000);
ExpectedConditions.textToBePresentInElementValue
method titleContains
titleContains: (title: string) => Function;
An expectation for checking that the title contains a case-sensitive substring.
Parameter title
The fragment of title expected
Returns
{!function} An expected condition that returns a promise representing whether the title contains the string.
Example 1
var EC = protractor.ExpectedConditions; // Waits for the title to contain 'foo'. browser.wait(EC.titleContains('foo'), 5000);
ExpectedConditions.titleContains
method titleIs
titleIs: (title: string) => Function;
An expectation for checking the title of a page.
Parameter title
The expected title, which must be an exact match.
Returns
{!function} An expected condition that returns a promise representing whether the title equals the string.
Example 1
var EC = protractor.ExpectedConditions; // Waits for the title to be 'foo'. browser.wait(EC.titleIs('foo'), 5000);
ExpectedConditions.titleIs
method urlContains
urlContains: (url: string) => Function;
An expectation for checking that the URL contains a case-sensitive substring.
Parameter url
The fragment of URL expected
Returns
{!function} An expected condition that returns a promise representing whether the URL contains the string.
Example 1
var EC = protractor.ExpectedConditions; // Waits for the URL to contain 'foo'. browser.wait(EC.urlContains('foo'), 5000);
ExpectedConditions.urlContains
method urlIs
urlIs: (url: string) => Function;
An expectation for checking the URL of a page.
Parameter url
The expected URL, which must be an exact match.
Returns
{!function} An expected condition that returns a promise representing whether the url equals the string.
Example 1
var EC = protractor.ExpectedConditions; // Waits for the URL to be 'foo'. browser.wait(EC.urlIs('foo'), 5000);
ExpectedConditions.urlIs
method visibilityOf
visibilityOf: (elementFinder: ElementFinder) => Function;
An expectation for checking that an element is present on the DOM of a page and visible. Visibility means that the element is not only displayed but also has a height and width that is greater than 0. This is the opposite of 'invisibilityOf'.
Parameter elementFinder
The element to check
Returns
{!function} An expected condition that returns a promise representing whether the element is visible.
Example 1
var EC = protractor.ExpectedConditions; // Waits for the element with id 'abc' to be visible on the dom. browser.wait(EC.visibilityOf($('#abc')), 5000);
ExpectedConditions.visibilityOf
class Ptor
class Ptor {}
property $
$: (search: string) => ElementFinder;
property $$
$$: (search: string) => ElementArrayFinder;
property ActionSequence
ActionSequence: any;
property browser
browser: ProtractorBrowser;
property Browser
Browser: webdriver.IBrowser;
property Builder
Builder: any;
property Button
Button: webdriver.IButton;
property by
by: ProtractorBy;
property By
By: ProtractorBy;
property Capabilities
Capabilities: any;
property Capability
Capability: webdriver.ICapability;
property Command
Command: any;
property CommandName
CommandName: any;
property element
element: ElementHelper;
property ElementArrayFinder
ElementArrayFinder: any;
property ElementFinder
ElementFinder: any;
property error
error: any;
property EventEmitter
EventEmitter: any;
property ExpectedConditions
ExpectedConditions: ProtractorExpectedConditions;
property FileDetector
FileDetector: any;
property Key
Key: webdriver.IKey;
property logging
logging: any;
property promise
promise: any;
property ProtractorBrowser
ProtractorBrowser: any;
property ProtractorBy
ProtractorBy: any;
property ProtractorExpectedConditions
ProtractorExpectedConditions: any;
property Session
Session: any;
property until
until: any;
property utils
utils: { firefox: any; http: any; remote: any; chrome: any };
property WebDriver
WebDriver: any;
property WebElement
WebElement: any;
property WebElementPromise
WebElementPromise: any;
property wrapDriver
wrapDriver: ( webdriver: webdriver.WebDriver, baseUrl?: string, rootElement?: string, untrackOutstandingTimeouts?: boolean) => ProtractorBrowser;
class Runner
class Runner extends EventEmitter {}
constructor
constructor(config: Config);
property config_
config_: Config;
property driverprovider_
driverprovider_: DriverProvider;
property exit_
exit_: (exitCode: number) => any;
Responsible for cleaning up test run and exiting the process.
Parameter Standard
unix exit code
property frameworkUsesAfterEach
frameworkUsesAfterEach: boolean;
property o
o: any;
property plugins_
plugins_: Plugins;
property preparer_
preparer_: any;
property ready_
ready_?: wdpromise.Promise<void>;
property restartPromise
restartPromise: q.Promise<any>;
method afterEach
afterEach: () => q.Promise<void>;
Called after each test finishes.
Responsible for
restartBrowserBetweenTests
{q.Promise} A promise that will resolve when the work here is done
Modifiers
@public
method controlFlow
controlFlow: () => any;
Get the control flow used by this runner. {Object} WebDriver control flow.
method createBrowser
createBrowser: (plugins: any, parentBrowser?: ProtractorBrowser) => any;
Create a new driver from a driverProvider. Then set up a new protractor instance using this driver. This is used to set up the initial protractor instances and any future ones.
Parameter plugins
The plugin functions
Parameter parentBrowser
The browser which spawned this one
{Protractor} a protractor instance.
Modifiers
@public
method getConfig
getConfig: () => Config;
Getter for the Runner config object
{Object} config
Modifiers
@public
method loadDriverProvider_
loadDriverProvider_: (config: Config) => void;
Grab driver provider based on type
Priority 1) if directConnect is true, use that 2) if seleniumAddress is given, use that 3) if a Sauce Labs account is given, use that 4) if a seleniumServerJar is specified, use that 5) try to find the seleniumServerJar in protractor/selenium
method run
run: () => q.Promise<any>;
The primary workhorse interface. Kicks off the test running process.
{q.Promise} A promise which resolves to the exit code of the tests.
Modifiers
@public
method runTestPreparer
runTestPreparer: (extraFlags?: string[]) => q.Promise<any>;
Executor of testPreparer
Parameter An
optional list of command line arguments the framework will accept. {q.Promise} A promise that will resolve when the test preparers are finished.
Modifiers
@public
method setTestPreparer
setTestPreparer: (filenameOrFn: string | Function) => void;
Registrar for testPreparers - executed right before tests run.
Parameter filenameOrFn
Modifiers
@public
method setupGlobals_
setupGlobals_: (browser_: ProtractorBrowser) => void;
Sets up convenience globals for test specs
method shutdown_
shutdown_: () => q.Promise<void>;
Final cleanup on exiting the runner.
{q.Promise} A promise which resolves on finish.
Interfaces
interface Config
interface Config {}
property afterLaunch
afterLaunch?: (exitCode: number) => void;
A callback function called once all tests have finished running and the WebDriver instance has been shut down. It is passed the exit code (0 if the tests passed). afterLaunch must return a promise if you want asynchronous code to be executed before the program exits. This is called only once before the program exits (after onCleanUp).
property allScriptsTimeout
allScriptsTimeout?: number;
The timeout in milliseconds for each script run on the browser. This should be longer than the maximum time your application needs to stabilize between tasks.
property baseUrl
baseUrl?: string;
A base URL for your application under test. Calls to protractor.get() with relative paths will be resolved against this URL (via url.resolve)
property beforeLaunch
beforeLaunch?: () => void;
A callback function called once configs are read but before any environment setup. This will only run once, and before onPrepare.
You can specify a file containing code to run by setting beforeLaunch to the filename string.
At this point, global variable 'protractor' object will NOT be set up, and globals from the test framework will NOT be available. The main purpose of this function should be to bring up test dependencies.
property blockingProxyUrl
blockingProxyUrl?: string;
If specified, Protractor will connect to the Blocking Proxy at the given url instead of starting it's own.
property browserstackKey
browserstackKey?: string;
If browserstackUser and browserstackKey are specified, seleniumServerJar will be ignored. The tests will be run remotely using BrowserStack.
property browserstackProxy
browserstackProxy?: string;
Proxy server to be used for connecting to BrowserStack APIs e.g. "http://proxy.example.com:1234". This should be used when you are behind a proxy server.
property browserstackUser
browserstackUser?: string;
If browserstackUser and browserstackKey are specified, seleniumServerJar will be ignored. The tests will be run remotely using BrowserStack.
property capabilities
capabilities?: { [key: string]: any; browserName?: string; /** * Name of the process executing this capability. Not used directly by * protractor or the browser, but instead pass directly to third parties * like BrowserStack and SauceLabs as the name of the job running this * test */ name?: string; /** * User defined name for the capability that will display in the results * log. Defaults to the browser name */ logName?: string; /** * Number of times to run this set of capabilities (in parallel, unless * limited by maxSessions). Default is 1. */ count?: number; /** * If this is set to be true, specs will be sharded by file (i.e. all * files to be run by this set of capabilities will run in parallel). * Default is false. */ shardTestFiles?: boolean; /** * Maximum number of browser instances that can run in parallel for this * set of capabilities. This is only needed if shardTestFiles is true. * Default is 1. */ maxInstances?: number; /** * Additional spec files to be run on this capability only. */ specs?: string[]; /** * Spec files to be excluded on this capability only. */ exclude?: string[]; /** * Optional: override global seleniumAddress on this capability only. */ seleniumAddress?: string;};
Protractor can launch your tests on one or more browsers. If you are testing on a single browser, use the capabilities option. If you are testing on multiple browsers, use the multiCapabilities array.
For a list of available capabilities, see https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities In addition, you may specify count, shardTestFiles, and maxInstances.
Example: capabilities: { browserName: 'chrome', name: 'Unnamed Job', logName: 'Chrome - English', count: 1, shardTestFiles: false, maxInstances: 1, specs: ['spec/chromeOnlySpec.js'], exclude: ['spec/doNotRunInChromeSpec.js'], seleniumAddress: 'http://localhost:4444/wd/hub' }
property chromeDriver
chromeDriver?: string;
ChromeDriver location is used to help find the chromedriver binary. This will be passed to the Selenium jar as the system property webdriver.chrome.driver. If the value is not set when launching locally, it will use the default values downloaded from webdriver-manager.
example: chromeDriver: './node_modules/webdriver-manager/selenium/chromedriver_2.20'
property configDir
configDir?: string;
property debug
debug?: boolean;
property debuggerServerPort
debuggerServerPort?: number;
property directConnect
directConnect?: boolean;
If true, Protractor will connect directly to the browser Drivers at the locations specified by chromeDriver and firefoxPath. Only Chrome and Firefox are supported for direct connect.
default: false
property disableChecks
disableChecks?: boolean;
Protractor will exit with an error if it sees any command line flags it doesn't recognize. Set disableChecks true to disable this check.
property disableEnvironmentOverrides
disableEnvironmentOverrides?: boolean;
Turns off WebDriver's environment variables overrides to ignore any environment variable and to only use the configuration in this file. Defaults to
false
property elementExplorer
elementExplorer?: any;
property exclude
exclude?: Array<string> | string;
Patterns to exclude specs.
property firefoxPath
firefoxPath?: string;
Path to the firefox application binary. If null, will attempt to find firefox in the default locations.
property framework
framework?: string;
Test framework to use. This may be one of: jasmine, mocha or custom. Default value is 'jasmine'
When the framework is set to "custom" you'll need to additionally set frameworkPath with the path relative to the config file or absolute:
framework: 'custom', frameworkPath: './frameworks/my_custom_jasmine.js',
See github.com/angular/protractor/blob/master/lib/frameworks/README.md to comply with the interface details of your custom implementation.
Jasmine is fully supported as test and assertion frameworks. Mocha has limited support. You will need to include your own assertion framework (such as Chai) if working with Mocha.
property frameworkPath
frameworkPath?: string;
property geckoDriver
geckoDriver?: string;
geckoDriver location is used to help find the gecko binary. This will be passed to the Selenium jar as the system property webdriver.gecko.driver. If the value is not set when launching locally, it will use the default values downloaded from webdriver-manager.
property getMultiCapabilities
getMultiCapabilities?: any;
If you need to resolve multiCapabilities asynchronously (i.e. wait for server/proxy, set firefox profile, etc), you can specify a function here which will return either
multiCapabilities
or a promise tomultiCapabilities
.If this returns a promise, it is resolved immediately after
beforeLaunch
is run, and before any driver is set up. If this is specified, both capabilities and multiCapabilities will be ignored.
property getPageTimeout
getPageTimeout?: number;
How long to wait for a page to load.
property highlightDelay
highlightDelay?: number;
If set, Protractor will pause the specified amount of time (in milliseconds) before interactions with browser elements (ie, sending keys, clicking). It will also highlight the element it's about to interact with.
This is an experimental feature. Enabling this will also turn on Blocking Proxy synchronization, which is also experimental.
property ignoreUncaughtExceptions
ignoreUncaughtExceptions?: boolean;
If set, Protractor will ignore uncaught exceptions instead of exiting without an error code. The exceptions will still be logged as warnings.
property jasmineNodeOpts
jasmineNodeOpts?: { [key: string]: any; /** * If true, print colors to the terminal. */ showColors?: boolean; /** * Default time to wait in ms before a test fails. */ defaultTimeoutInterval?: number; /** * Function called to print jasmine results. */ print?: () => void; /** * If set, only execute specs whose names match the pattern, which is * internally compiled to a RegExp. */ grep?: string; /** * Inverts 'grep' matches */ invertGrep?: boolean; /** * If true, run specs in semi-random order */ random?: boolean; /** * Set the randomization seed if randomization is turned on */ seed?: string;};
Options to be passed to jasmine.
See https://github.com/jasmine/jasmine-npm/blob/master/lib/jasmine.js for the exact options available.
property jvmArgs
jvmArgs?: string[];
property kobitonKey
kobitonKey?: string;
If kobitonUser and kobitonKey are specified, testobjectUser, testojbectKey, browserStackUser, browserStackKey and seleniumServerJar will be ignored. The tests will be run remotely using TestObject.
property kobitonUser
kobitonUser?: string;
If kobitonUser and kobitonKey are specified, testobjectUser, testojbectKey, browserstackUser, browserStackKey and seleniumServerJar will be ignored. The tests will be run remotely using TestObject.
property localSeleniumStandaloneOpts
localSeleniumStandaloneOpts?: { /** * The port to start the Selenium Server on, or null if the server should * find its own unused port. */ port?: any; /** * Additional command line options to pass to selenium. For example, * if you need to change the browser timeout, use * seleniumArgs: ['-browserTimeout=60'] */ args?: any; /** * Additional command line jvm options to pass to selenium. For example, * if you need to change the browser driver, use * jvmArgs: ['-Dwebdriver.ie.driver=IEDriverServer_Win32_2.53.1.exe'] */ jvmArgs?: string[];};
Can be an object which will be passed to the SeleniumServer class as args. See a full list of options at https://github.com/SeleniumHQ/selenium/blob/master/javascript/node/selenium-webdriver/remote/index.js If you specify
args
orport
in this object, it will overwrite the values set via the deprecated config valuesseleniumPort
andseleniumArgs
.
property logLevel
logLevel?: 'ERROR' | 'WARN' | 'INFO' | 'DEBUG';
Protractor log level
default: INFO
property maxSessions
maxSessions?: number;
Maximum number of total browser sessions to run. Tests are queued in sequence if number of browser sessions is limited by this parameter. Use a number less than 1 to denote unlimited. Default is unlimited.
property mochaOpts
mochaOpts?: { [key: string]: any; ui?: string; reporter?: string;};
Options to be passed to Mocha.
See the full list at http://mochajs.org/
property mockSelenium
mockSelenium?: boolean;
property multiCapabilities
multiCapabilities?: Array<any>;
If you would like to run more than one instance of WebDriver on the same tests, use multiCapabilities, which takes an array of capabilities. If this is specified, capabilities will be ignored.
property ng12Hybrid
ng12Hybrid?: boolean;
Tells Protractor to interpret any angular apps it comes across as hybrid angular1/angular2 apps (i.e. apps using ngUpgrade) Defaults to
false
{boolean}
property nodeDebug
nodeDebug?: boolean;
property noGlobals
noGlobals?: boolean;
Use default globals: 'protractor', 'browser', '$', '$$', 'element', 'by'. These also exist as properties of the protractor namespace: 'protractor.browser', 'protractor.$', 'protractor.$$', 'protractor.element', 'protractor.by', and 'protractor.By'.
When no globals is set to true, the only available global variable will be 'protractor'.
property onCleanUp
onCleanUp?: (exitCode: number) => void;
A callback function called once the tests have finished running and the WebDriver instance has been shut down. It is passed the exit code (0 if the tests passed). This is called once per capability.
property onComplete
onComplete?: () => void;
A callback function called once tests are finished. onComplete can optionally return a promise, which Protractor will wait for before shutting down webdriver.
At this point, tests will be done but global objects will still be available.
property onPrepare
onPrepare?: () => void;
A callback function called once protractor is ready and available, and before the specs are executed. If multiple capabilities are being run, this will run once per capability.
You can specify a file containing code to run by setting onPrepare to the filename string. onPrepare can optionally return a promise, which Protractor will wait for before continuing execution. This can be used if the preparation involves any asynchronous calls, e.g. interacting with the browser. Otherwise Protractor cannot guarantee order of execution and may start the tests before preparation finishes.
At this point, global variable 'protractor' object will be set up, and globals from the test framework will be available. For example, if you are using Jasmine, you can add a reporter with:
jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter( 'outputdir/', true, true));
If you need access back to the current configuration object, use a pattern like the following:
return browser.getProcessedConfig().then(function(config) { // config.capabilities is the CURRENT capability being run, if // you are using multiCapabilities. console.log('Executing capability', config.capabilities); });
property params
params?: any;
The params object will be passed directly to the Protractor instance, and can be accessed from your test as browser.params. It is an arbitrary object and can contain anything you may need in your test. This can be changed via the command line as: --params.login.user "Joe"
Example: params: { login: { user: 'Jane', password: '1234' } }
property plugins
plugins?: PluginConfig[];
See docs/plugins.md
property restartBrowserBetweenTests
restartBrowserBetweenTests?: boolean;
If true, protractor will restart the browser between each test. Default value is false.
CAUTION: This will cause your tests to slow down drastically.
property resultJsonOutputFile
resultJsonOutputFile?: any;
If set, protractor will save the test output in json format at this path. The path is relative to the location of this config.
property rootElement
rootElement?: string;
A CSS Selector for a DOM element within your Angular application. Protractor will attempt to automatically find your application, but it is necessary to set rootElement in certain cases.
In Angular 1, Protractor will use the element your app bootstrapped to by default. If that doesn't work, it will then search for hooks in
body
orng-app
elements (details here: https://git.io/v1b2r).In later versions of Angular, Protractor will try to hook into all angular apps on the page. Use rootElement to limit the scope of which apps Protractor waits for and searches within.
property sauceAgent
sauceAgent?: any;
Use sauceAgent if you need custom HTTP agent to connect to saucelabs.com APIs. This is needed if your computer is behind a corporate proxy.
To match sauce agent implementation, use [HttpProxyAgent](https://github.com/TooTallNate/node-http-proxy-agent) to generate the agent or use sauceProxy as an alternative. If a sauceProxy is provided, the sauceAgent will be overridden.
property sauceBuild
sauceBuild?: string;
Use sauceBuild if you want to group test capabilites by a build ID
property sauceKey
sauceKey?: string;
If the sauceUser and sauceKey are specified, seleniumServerJar will be ignored. The tests will be run remotely using Sauce Labs.
property sauceProxy
sauceProxy?: string;
The address of a proxy server to use for communicating to Sauce Labs REST APIs via the saucelabs node module. For example, the Sauce Labs Proxy can be setup with: sauceProxy: 'http://localhost:3128'
property sauceRegion
sauceRegion?: string;
If you run your tests on SauceLabs you can specify the region you want to run your tests in via the
sauceRegion
property. Available short handles for regions are: us: us-west-1 (default) eu: eu-central-1
property sauceSeleniumAddress
sauceSeleniumAddress?: string;
Use sauceSeleniumAddress if you need to customize the URL Protractor uses to connect to sauce labs (for example, if you are tunneling selenium traffic through a sauce connect tunnel). Default is ondemand.saucelabs.com:443/wd/hub
property sauceSeleniumUseHttp
sauceSeleniumUseHttp?: boolean;
If true, Protractor will use http:// protocol instead of https:// to connect to Sauce Labs defined by sauceSeleniumAddress.
default: false
property sauceUser
sauceUser?: string;
If the sauceUser and sauceKey are specified, seleniumServerJar will be ignored. The tests will be run remotely using Sauce Labs.
property SELENIUM_PROMISE_MANAGER
SELENIUM_PROMISE_MANAGER?: boolean;
Enable/disable the WebDriver Control Flow.
WebDriverJS (and by extention, Protractor) uses a Control Flow to manage the order in which commands are executed and promises are resolved (see docs/control-flow.md for details). However, as syntax like
async
/await
are being introduced, WebDriverJS has decided to deprecate the control flow, and have users manage the asynchronous activity themselves (details here: https://github.com/SeleniumHQ/selenium/issues/2969).At the moment, the WebDriver Control Flow is still enabled by default. You can disable it by setting the environment variable
SELENIUM_PROMISE_MANAGER
to0
. In a webdriver release in Q4 2017, the Control Flow will be disabled by default, but you will be able to re-enable it by settingSELENIUM_PROMISE_MANAGER
to1
. At a later point, the control flow will be removed for good.If you don't like managing environment variables, you can set this option in your config file, and Protractor will handle enabling/disabling the control flow for you. Setting this option is higher priority than the
SELENIUM_PROMISE_MANAGER
environment variable.{boolean=}
property seleniumAddress
seleniumAddress?: string;
The address of a running Selenium Server. If specified, Protractor will connect to an already running instance of Selenium. This usually looks like seleniumAddress: 'http://localhost:4444/wd/hub'
property seleniumArgs
seleniumArgs?: any[];
property seleniumPort
seleniumPort?: number;
property seleniumServerJar
seleniumServerJar?: string;
The location of the standalone Selenium Server jar file, relative to the location of webdriver-manager. If no other method of starting Selenium Server is found, this will default to node_modules/protractor/node_modules/webdriver-manager/selenium/<jar file>
property seleniumServerStartTimeout
seleniumServerStartTimeout?: number;
The timeout milliseconds waiting for a local standalone Selenium Server to start.
default: 30000ms
property seleniumSessionId
seleniumSessionId?: string;
The selenium session id allows Protractor to attach to an existing selenium browser session. The selenium session is maintained after the test has completed. Ignored if seleniumAddress is null.
property seleniumWebDriver
seleniumWebDriver?: WebDriver;
property skipSourceMapSupport
skipSourceMapSupport?: boolean;
Turns off source map support. Stops protractor from registering global variable
source-map-support
. Defaults tofalse
property specs
specs?: Array<string>;
Required. Spec patterns are relative to the location of this config.
Example: specs: [ 'spec/*_spec.js' ]
property suite
suite?: string;
If you would like protractor to use a specific suite by default instead of all suites, you can put that in the config file as well.
property suites
suites?: any;
Alternatively, suites may be used. When run without a command line parameter, all suites will run. If run with --suite=smoke or --suite=smoke,full only the patterns matched by the specified suites will run.
Example: suites: { smoke: 'spec/smoketests/*.js', full: 'spec/*.js' }
property testobjectKey
testobjectKey?: string;
If testobjectUser and testobjectKey are specified, kobitonUser, kobitonKey, browserStackUser, browserStackKey and seleniumServerJar will be ignored. The tests will be run remotely using TestObject.
property testobjectUser
testobjectUser?: string;
If testobjectUser and testobjectKey are specified, kobitonUser, kobitonKey, browserstackUser, browserStackKey and seleniumServerJar will be ignored. The tests will be run remotely using TestObject.
property troubleshoot
troubleshoot?: boolean;
property unknownFlags_
unknownFlags_?: string[];
property untrackOutstandingTimeouts
untrackOutstandingTimeouts?: boolean;
Protractor will track outstanding $timeouts by default, and report them in the error message if Protractor fails to synchronize with Angular in time. In order to do this Protractor needs to decorate $timeout.
CAUTION: If your app decorates $timeout, you must turn on this flag. This is false by default.
property useBlockingProxy
useBlockingProxy?: boolean;
If specified, connect to webdriver through a proxy that manages client-side synchronization. Blocking Proxy is an experimental feature and may change without notice.
property v8Debug
v8Debug?: any;
property verboseMultiSessions
verboseMultiSessions?: boolean;
Whether or not to buffer output when running tests on multiple browsers in parallel. By default, when running multiple browser sessions, the results are buffered and not logged until the test run finishes. If true, when running multiple sessions in parallel results will be logged when each test finishes.
property webDriverLogDir
webDriverLogDir?: string;
If set, will create a log file in the given directory with a readable log of the webdriver commands it executes.
This is an experimental feature. Enabling this will also turn on Blocking Proxy synchronization, which is also experimental.
property webDriverProxy
webDriverProxy?: string;
The proxy address that WebDriver (e.g. Selenium commands) traffic will go through which is tied to the browser session.
index signature
[key: string]: any;
interface ElementHelper
interface ElementHelper extends Function {}
property all
all: (locator: Locator) => ElementArrayFinder;
call signature
(locator: Locator): ElementFinder;
interface PluginConfig
interface PluginConfig {}
property inline
inline?: ProtractorPlugin;
property name
name?: string;
property package
package?: string;
property path
path?: string;
index signature
[key: string]: any;
interface ProtractorPlugin
interface ProtractorPlugin {}
property config
config?: PluginConfig;
The plugin's configuration object.
Note: this property is added by Protractor at runtime. Any pre-existing value will be overwritten.
Note: that this is not the entire Protractor config object, just the entry in the
plugins
array for this plugin.{Object}
property name
name?: string;
The name of the plugin. Used when reporting results.
If you do not specify this property, it will be filled in with something reasonable (e.g. the plugin's path) by Protractor at runtime.
{string}
property skipAngularStability
skipAngularStability?: boolean;
Used to turn off default checks for angular stability
Normally Protractor waits for all $timeout and $http calls to be processed before executing the next command. This can be disabled using browser.ignoreSynchronization, but that will also disable any .waitForPromise or .waitForCondition checks. If you want to disable synchronization with angular, but leave intact any custom plugin synchronization, this is the option for you.
This is used by plugin authors who want to replace Protractor's synchronization code with their own.
{boolean}
method addFailure
addFailure: ( message?: string, info?: { specName?: string; stackTrace?: string }) => void;
Adds a failed assertion to the test's results.
Note: this property is added by Protractor at runtime. Any pre-existing value will be overwritten.
Parameter message
The error message for the failed assertion
Parameter options
Some optional extra information about the assertion: - specName The name of the spec which this assertion belongs to. Defaults to
PLUGIN_NAME + ' Plugin Tests'
. - stackTrace The stack trace for the failure. Defaults to undefined. Defaults to{}
.Throws
{Error} Throws an error if called after results have been reported
method addSuccess
addSuccess: (info?: { specName?: string }) => void;
Adds a passed assertion to the test's results.
Note: this property is added by Protractor at runtime. Any pre-existing value will be overwritten.
Parameter options
Extra information about the assertion: - specName The name of the spec which this assertion belongs to. Defaults to
PLUGIN_NAME + ' Plugin Tests'
. Defaults to{}
.Throws
{Error} Throws an error if called after results have been reported
method addWarning
addWarning: (message?: string, info?: { specName?: string }) => void;
Warns the user that something is problematic.
Note: this property is added by Protractor at runtime. Any pre-existing value will be overwritten.
Parameter message
The message to warn the user about
Parameter options
Extra information about the assertion: - specName The name of the spec which this assertion belongs to. Defaults to
PLUGIN_NAME + ' Plugin Tests'
. Defaults to{}
.
method onPageLoad
onPageLoad: ( this: any, browser: ProtractorBrowser) => void | webdriver.promise.Promise<void>;
This is called inside browser.get() directly after the page loads, and before angular bootstraps.
Parameter browser
The browser instance which is loading a page.
{Object} bound to module.exports.
Throws
{*} If this function throws an error, a failed assertion is added to the test results.
{webdriver.promise.Promise=} Can return a promise, in which case protractor will wait for the promise to resolve before continuing. If the promise is rejected, a failed assertion is added to the test results.
method onPageStable
onPageStable: ( this: any, browser: ProtractorBrowser) => void | webdriver.promise.Promise<void>;
This is called inside browser.get() directly after angular is done bootstrapping/synchronizing. If
browser.ignoreSynchronization
istrue
, this will not be called.Parameter browser
The browser instance which is loading a page.
{Object} bound to module.exports.
Throws
{*} If this function throws an error, a failed assertion is added to the test results.
{webdriver.promise.Promise=} Can return a promise, in which case protractor will wait for the promise to resolve before continuing. If the promise is rejected, a failed assertion is added to the test results.
method onPrepare
onPrepare: (this: any) => void | Promise<void>;
This is called before the test have been run but after the test framework has been set up. Analogous to a config file's
onPrepare
.Very similar to using
setup
, but allows you to access framework-specific variables/functions (e.g.jasmine.getEnv().addReporter()
).{Object} bound to module.exports.
Throws
{*} If this function throws an error, a failed assertion is added to the test results.
{Promise=} Can return a promise, in which case protractor will wait for the promise to resolve before continuing. If the promise is rejected, a failed assertion is added to the test results.
method postResults
postResults: (this: any) => void | Promise<void>;
Called after the test results have been finalized and any jobs have been updated (if applicable).
{Object} bound to module.exports.
Throws
{*} If this function throws an error, it is outputted to the console. It is too late to add a failed assertion to the test results.
{Promise=} Can return a promise, in which case protractor will wait for the promise to resolve before continuing. If the promise is rejected, an error is logged to the console.
method postTest
postTest: (this: any, passed: boolean, testInfo: any) => void | Promise<void>;
Called after each test block (in Jasmine, this means an
it
block) completes.Parameter passed
True if the test passed.
Parameter testInfo
information about the test which just ran.
{Object} bound to module.exports.
Throws
{*} If this function throws an error, a failed assertion is added to the test results.
{Promise=} Can return a promise, in which case protractor will wait for the promise to resolve before outputting test results. Protractor will *not* wait before executing the next test; however, if the promise is rejected, a failed assertion is added to the test results.
method setup
setup: (this: any) => void | Promise<void>;
Sets up plugins before tests are run. This is called after the WebDriver session has been started, but before the test framework has been set up.
{Object} bound to module.exports.
Throws
{*} If this function throws an error, a failed assertion is added to the test results.
{Promise=} Can return a promise, in which case protractor will wait for the promise to resolve before continuing. If the promise is rejected, a failed assertion is added to the test results.
method teardown
teardown: (this: any) => void | Promise<void>;
This is called after the tests have been run, but before the WebDriver session has been terminated.
{Object} bound to module.exports.
Throws
{*} If this function throws an error, a failed assertion is added to the test results.
{Promise=} Can return a promise, in which case protractor will wait for the promise to resolve before continuing. If the promise is rejected, a failed assertion is added to the test results.
method waitForCondition
waitForCondition: ( this: any, browser: ProtractorBrowser) => webdriver.promise.Promise<boolean> | boolean;
Between every webdriver action, Protractor calls browser.waitForAngular() to make sure that Angular has no outstanding $http or $timeout calls. You can use waitForCondition() to have Protractor additionally wait for your custom condition to be truthy. If specified, this function will be called repeatedly until truthy.
Parameter browser
The browser instance which needs invoked
waitForAngular
.{Object} bound to module.exports.
Throws
{*} If this function throws an error, a failed assertion is added to the test results.
{webdriver.promise.Promise|boolean} If truthy, Protractor will continue onto the next command. If falsy, webdriver will continuously re-run this function until it is truthy. If a rejected promise is returned, a failed assertion is added to the test results, and Protractor will continue onto the next command.
method waitForPromise
waitForPromise: ( this: any, browser: ProtractorBrowser) => webdriver.promise.Promise<void>;
Between every webdriver action, Protractor calls browser.waitForAngular() to make sure that Angular has no outstanding $http or $timeout calls. You can use waitForPromise() to have Protractor additionally wait for your custom promise to be resolved inside of browser.waitForAngular().
Parameter browser
The browser instance which needs invoked
waitForAngular
.{Object} bound to module.exports.
Throws
{*} If this function throws an error, a failed assertion is added to the test results.
{webdriver.promise.Promise=} Can return a promise, in which case protractor will wait for the promise to resolve before continuing. If the promise is rejected, a failed assertion is added to the test results, and protractor will continue onto the next command. If nothing is returned or something other than a promise is returned, protractor will continue onto the next command.
Type Aliases
type Locator
type Locator = ProtractorLocator | WebDriverLocator;
Package Files (9)
Dependencies (15)
Dev Dependencies (28)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/protractor
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/protractor)
- HTML<a href="https://www.jsdocs.io/package/protractor"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3401 ms. - Missing or incorrect documentation? Open an issue for this package.