UNPKG

protractor

Version:

Webdriver E2E test wrapper for Angular.

1,971 lines (1,117 loc) 88.6 kB
Protractor API 0.22.0 ============== ##protractor * [element](#element) * [elementFinder.find](#elementfinderfind) * [elementFinder.isPresent](#elementfinderispresent) * [elementFinder.locator](#elementfinderlocator) * [elementFinder.element](#elementfinderelement) * [elementFinder.$](#elementfinder) * [element.all](#elementall) * [elementArrayFinder.count](#elementarrayfindercount) * [elementArrayFinder.get](#elementarrayfinderget) * [elementArrayFinder.first](#elementarrayfinderfirst) * [elementArrayFinder.last](#elementarrayfinderlast) * [elementArrayFinder.each](#elementarrayfindereach) * [elementArrayFinder.map](#elementarrayfindermap) * [Protractor](#protractor) * [Protractor.prototype.waitForAngular](#protractorprototypewaitforangular) * [Protractor.prototype.wrapWebElement](#protractorprototypewrapwebelement) * [element.$](#element) * [element.findElement](#elementfindelement) * [element.$$](#element) * [element.findElements](#elementfindelements) * [element.isElementPresent](#elementiselementpresent) * [element.evaluate](#elementevaluate) * [Protractor.prototype.findElement](#protractorprototypefindelement) * [Protractor.prototype.findElements](#protractorprototypefindelements) * [Protractor.prototype.isElementPresent](#protractorprototypeiselementpresent) * [Protractor.prototype.addMockModule](#protractorprototypeaddmockmodule) * [Protractor.prototype.clearMockModules](#protractorprototypeclearmockmodules) * [Protractor.prototype.removeMockModule](#protractorprototyperemovemockmodule) * [Protractor.prototype.get](#protractorprototypeget) * [Protractor.prototype.refresh](#protractorprototyperefresh) * [Protractor.prototype.navigate](#protractorprototypenavigate) * [Protractor.prototype.setLocation](#protractorprototypesetlocation) * [Protractor.prototype.getLocationAbsUrl](#protractorprototypegetlocationabsurl) * [Protractor.prototype.debugger](#protractorprototypedebugger) * [Protractor.prototype.pause](#protractorprototypepause) ##locators * [ProtractorBy](#protractorby) * [WebdriverBy.prototype](#webdriverbyprototype) * [ProtractorBy.prototype.addLocator](#protractorbyprototypeaddlocator) * [ProtractorBy.prototype.binding](#protractorbyprototypebinding) * [ProtractorBy.prototype.exactBinding](#protractorbyprototypeexactbinding) * [ProtractorBy.prototype.select](#protractorbyprototypeselect) * [ProtractorBy.prototype.selectedOption](#protractorbyprototypeselectedoption) * [ProtractorBy.prototype.input](#protractorbyprototypeinput) * [ProtractorBy.prototype.model](#protractorbyprototypemodel) * [ProtractorBy.prototype.buttonText](#protractorbyprototypebuttontext) * [ProtractorBy.prototype.partialButtonText](#protractorbyprototypepartialbuttontext) * [ProtractorBy.prototype.textarea](#protractorbyprototypetextarea) * [ProtractorBy.prototype.repeater](#protractorbyprototyperepeater) * [ProtractorBy.prototype.cssContainingText](#protractorbyprototypecsscontainingtext) ##webdriver * [webdriver.WebDriver](#webdriverwebdriver) * [webdriver.WebDriver.attachToSession](#webdriverwebdriverattachtosession) * [webdriver.WebDriver.createSession](#webdriverwebdrivercreatesession) * [webdriver.WebDriver.prototype.controlFlow](#webdriverwebdriverprototypecontrolflow) * [webdriver.WebDriver.prototype.schedule](#webdriverwebdriverprototypeschedule) * [webdriver.WebDriver.prototype.getSession](#webdriverwebdriverprototypegetsession) * [webdriver.WebDriver.prototype.getCapabilities](#webdriverwebdriverprototypegetcapabilities) * [webdriver.WebDriver.prototype.quit](#webdriverwebdriverprototypequit) * [webdriver.WebDriver.prototype.actions](#webdriverwebdriverprototypeactions) * [webdriver.WebDriver.prototype.executeScript](#webdriverwebdriverprototypeexecutescript) * [webdriver.WebDriver.prototype.executeAsyncScript](#webdriverwebdriverprototypeexecuteasyncscript) * [webdriver.WebDriver.prototype.call](#webdriverwebdriverprototypecall) * [webdriver.WebDriver.prototype.wait](#webdriverwebdriverprototypewait) * [webdriver.WebDriver.prototype.sleep](#webdriverwebdriverprototypesleep) * [webdriver.WebDriver.prototype.getWindowHandle](#webdriverwebdriverprototypegetwindowhandle) * [webdriver.WebDriver.prototype.getAllWindowHandles](#webdriverwebdriverprototypegetallwindowhandles) * [webdriver.WebDriver.prototype.getPageSource](#webdriverwebdriverprototypegetpagesource) * [webdriver.WebDriver.prototype.close](#webdriverwebdriverprototypeclose) * [webdriver.WebDriver.prototype.get](#webdriverwebdriverprototypeget) * [webdriver.WebDriver.prototype.getCurrentUrl](#webdriverwebdriverprototypegetcurrenturl) * [webdriver.WebDriver.prototype.getTitle](#webdriverwebdriverprototypegettitle) * [webdriver.WebDriver.prototype.findElement](#webdriverwebdriverprototypefindelement) * [webdriver.WebDriver.prototype.isElementPresent](#webdriverwebdriverprototypeiselementpresent) * [webdriver.WebDriver.prototype.findElements](#webdriverwebdriverprototypefindelements) * [webdriver.WebDriver.prototype.takeScreenshot](#webdriverwebdriverprototypetakescreenshot) * [webdriver.WebDriver.prototype.manage](#webdriverwebdriverprototypemanage) * [webdriver.WebDriver.prototype.navigate](#webdriverwebdriverprototypenavigate) * [webdriver.WebDriver.prototype.switchTo](#webdriverwebdriverprototypeswitchto) * [webdriver.WebDriver.Navigation](#webdriverwebdrivernavigation) * [webdriver.WebDriver.Navigation.prototype.to](#webdriverwebdrivernavigationprototypeto) * [webdriver.WebDriver.Navigation.prototype.back](#webdriverwebdrivernavigationprototypeback) * [webdriver.WebDriver.Navigation.prototype.forward](#webdriverwebdrivernavigationprototypeforward) * [webdriver.WebDriver.Navigation.prototype.refresh](#webdriverwebdrivernavigationprototyperefresh) * [webdriver.WebDriver.Options](#webdriverwebdriveroptions) * [webdriver.WebDriver.Options.prototype.addCookie](#webdriverwebdriveroptionsprototypeaddcookie) * [webdriver.WebDriver.Options.prototype.deleteAllCookies](#webdriverwebdriveroptionsprototypedeleteallcookies) * [webdriver.WebDriver.Options.prototype.deleteCookie](#webdriverwebdriveroptionsprototypedeletecookie) * [webdriver.WebDriver.Options.prototype.getCookies](#webdriverwebdriveroptionsprototypegetcookies) * [webdriver.WebDriver.Options.prototype.getCookie](#webdriverwebdriveroptionsprototypegetcookie) * [webdriver.WebDriver.Options.prototype.logs](#webdriverwebdriveroptionsprototypelogs) * [webdriver.WebDriver.Options.prototype.timeouts](#webdriverwebdriveroptionsprototypetimeouts) * [webdriver.WebDriver.Options.prototype.window](#webdriverwebdriveroptionsprototypewindow) * [webdriver.WebDriver.Timeouts](#webdriverwebdrivertimeouts) * [webdriver.WebDriver.Timeouts.prototype.implicitlyWait](#webdriverwebdrivertimeoutsprototypeimplicitlywait) * [webdriver.WebDriver.Timeouts.prototype.setScriptTimeout](#webdriverwebdrivertimeoutsprototypesetscripttimeout) * [webdriver.WebDriver.Timeouts.prototype.pageLoadTimeout](#webdriverwebdrivertimeoutsprototypepageloadtimeout) * [webdriver.WebDriver.Window](#webdriverwebdriverwindow) * [webdriver.WebDriver.Window.prototype.getPosition](#webdriverwebdriverwindowprototypegetposition) * [webdriver.WebDriver.Window.prototype.setPosition](#webdriverwebdriverwindowprototypesetposition) * [webdriver.WebDriver.Window.prototype.getSize](#webdriverwebdriverwindowprototypegetsize) * [webdriver.WebDriver.Window.prototype.setSize](#webdriverwebdriverwindowprototypesetsize) * [webdriver.WebDriver.Window.prototype.maximize](#webdriverwebdriverwindowprototypemaximize) * [webdriver.WebDriver.Logs](#webdriverwebdriverlogs) * [webdriver.WebDriver.Logs.prototype.get](#webdriverwebdriverlogsprototypeget) * [webdriver.WebDriver.Logs.prototype.getAvailableLogTypes](#webdriverwebdriverlogsprototypegetavailablelogtypes) * [webdriver.WebDriver.TargetLocator](#webdriverwebdrivertargetlocator) * [webdriver.WebDriver.TargetLocator.prototype.activeElement](#webdriverwebdrivertargetlocatorprototypeactiveelement) * [webdriver.WebDriver.TargetLocator.prototype.defaultContent](#webdriverwebdrivertargetlocatorprototypedefaultcontent) * [webdriver.WebDriver.TargetLocator.prototype.frame](#webdriverwebdrivertargetlocatorprototypeframe) * [webdriver.WebDriver.TargetLocator.prototype.window](#webdriverwebdrivertargetlocatorprototypewindow) * [webdriver.WebDriver.TargetLocator.prototype.alert](#webdriverwebdrivertargetlocatorprototypealert) * [webdriver.Key.chord](#webdriverkeychord) * [webdriver.WebElement](#webdriverwebelement) * [webdriver.WebElement.equals](#webdriverwebelementequals) * [webdriver.WebElement.prototype.getDriver](#webdriverwebelementprototypegetdriver) * [webdriver.WebElement.prototype.toWireValue](#webdriverwebelementprototypetowirevalue) * [webdriver.WebElement.prototype.findElement](#webdriverwebelementprototypefindelement) * [webdriver.WebElement.prototype.isElementPresent](#webdriverwebelementprototypeiselementpresent) * [webdriver.WebElement.prototype.findElements](#webdriverwebelementprototypefindelements) * [webdriver.WebElement.prototype.click](#webdriverwebelementprototypeclick) * [webdriver.WebElement.prototype.sendKeys](#webdriverwebelementprototypesendkeys) * [webdriver.WebElement.prototype.getTagName](#webdriverwebelementprototypegettagname) * [webdriver.WebElement.prototype.getCssValue](#webdriverwebelementprototypegetcssvalue) * [webdriver.WebElement.prototype.getAttribute](#webdriverwebelementprototypegetattribute) * [webdriver.WebElement.prototype.getText](#webdriverwebelementprototypegettext) * [webdriver.WebElement.prototype.getSize](#webdriverwebelementprototypegetsize) * [webdriver.WebElement.prototype.getLocation](#webdriverwebelementprototypegetlocation) * [webdriver.WebElement.prototype.isEnabled](#webdriverwebelementprototypeisenabled) * [webdriver.WebElement.prototype.isSelected](#webdriverwebelementprototypeisselected) * [webdriver.WebElement.prototype.submit](#webdriverwebelementprototypesubmit) * [webdriver.WebElement.prototype.clear](#webdriverwebelementprototypeclear) * [webdriver.WebElement.prototype.isDisplayed](#webdriverwebelementprototypeisdisplayed) * [webdriver.WebElement.prototype.getOuterHtml](#webdriverwebelementprototypegetouterhtml) * [webdriver.WebElement.prototype.getInnerHtml](#webdriverwebelementprototypegetinnerhtml) * [webdriver.Alert](#webdriveralert) * [webdriver.Alert.prototype.getText](#webdriveralertprototypegettext) * [webdriver.Alert.prototype.accept](#webdriveralertprototypeaccept) * [webdriver.Alert.prototype.dismiss](#webdriveralertprototypedismiss) * [webdriver.Alert.prototype.sendKeys](#webdriveralertprototypesendkeys) * [webdriver.UnhandledAlertError](#webdriverunhandledalerterror) * [webdriver.UnhandledAlertError.prototype.getAlert](#webdriverunhandledalerterrorprototypegetalert) ##[element](https://github.com/angular/protractor/blob/master/lib/protractor.js#L74) #### Use as: element(locator) The element function returns an Element Finder. Element Finders do not actually attempt to find the element until a method is called on them, which means they can be set up in helper files before the page is available. ###Example ```html <span>{{person.name}}</span> <span ng-bind="person.email"></span> <input type="text" ng-model="person.name"/> ``` ```javascript // Find element with {{scopeVar}} syntax. element(by.binding('person.name')).getText().then(function(name) { expect(name).toBe('Foo'); }); // Find element with ng-bind="scopeVar" syntax. expect(element(by.binding('person.email')).getText()).toBe('foo@bar.com'); // Find by model. var input = element(by.model('person.name')); input.sendKeys('123'); expect(input.getAttribute('value')).toBe('Foo123'); ``` ###Params Param | Type | Description --- | --- | --- locator | webdriver.Locator | An element locator. ###Returns Type | Description --- | --- ElementFinder | ##[elementFinder.find](https://github.com/angular/protractor/blob/master/lib/protractor.js#L128) #### Use as: element(locator).find() Returns the specified WebElement. Throws the WebDriver error if the element doesn't exist. ###Returns Type | Description --- | --- [webdriver.WebElement](#webdriverwebelement) | ##[elementFinder.isPresent](https://github.com/angular/protractor/blob/master/lib/protractor.js#L139) #### Use as: element(locator).isPresent() Determine whether an element is present on the page. ###Example ```html <span>{{person.name}}</span> ``` ```javascript // Element exists. expect(element(by.binding('person.name')).isPresent()).toBe(true); // Element not present. expect(element(by.binding('notPresent')).isPresent()).toBe(false); ``` ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise which resolves to a boolean. ##[elementFinder.locator](https://github.com/angular/protractor/blob/master/lib/protractor.js#L161) Returns the originally specified locator. ###Returns Type | Description --- | --- webdriver.Locator | The element locator. ##[elementFinder.element](https://github.com/angular/protractor/blob/master/lib/protractor.js#L170) #### Use as: element(locator).element(locator) Calls to element may be chained to find elements within a parent. ###Example ```html <div class="parent"> <div class="child"> Child text <div>{{person.phone}}</div> </div> </div> ``` ```javascript // Chain 2 element calls. var child = element(by.css('.parent')). element(by.css('.child')); expect(child.getText()).toBe('Child text\n555-123-4567'); // Chain 3 element calls. var triple = element(by.css('.parent')). element(by.css('.child')). element(by.binding('person.phone')); expect(triple.getText()).toBe('555-123-4567'); ``` ###Params Param | Type | Description --- | --- | --- ptor | [Protractor](#protractor) | opt_usingChain | Array.&lt;webdriver.Locator&gt;= | ###Returns Type | Description --- | --- function(webdriver.Locator): ElementFinder | ##[elementFinder.$](https://github.com/angular/protractor/blob/master/lib/protractor.js#L201) #### Use as: element(locator).$(cssSelector) Shortcut for chaining css element finders. ###Example ```html <div class="parent"> <div class="child"> Child text <div class="grandchild">{{person.phone}}</div> </div> </div> ``` ```javascript // Chain 2 element calls. var child = element(by.css('.parent')).$('.child'); expect(child.getText()).toBe('Child text\n555-123-4567'); // Chain 3 element calls. var triple = $('.parent').$('.child').$('.grandchild'); expect(triple.getText()).toBe('555-123-4567'); ``` ###Params Param | Type | Description --- | --- | --- cssSelector | string | A css selector. ###Returns Type | Description --- | --- ElementFinder | ##[element.all](https://github.com/angular/protractor/blob/master/lib/protractor.js#L238) #### Use as: element.all(locator) element.all is used for operations on an array of elements (as opposed to a single element). ###Example ```html <ul class="items"> <li>First</li> <li>Second</li> <li>Third</li> </ul> ``` ```javascript element.all(by.css('.items li')).then(function(items) { expect(items.length).toBe(3); expect(items[0].getText()).toBe('First'); }); ``` ###Params Param | Type | Description --- | --- | --- locator | webdriver.Locator | ###Returns Type | Description --- | --- ElementArrayFinder | ##[elementArrayFinder.count](https://github.com/angular/protractor/blob/master/lib/protractor.js#L262) #### Use as: element.all(locator).count() Count the number of elements found by the locator. ###Example ```html <ul class="items"> <li>First</li> <li>Second</li> <li>Third</li> </ul> ``` ```javascript var list = element.all(by.css('.items li')); expect(list.count()).toBe(3); ``` ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise which resolves to the number of elements matching the locator. ##[elementArrayFinder.get](https://github.com/angular/protractor/blob/master/lib/protractor.js#L286) #### Use as: element.all(locator).get(index) Get an element found by the locator by index. The index starts at 0. ###Example ```html <ul class="items"> <li>First</li> <li>Second</li> <li>Third</li> </ul> ``` ```javascript var list = element.all(by.css('.items li')); expect(list.get(0).getText()).toBe('First'); expect(list.get(1).getText()).toBe('Second'); ``` ###Params Param | Type | Description --- | --- | --- index | number | Element index. ###Returns Type | Description --- | --- [webdriver.WebElement](#webdriverwebelement) | The element at the given index ##[elementArrayFinder.first](https://github.com/angular/protractor/blob/master/lib/protractor.js#L312) #### Use as: element.all(locator).first() Get the first element found using the locator. ###Example ```html <ul class="items"> <li>First</li> <li>Second</li> <li>Third</li> </ul> ``` ```javascript var list = element.all(by.css('.items li')); expect(list.first().getText()).toBe('First'); ``` ###Returns Type | Description --- | --- [webdriver.WebElement](#webdriverwebelement) | The first matching element ##[elementArrayFinder.last](https://github.com/angular/protractor/blob/master/lib/protractor.js#L339) #### Use as: element.all(locator).last() Get the last matching element for the locator. ###Example ```html <ul class="items"> <li>First</li> <li>Second</li> <li>Third</li> </ul> ``` ```javascript var list = element.all(by.css('.items li')); expect(list.last().getText()).toBe('Third'); ``` ###Returns Type | Description --- | --- [webdriver.WebElement](#webdriverwebelement) | the last matching element ##[elementArrayFinder.each](https://github.com/angular/protractor/blob/master/lib/protractor.js#L389) #### Use as: element.all(locator).each(eachFunction) Calls the input function on each WebElement found by the locator. ###Example ```html <ul class="items"> <li>First</li> <li>Second</li> <li>Third</li> </ul> ``` ```javascript element.all(by.css('.items li')).each(function(element) { // Will print First, Second, Third. element.getText().then(console.log); }); ``` ###Params Param | Type | Description --- | --- | --- fn | function([webdriver.WebElement](#webdriverwebelement)) | Input function ##[elementArrayFinder.map](https://github.com/angular/protractor/blob/master/lib/protractor.js#L416) #### Use as: element.all(locator).map(mapFunction) Apply a map function to each element found using the locator. The callback receives the web element as the first argument and the index as a second arg. ###Example ```html <ul class="items"> <li class="one">First</li> <li class="two">Second</li> <li class="three">Third</li> </ul> ``` ```javascript var 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'} ]); ``` ###Params Param | Type | Description --- | --- | --- mapFn | function([webdriver.WebElement](#webdriverwebelement), number) | Map function that will be applied to each element. ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise that resolves to an array of values returned by the map function. ##[Protractor](https://github.com/angular/protractor/blob/master/lib/protractor.js#L494) ###Params Param | Type | Description --- | --- | --- webdriver | [webdriver.WebDriver](#webdriverwebdriver) | opt_baseUrl | string= | A base URL to run get requests against. opt_rootElement | string= | Selector element that has an ng-app in scope. ##[Protractor.prototype.waitForAngular](https://github.com/angular/protractor/blob/master/lib/protractor.js#L589) Instruct webdriver to wait until Angular has finished rendering and has no outstanding $http calls before continuing. ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise that will resolve to the scripts return value. ##[Protractor.prototype.wrapWebElement](https://github.com/angular/protractor/blob/master/lib/protractor.js#L630) Wrap a webdriver.WebElement with protractor specific functionality. ###Params Param | Type | Description --- | --- | --- element | [webdriver.WebElement](#webdriverwebelement) | ###Returns Type | Description --- | --- [webdriver.WebElement](#webdriverwebelement) | the wrapped web element. ##[element.$](https://github.com/angular/protractor/blob/master/lib/protractor.js#L655) #### Use as: $(cssSelector) Shortcut for querying the document directly with css. ###Example ```html <div class="count"> <span class="one">First</span> <span class="two">Second</span> </div> ``` ```javascript var item = $('.count .two'); expect(item.getText()).toBe('Second'); ``` ###Params Param | Type | Description --- | --- | --- selector | string | A css selector ###Returns Type | Description --- | --- &#33;[webdriver.WebElement](#webdriverwebelement) | ##[element.findElement](https://github.com/angular/protractor/blob/master/lib/protractor.js#L678) ###Returns Type | Description --- | --- &#33;[webdriver.WebElement](#webdriverwebelement) | ##[element.$$](https://github.com/angular/protractor/blob/master/lib/protractor.js#L695) #### Use as: $$(cssSelector) Shortcut for querying the document directly with css. ###Example ```html <div class="count"> <span class="one">First</span> <span class="two">Second</span> </div> ``` ```javascript // The following protractor expressions are equivalent. var list = element.all(by.css('.count span')); expect(list.count()).toBe(2); list = $$('.count span'); expect(list.count()).toBe(2); expect(list.get(0).getText()).toBe('First'); expect(list.get(1).getText()).toBe('Second'); ``` ###Params Param | Type | Description --- | --- | --- selector | string | a css selector ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise that will be resolved to an array of the located [webdriver.WebElement](#webdriverwebelement)s. ##[element.findElements](https://github.com/angular/protractor/blob/master/lib/protractor.js#L725) ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise that will be resolved to an array of the located [webdriver.WebElement](#webdriverwebelement)s. ##[element.isElementPresent](https://github.com/angular/protractor/blob/master/lib/protractor.js#L749) ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise that will be resolved with whether an element could be located on the page. ##[element.evaluate](https://github.com/angular/protractor/blob/master/lib/protractor.js#L765) Evaluates the input as if it were on the scope of the current element. ###Params Param | Type | Description --- | --- | --- expression | string | ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise that will resolve to the evaluated expression. The result will be resolved as in {@link 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. ##[Protractor.prototype.findElement](https://github.com/angular/protractor/blob/master/lib/protractor.js#L784) Waits for Angular to finish rendering before searching for elements. ###Returns Type | Description --- | --- &#33;[webdriver.WebElement](#webdriverwebelement) | ##[Protractor.prototype.findElements](https://github.com/angular/protractor/blob/master/lib/protractor.js#L802) Waits for Angular to finish rendering before searching for elements. ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise that will be resolved to an array of the located [webdriver.WebElement](#webdriverwebelement)s. ##[Protractor.prototype.isElementPresent](https://github.com/angular/protractor/blob/master/lib/protractor.js#L827) Tests if an element is present on the page. ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise that will resolve to whether the element is present on the page. ##[Protractor.prototype.addMockModule](https://github.com/angular/protractor/blob/master/lib/protractor.js#L843) 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. ###Params Param | Type | Description --- | --- | --- name | !string | The name of the module to load or override. script | !string&#124;Function | The JavaScript to load the module. varArgs | ...* | Any additional arguments will be provided to the script and may be referenced using the `arguments` object. ##[Protractor.prototype.clearMockModules](https://github.com/angular/protractor/blob/master/lib/protractor.js#L861) Clear the list of registered mock modules. ##[Protractor.prototype.removeMockModule](https://github.com/angular/protractor/blob/master/lib/protractor.js#L870) Remove a registered mock module. ###Params Param | Type | Description --- | --- | --- name | !string | The name of the module to remove. ##[Protractor.prototype.get](https://github.com/angular/protractor/blob/master/lib/protractor.js#L881) See 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. ###Params Param | Type | Description --- | --- | --- destination | string | Destination URL. opt_timeout | number= | Number of seconds to wait for Angular to start. ##[Protractor.prototype.refresh](https://github.com/angular/protractor/blob/master/lib/protractor.js#L949) See 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. ###Params Param | Type | Description --- | --- | --- opt_timeout | number= | Number of seconds to wait for Angular to start. ##[Protractor.prototype.navigate](https://github.com/angular/protractor/blob/master/lib/protractor.js#L972) Mixin navigation methods back into the navigation object so that they are invoked as before, i.e. driver.navigate().refresh() ##[Protractor.prototype.setLocation](https://github.com/angular/protractor/blob/master/lib/protractor.js#L982) Browse to another page using in-page navigation. ###Params Param | Type | Description --- | --- | --- url | string | In page URL using the same syntax as $location.url() ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise that will resolve once page has been changed. ##[Protractor.prototype.getLocationAbsUrl](https://github.com/angular/protractor/blob/master/lib/protractor.js#L1000) Returns the current absolute url from AngularJS. ##[Protractor.prototype.debugger](https://github.com/angular/protractor/blob/master/lib/protractor.js#L1008) Pauses the test and injects some helper functions into the browser, so that debugging may be done in the browser console. This should be used under node in debug mode, i.e. with protractor debug <configuration.js> While in the debugger, commands can be scheduled through webdriver by entering the repl: debug> repl Press Ctrl + C to leave rdebug repl > ptor.findElement(protractor.By.input('user').sendKeys('Laura')); > ptor.debugger(); debug> c This will run the sendKeys command as the next task, then re-enter the debugger. ##[Protractor.prototype.pause](https://github.com/angular/protractor/blob/master/lib/protractor.js#L1043) Beta (unstable) pause function for debugging webdriver tests. Use browser.pause() in your test to enter the protractor debugger from that point in the control flow. Does not require changes to the command line (no need to add 'debug'). ##[ProtractorBy](https://github.com/angular/protractor/blob/master/lib/locators.js#L6) The Protractor Locators. These provide ways of finding elements in Angular applications by binding, model, etc. ##[WebdriverBy.prototype](https://github.com/angular/protractor/blob/master/lib/locators.js#L15) webdriver's By is an enum of locator functions, so we must set it to a prototype before inheriting from it. ##[ProtractorBy.prototype.addLocator](https://github.com/angular/protractor/blob/master/lib/locators.js#L22) #### Use as: by.addLocator(locatorName, functionOrScript) Add a locator to this instance of ProtractorBy. This locator can then be used with element(by.locatorName(args)). ###Example ```html <button ng-click="doAddition()">Go!</button> ``` ```javascript // Add the custom locator. by.addLocator('buttonTextSimple', function(buttonText, opt_parentElement) { // 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(); ``` ###Params Param | Type | Description --- | --- | --- name | string | The name of the new locator. script | Function&#124;string | 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. It should return an array of elements. ##[ProtractorBy.prototype.binding](https://github.com/angular/protractor/blob/master/lib/locators.js#L73) #### Use as: by.binding() Find an element by binding. ###Example ```html <span>{{person.name}}</span> <span ng-bind="person.email"></span> ``` ```javascript 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'); ``` ###Params Param | Type | Description --- | --- | --- bindingDescriptor | string | ###Returns Type | Description --- | --- {findElementsOverride: findElementsOverride, message: string} | ##[ProtractorBy.prototype.exactBinding](https://github.com/angular/protractor/blob/master/lib/locators.js#L102) #### Use as: by.exactBinding() Same as by.binding() except this does not allow for partial matches Find an element by exact binding. ###Params Param | Type | Description --- | --- | --- bindingDescriptor | string | ###Returns Type | Description --- | --- {findElementsOverride: findElementsOverride, message: string} | ##[ProtractorBy.prototype.select](https://github.com/angular/protractor/blob/master/lib/locators.js#L122) **DEPRECATED** Use 'model' instead. ###Example ```html <select ng-model="user" ng-options="user.name for user in users"></select> ``` ```javascript element(by.select('user')); ``` ##[ProtractorBy.prototype.selectedOption](https://github.com/angular/protractor/blob/master/lib/locators.js#L141) ###Example ```html <select ng-model="user" ng-options="user.name for user in users"></select> ``` ```javascript element(by.selectedOption("user")); ``` ##[ProtractorBy.prototype.input](https://github.com/angular/protractor/blob/master/lib/locators.js#L158) **DEPRECATED** Use 'model' instead. ###Example ```html <input ng-model="user" type="text"/> ``` ```javascript element(by.input('user')); ``` ##[ProtractorBy.prototype.model](https://github.com/angular/protractor/blob/master/lib/locators.js#L176) #### Use as: by.model(modelName) Find an element by ng-model expression. ###Example ```html <input type="text" ng-model="person.name"/> ``` ```javascript var input = element(by.model('person.name')); input.sendKeys('123'); expect(input.getAttribute('value')).toBe('Foo123'); ``` ###Params Param | Type | Description --- | --- | --- model | string | ng-model expression. ##[ProtractorBy.prototype.buttonText](https://github.com/angular/protractor/blob/master/lib/locators.js#L200) Find a button by text. ###Example ```html <button>Save</button> ``` ```javascript element(by.buttonText('Save')); ``` ###Params Param | Type | Description --- | --- | --- searchText | string | ###Returns Type | Description --- | --- {findElementsOverride: findElementsOverride, message: string} | ##[ProtractorBy.prototype.partialButtonText](https://github.com/angular/protractor/blob/master/lib/locators.js#L223) Find a button by partial text. ###Example ```html <button>Save my file</button> ``` ```javascript element(by.partialButtonText('Save')); ``` ###Params Param | Type | Description --- | --- | --- searchText | string | ###Returns Type | Description --- | --- {findElementsOverride: findElementsOverride, message: string} | ##[ProtractorBy.prototype.textarea](https://github.com/angular/protractor/blob/master/lib/locators.js#L247) **DEPRECATED** Use 'model' instead. ###Example ```html <textarea ng-model="user"></textarea> ``` ```javascript element(by.textarea('user')); ``` ##[ProtractorBy.prototype.repeater](https://github.com/angular/protractor/blob/master/lib/locators.js#L265) Find elements inside an ng-repeat. ###Example ```html <div ng-repeat="cat in pets"> <span>{{cat.name}}</span> <span>{{cat.age}}</span> </div> ``` ```javascript // 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 rows of the repeater. var rows = element.all(by.repeater('cat in pets')); ``` ##[ProtractorBy.prototype.cssContainingText](https://github.com/angular/protractor/blob/master/lib/locators.js#L344) Find elements by CSS which contain a certain string. ###Example ```html <ul> <li class="pet">Dog</li> <li class="pet">Cat</li> </ul> ``` ```javascript // Returns the DIV for the dog, but not cat. var dog = element(by.cssContainingText('.pet', 'Dog')); ``` ##[webdriver.WebDriver](https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js#47) Creates a new WebDriver client, which provides control over a browser. Every WebDriver command returns a {@code webdriver.promise.Promise} that represents the result of that command. Callbacks may be registered on this object to manipulate the command result or catch an expected error. Any commands scheduled with a callback are considered sub-commands and will execute before the next command in the current frame. For example: <pre><code> var message = []; driver.call(message.push, message, 'a').then(function() { driver.call(message.push, message, 'b'); }); driver.call(message.push, message, 'c'); driver.call(function() { alert('message is abc? ' + (message.join('') == 'abc')); }); </code></pre> ###Params Param | Type | Description --- | --- | --- session | !(webdriver.Session&#124;webdriver.promise.Promise) | Either a known session or a promise that will be resolved to a session. executor | !webdriver.CommandExecutor | The executor to use when sending commands to the browser. opt_flow | webdriver.promise.ControlFlow= | The flow to schedule commands through. Defaults to the active flow object. ##[webdriver.WebDriver.attachToSession](https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js#87) Creates a new WebDriver client for an existing session. ###Params Param | Type | Description --- | --- | --- executor | !webdriver.CommandExecutor | Command executor to use when querying for session details. sessionId | string | ID of the session to attach to. ###Returns Type | Description --- | --- &#33;[webdriver.WebDriver](#webdriverwebdriver) | A new client for the specified session. ##[webdriver.WebDriver.createSession](https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js#102) Creates a new WebDriver session. ###Params Param | Type | Description --- | --- | --- executor | !webdriver.CommandExecutor | The executor to create the new session with. desiredCapabilities | !webdriver.Capabilities | The desired capabilities for the new session. ###Returns Type | Description --- | --- &#33;[webdriver.WebDriver](#webdriverwebdriver) | The driver for the newly created session. ##[webdriver.WebDriver.prototype.controlFlow](https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js#243) ###Returns Type | Description --- | --- !webdriver.promise.ControlFlow | The control flow used by this instance. ##[webdriver.WebDriver.prototype.schedule](https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js#252) Schedules a {@code webdriver.Command} to be executed by this driver's {@code webdriver.CommandExecutor}. ###Params Param | Type | Description --- | --- | --- command | !webdriver.Command | The command to schedule. description | string | A description of the command for debugging. ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise that will be resolved with the command result. ##[webdriver.WebDriver.prototype.getSession](https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js#304) ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise for this client's session. ##[webdriver.WebDriver.prototype.getCapabilities](https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js#312) ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise that will resolve with the this instance's capabilities. ##[webdriver.WebDriver.prototype.quit](https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js#323) Schedules a command to quit the current session. After calling quit, this instance will be invalidated and may no longer be used to issue commands against the browser. ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise that will be resolved when the command has completed. ##[webdriver.WebDriver.prototype.actions](https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js#342) Creates a new action sequence using this driver. The sequence will not be scheduled for execution until {@link webdriver.ActionSequence#perform} is called. Example: <pre><code> driver.actions(). mouseDown(element1). mouseMove(element2). mouseUp(). perform(); </code></pre> ###Returns Type | Description --- | --- !webdriver.ActionSequence | A new action sequence for this instance. ##[webdriver.WebDriver.prototype.executeScript](https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js#360) Schedules a command to execute JavaScript in the context of the currently selected frame or window. The script fragment will be executed as the body of an anonymous function. If the script is provided as a function object, that function will be converted to a string for injection into the target window. Any arguments provided in addition to the script will be included as script arguments and may be referenced using the {@code arguments} object. Arguments may be a boolean, number, string, or {@code webdriver.WebElement}. Arrays and objects may also be used as script arguments as long as each item adheres to the types previously mentioned. The script may refer to any variables accessible from the current window. Furthermore, the script will execute in the window's context, thus {@code document} may be used to refer to the current document. Any local variables will not be available once the script has finished executing, though global variables will persist. If the script has a return value (i.e. if the script contains a return statement), then the following steps will be taken for resolving this functions return value: <ul> <li>For a HTML element, the value will resolve to a {@code webdriver.WebElement}</li> <li>Null and undefined return values will resolve to null</li> <li>Booleans, numbers, and strings will resolve as is</li> <li>Functions will resolve to their string representation</li> <li>For arrays and objects, each member item will be converted according to the rules above</li> </ul> ###Params Param | Type | Description --- | --- | --- script | !(string&#124;Function) | The script to execute. var_args | ...* | The arguments to pass to the script. ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise that will resolve to the scripts return value. ##[webdriver.WebDriver.prototype.executeAsyncScript](https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js#409) Schedules a command to execute asynchronous JavaScript in the context of the currently selected frame or window. The script fragment will be executed as the body of an anonymous function. If the script is provided as a function object, that function will be converted to a string for injection into the target window. Any arguments provided in addition to the script will be included as script arguments and may be referenced using the {@code arguments} object. Arguments may be a boolean, number, string, or {@code webdriver.WebElement}. Arrays and objects may also be used as script arguments as long as each item adheres to the types previously mentioned. Unlike executing synchronous JavaScript with {@code webdriver.WebDriver.prototype.executeScript}, scripts executed with this function must explicitly signal they are finished by invoking the provided callback. This callback will always be injected into the executed function as the last argument, and thus may be referenced with {@code arguments[arguments.length - 1]}. The following steps will be taken for resolving this functions return value against the first argument to the script's callback function: <ul> <li>For a HTML element, the value will resolve to a {@code webdriver.WebElement}</li> <li>Null and undefined return values will resolve to null</li> <li>Booleans, numbers, and strings will resolve as is</li> <li>Functions will resolve to their string representation</li> <li>For arrays and objects, each member item will be converted according to the rules above</li> </ul> Example #1: Performing a sleep that is synchronized with the currently selected window: <code><pre> var start = new Date().getTime(); driver.executeAsyncScript( 'window.setTimeout(arguments[arguments.length - 1], 500);'). then(function() { console.log('Elapsed time: ' + (new Date().getTime() - start) + ' ms'); }); </pre></code> Example #2: Synchronizing a test with an AJAX application: <code><pre> var button = driver.findElement(By.id('compose-button')); button.click(); driver.executeAsyncScript( 'var callback = arguments[arguments.length - 1];' + 'mailClient.getComposeWindowWidget().onload(callback);'); driver.switchTo().frame('composeWidget'); driver.findElement(By.id('to')).sendKEys('dog@example.com'); </pre></code> Example #3: Injecting a XMLHttpRequest and waiting for the result. In this example, the inject script is specified with a function literal. When using this format, the function is converted to a string for injection, so it should not reference any symbols not defined in the scope of the page under test. <code><pre> driver.executeAsyncScript(function() { var callback = arguments[arguments.length - 1]; var xhr = new XMLHttpRequest(); xhr.open("GET", "/resource/data.json", true); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { callback(xhr.resposneText); } } xhr.send(''); }).then(function(str) { console.log(JSON.parse(str)['food']); }); </pre></code> ###Params Param | Type | Description --- | --- | --- script | !(string&#124;Function) | The script to execute. var_args | ...* | The arguments to pass to the script. ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise that will resolve to the scripts return value. ##[webdriver.WebDriver.prototype.call](https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js#500) Schedules a command to execute a custom function. ###Params Param | Type | Description --- | --- | --- fn | !Function | The function to execute. opt_scope | Object= | The object in whose scope to execute the function. var_args | ...* | Any arguments to pass to the function. ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise that will be resolved with the function's result. ##[webdriver.WebDriver.prototype.wait](https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js#519) Schedules a command to wait for a condition to hold, as defined by some user supplied function. If any errors occur while evaluating the wait, they will be allowed to propagate. ###Params Param | Type | Description --- | --- | --- fn | function():boolean | The function to evaluate as a wait condition. timeout | number | How long to wait for the condition to be true. opt_message | string= | An optional message to use if the wait times out. ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise that will be resolved when the wait condition has been satisfied. ##[webdriver.WebDriver.prototype.sleep](https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js#535) Schedules a command to make the driver sleep for the given amount of time. ###Params Param | Type | Description --- | --- | --- ms | number | The amount of time, in milliseconds, to sleep. ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise that will be resolved when the sleep has finished. ##[webdriver.WebDriver.prototype.getWindowHandle](https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js#546) Schedules a command to retrieve they current window handle. ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise that will be resolved with the current window handle. ##[webdriver.WebDriver.prototype.getAllWindowHandles](https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js#558) Schedules a command to retrieve the current list of available window handles. ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise that will be resolved with an array of window handles. ##[webdriver.WebDriver.prototype.getPageSource](https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js#570) Schedules a command to retrieve the current page's source. The page source returned is a representation of the underlying DOM: do not expect it to be formatted or escaped in the same way as the response sent from the web server. ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise that will be resolved with the current page source. ##[webdriver.WebDriver.prototype.close](https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js#585) Schedules a command to close the current window. ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise that will be resolved when this command has completed. ##[webdriver.WebDriver.prototype.get](https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js#596) Schedules a command to navigate to the given URL. ###Params Param | Type | Description --- | --- | --- url | string | The fully qualified URL to open. ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise that will be resolved when the document has finished loading. ##[webdriver.WebDriver.prototype.getCurrentUrl](https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js#607) Schedules a command to retrieve the URL of the current page. ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise that will be resolved with the current URL. ##[webdriver.WebDriver.prototype.getTitle](https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js#619) Schedules a command to retrieve the current page's title. ###Returns Type | Description --- | --- !webdriver.promise.Promise | A promise that will be resolved with the current page's title. ##[webdriver.WebDriver.prototype.findElement](https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js#630) Schedule a command to find an element on the page. If the element cannot be found, a {@link bot.ErrorCode.NO_SUCH_ELEMENT} result will be returned by the driver. Unlike other commands, this error cannot be suppressed. In other words, scheduling a command to find an element doubles as an assert that the element is present on the page. To test whether an element is present on the page, use {@link #isElementPresent} instead. <p>The search criteria for an element may be defined using one of the factories in the {@link webdriver.By} namespace, or as a short-hand {@link webdriver.By.Hash} object. For example, the following two statements are equivalent: <code><pre> var e1 = driver.findElement(By.id('foo'))