"use strict"; var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; var selenium_webdriver_1 = require("selenium-webdriver"); var clientSideScripts = require('./clientsidescripts'); // Explicitly define webdriver.By. var WebdriverBy = (function () { function WebdriverBy() { this.className = selenium_webdriver_1.By.className; this.css = selenium_webdriver_1.By.css; this.id = selenium_webdriver_1.By.id; this.linkText = selenium_webdriver_1.By.linkText; this.js = selenium_webdriver_1.By.js; this.name = selenium_webdriver_1.By.name; this.partialLinkText = selenium_webdriver_1.By.partialLinkText; this.tagName = selenium_webdriver_1.By.tagName; this.xpath = selenium_webdriver_1.By.xpath; } return WebdriverBy; }()); exports.WebdriverBy = WebdriverBy; /** * The Protractor Locators. These provide ways of finding elements in * Angular applications by binding, model, etc. * * @alias by * @extends {webdriver.By} */ var ProtractorBy = (function (_super) { __extends(ProtractorBy, _super); function ProtractorBy() { return _super.apply(this, arguments) || this; } /** * Add a locator to this instance of ProtractorBy. This locator can then be * used with element(by.locatorName(args)). * * @view * * * @example * // 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(); * * @alias by.addLocator(locatorName, functionOrScript) * @param {string} name The name of the new locator. * @param {Function|string} 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. */ ProtractorBy.prototype.addLocator = function (name, script) { this[name] = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var locatorArguments = args; return { findElementsOverride: function (driver, using, rootSelector) { var findElementArguments = [script]; for (var i = 0; i < locatorArguments.length; i++) { findElementArguments.push(locatorArguments[i]); } findElementArguments.push(using); findElementArguments.push(rootSelector); return driver.findElements(selenium_webdriver_1.By.js.apply(selenium_webdriver_1.By, findElementArguments)); }, toString: function () { return 'by.' + name + '("' + Array.prototype.join.call(locatorArguments, '", "') + '")'; } }; }; }; ; /** * 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. * * @view * {{person.name}} * * * @example * 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}}')); * * @param {string} bindingDescriptor * @returns {Locator} location strategy */ ProtractorBy.prototype.binding = function (bindingDescriptor) { return { findElementsOverride: function (driver, using, rootSelector) { return driver.findElements(selenium_webdriver_1.By.js(clientSideScripts.findBindings, bindingDescriptor, false, using, rootSelector)); }, toString: function () { return 'by.binding("' + bindingDescriptor + '")'; } }; }; ; /** * Find an element by exact binding. * * @view * {{ person.name }} * * {{person_phone|uppercase}} * * @example * 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); * * @param {string} bindingDescriptor * @returns {Locator} location strategy */ ProtractorBy.prototype.exactBinding = function (bindingDescriptor) { return { findElementsOverride: function (driver, using, rootSelector) { return driver.findElements(selenium_webdriver_1.By.js(clientSideScripts.findBindings, bindingDescriptor, true, using, rootSelector)); }, toString: function () { return 'by.exactBinding("' + bindingDescriptor + '")'; } }; }; ; /** * Find an element by ng-model expression. * * @alias by.model(modelName) * @view * * * @example * var input = element(by.model('person.name')); * input.sendKeys('123'); * expect(input.getAttribute('value')).toBe('Foo123'); * * @param {string} model ng-model expression. * @returns {Locator} location strategy */ ProtractorBy.prototype.model = function (model) { return { findElementsOverride: function (driver, using, rootSelector) { return driver.findElements(selenium_webdriver_1.By.js(clientSideScripts.findByModel, model, using, rootSelector)); }, toString: function () { return 'by.model("' + model + '")'; } }; }; ; /** * Find a button by text. * * @view * * * @example * element(by.buttonText('Save')); * * @param {string} searchText * @returns {Locator} location strategy */ ProtractorBy.prototype.buttonText = function (searchText) { return { findElementsOverride: function (driver, using, rootSelector) { return driver.findElements(selenium_webdriver_1.By.js(clientSideScripts.findByButtonText, searchText, using, rootSelector)); }, toString: function () { return 'by.buttonText("' + searchText + '")'; } }; }; ; /** * Find a button by partial text. * * @view * * * @example * element(by.partialButtonText('Save')); * * @param {string} searchText * @returns {Locator} location strategy */ ProtractorBy.prototype.partialButtonText = function (searchText) { return { findElementsOverride: function (driver, using, rootSelector) { return driver.findElements(selenium_webdriver_1.By.js(clientSideScripts.findByPartialButtonText, searchText, using, rootSelector)); }, toString: function () { return 'by.partialButtonText("' + searchText + '")'; } }; }; ; // Generate either by.repeater or by.exactRepeater ProtractorBy.prototype.byRepeaterInner = function (exact, repeatDescriptor) { var name = 'by.' + (exact ? 'exactR' : 'r') + 'epeater'; return { findElementsOverride: function (driver, using, rootSelector) { return driver.findElements(selenium_webdriver_1.By.js(clientSideScripts.findAllRepeaterRows, repeatDescriptor, exact, using, rootSelector)); }, toString: function () { return name + '("' + repeatDescriptor + '")'; }, row: function (index) { return { findElementsOverride: function (driver, using, rootSelector) { return driver.findElements(selenium_webdriver_1.By.js(clientSideScripts.findRepeaterRows, repeatDescriptor, exact, index, using, rootSelector)); }, toString: function () { return name + '(' + repeatDescriptor + '").row("' + index + '")"'; }, column: function (binding) { return { findElementsOverride: function (driver, using, rootSelector) { return driver.findElements(selenium_webdriver_1.By.js(clientSideScripts.findRepeaterElement, repeatDescriptor, exact, index, binding, using, rootSelector)); }, toString: function () { return name + '("' + repeatDescriptor + '").row("' + index + '").column("' + binding + '")'; } }; } }; }, column: function (binding) { return { findElementsOverride: function (driver, using, rootSelector) { return driver.findElements(selenium_webdriver_1.By.js(clientSideScripts.findRepeaterColumn, repeatDescriptor, exact, binding, using, rootSelector)); }, toString: function () { return name + '("' + repeatDescriptor + '").column("' + binding + '")'; }, row: function (index) { return { findElementsOverride: function (driver, using, rootSelector) { return driver.findElements(selenium_webdriver_1.By.js(clientSideScripts.findRepeaterElement, repeatDescriptor, exact, index, binding, using, rootSelector)); }, toString: function () { return name + '("' + repeatDescriptor + '").column("' + binding + '").row("' + index + '")'; } }; } }; } }; }; /** * Find elements inside an ng-repeat. * * @view *
{{book.blurb}}
*