bitfront-library
Version:
Angular CLI project with components and classes used by other Angular projects of the BIT foundation.
783 lines (782 loc) • 35.2 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Base = void 0;
var protractor_1 = require("protractor");
/**
* Clase base con operaciones para poder acceder via protractor a los elementos del DOM. Todas las clase PO deben extender esta clase
*/
var Base = /** @class */ (function () {
function Base() {
}
/***Funciones de alto nivel *******/
/** Retornará el elemento (ElementFinder) que coincida con el id especificado por parámetro.
* @param id identificador del elemento
*/
Base.prototype.getElementById = function (id) {
return protractor_1.element(protractor_1.by.id(id));
};
/** Retornará el elemento (ElementFinder) que coincida con el tagName especificado por parámetro.
* @param tagName nombre del tag que representa al elemento a recuperar
*/
Base.prototype.getElementByTagName = function (tagName) {
return protractor_1.element(protractor_1.by.tagName(tagName));
};
/** Retornará el elemento (ElementFinder) que corresponda en función de lo que diga su HTML embebido.
* En estos momentos solo retorna un el input asociado a un Calendar si el elemento asociado al id especificado es un p-calendar
* o el input directamente asociado al id especificado.
* @param html código html que está dentro del elemento y nos dirá que es
* @param id identificador del elemento
*/
Base.prototype.getElementByHtml = function (html, id) {
if (html.indexOf("input") != -1) {
//es un p-calendar
this.log(id + " es un p-calendar");
return this.getInputCalendar(id);
}
else {
this.log(id + " es un input text");
return this.getElementById(id);
}
};
/*** Funciones para acceder elementos de formularios *****/
/**
* Recupera el elemento DropDown que tenga el id especificado por parámetro
* @param id identificador del dropDown
*/
Base.prototype.getDropDown = function (id) {
return this.getElementById(id)
.all(protractor_1.by.css("div"))
.first();
// otras via pero me gustan menos return element.all(by.tagName("p-dropdown div")).first(); //element(by.id(id)).element(by.css('div.ui-dropdown'))
};
/**
* Recupera la lista de opciones de un dropDown. Básicamente recupera la lista de <li>
* Es necesario que quien invoque a este método previamente haga click() sobre el dropDown
* @param dropDown elemento dropDown de tipo ElementFinder
*/
Base.prototype.getDropDownOptions = function (dropDown) {
return dropDown.all(protractor_1.by.tagName("li")); //otra via pero me gusta menos by.css(".ui-dropdown-item")
};
/**
* Recupera el valor seleccionado en el dropDown
* @param id identificador del dropDown
*/
Base.prototype.getDropDownValue = function (id) {
return this.getDropDown(id)
.element(protractor_1.by.tagName("label"))
.getText();
};
/** Retornará el botón que contenga el texto indicado por parámetro
* @param textButton texto del botón
*/
Base.prototype.getButton = function (textButton) {
return protractor_1.element(protractor_1.by.partialButtonText(textButton));
};
/** Retornará el botón dentro de una ventana modal y que contenga el texto indicado por parámetro
* @param textButton texto del botón
*/
Base.prototype.getDialogButton = function (tagName, textButton) {
return protractor_1.element(protractor_1.by.cssContainingText(tagName + " button", textButton));
};
/** Retornará todos los botones que contengan el texto indicado por parámetro
* @param textButton texto del botón
*/
Base.prototype.getAllButtons = function (textButton) {
return protractor_1.element.all(protractor_1.by.partialButtonText(textButton));
};
/** Retornará el botón que contenga el texto Cerca*/
Base.prototype.getSearchButton = function () {
return this.getButton("Cerca"); // element(by.partialButtonText("Cerca"));
};
/** Retornará el botón que contenga el texto Desa*/
Base.prototype.getSaveButton = function () {
return this.getButton("Desa");
};
/** Retornará el botón que contenga el texto Elimina*/
Base.prototype.getDeleteButton = function () {
return this.getButton("Elimina");
};
/** Retornará el botón que esté visible en caso de que haya más de uno */
Base.prototype.getVisibleButton = function (textButton) {
var elemento = null;
return this.getAllButtons(textButton)
.each(function (element) {
element.isDisplayed().then(function (displayed) {
if (displayed) {
elemento = element;
}
});
})
.then(function () {
return new protractor_1.promise.Promise(function (resolve, reject) { return resolve(elemento); });
});
};
/** Recupera el inputText que tenga asociado el campo p-calendar con id especificado.
* @param id identificador del elemento
*/
Base.prototype.getInputCalendar = function (id) {
return this.getElementById(id).element(protractor_1.by.tagName("input"));
};
/** Retorna el input asociado al id especificado
* @param id identificador del elemento
*/
Base.prototype.getInputText = function (id) {
return this.getElementById(id);
};
/** Recupera el elemento InputSwitch que tenga el id especificado por parámetro
* @param id identificador del dropDown
*/
Base.prototype.getInputSwitch = function (id) {
return this.getElementById(id)
.all(protractor_1.by.css("div"))
.first();
};
/** Recupera el elemento Editor que tenga el id especificado por parámetro
* @param id identificador del editor
*/
Base.prototype.getBitEditor = function (id) {
return this.getElementById(id)
.all(protractor_1.by.className("ql-editor"))
.first();
};
Base.prototype.getCheckBox = function (id) {
return this.getElementById(id)
.all(protractor_1.by.tagName("div.ui-chkbox-box"))
.first();
};
Base.prototype.getSpanByText = function (text) {
return protractor_1.element(protractor_1.by.cssContainingText("span", text));
};
Base.prototype.getDivByText = function (text) {
return protractor_1.element(protractor_1.by.cssContainingText("div", text));
};
/** Recupera todos los acordeones de la página*/
Base.prototype.getAllAccordionTabs = function () {
return protractor_1.element.all(protractor_1.by.css("p-accordiontab div:first-child"));
};
/** Recupera todos los acordeones de la página que cuelgan de un tag concreto
* @param tagName nombre del tag
*/
Base.prototype.getAllAcordionTabsFromTagName = function (tagName) {
return this.getElementByTagName(tagName).all(protractor_1.by.css("p-accordiontab div:first-child"));
};
/** Recupera el diágolo que cuelga de un tag concreto
* @param tagName nombre del tag
*/
Base.prototype.getDialogFromTagName = function (tagName) {
return this.getElementByTagName(tagName).element(protractor_1.by.tagName("p-dialog div:first-child"));
};
/** Recupera el texto que tenga el elemento HTML asociado.
* @param id identificador del elemento
*/
Base.prototype.getTextFromInput = function (id) {
return this.getElementById(id).getText();
};
/** Retorna el contenido del atributo value que tenga el elemento p-calendar con id especificado
* @param id
*/
Base.prototype.getAttributeDateFromCalendar = function (id) {
return this.getElementById(id)
.element(protractor_1.by.tagName("input"))
.getAttribute("value");
};
Base.prototype.getCheckBoxValue = function (id) {
return this.getElementById(id)
.element(protractor_1.by.css("span.ui-chkbox-icon"))
.getAttribute("class")
.then(function (c) {
return new protractor_1.promise.Promise(function (resolve, reject) {
return resolve(c.indexOf("pi-check") == -1 ? "false" : "true");
});
});
};
/** Retorna el contenido del atributo value que tenga el elemento HTML con id especificado
* @param id identificador del elemento
*/
Base.prototype.getAttributeValue = function (id) {
return this.getElementById(id).getAttribute("value");
};
/** Retorna el valor del editor de HTML con id especificado
* @param id
*/
Base.prototype.getBitEditorValue = function (id) {
return this.getBitEditor(id).getAttribute("innerHTML");
};
/** Retorna la lista de opciones del elemento p-dropdown que contengan el texto especificado por parámetro
* @param dropDown elemento p-dropdown del que queremos recueperar las opciones
* @param option texto del desplegable que nos interesa
*/
Base.prototype.getSelectOptionsByText = function (dropDown, option) {
dropDown.click(); //necesario para poder mostrar todos los li>span
var allOptions = dropDown.all(protractor_1.by.cssContainingText("span", option));
return allOptions.filter(function (elem) {
return elem.getText().then(function (text) {
return text === option;
});
});
};
/**
* Retorna la lista de opciones para un elemento select html que contengan el texto especificado por parámetro
* @param select elemento select html del que queremos recuperar las opciones
* @param text texto del desplegable que nos interesa
*/
Base.prototype.getSelectHTMLOptionsByText = function (select, text) {
var allOptions = select.all(protractor_1.by.cssContainingText("option", text));
return allOptions.filter(function (elem) {
return elem.getText().then(function (textElem) {
return textElem === text;
});
});
};
/**
* Retorna una promesa con un array de string conteniendo el texto de los inputs en readonly especificados
* @param inputs lista de inputs en readonly de los que extraer el texto
*/
Base.prototype.getFormReadOnlyValues = function (inputs) {
var _this = this;
return protractor_1.protractor.promise.all(inputs.map(function (input) { return _this.getTextFromInput(input); })); //.then((values) => { return values });
};
/**
* Retorna una promesa con un array de string conteniendo los valores de los inputs especificados
* @param inputs lista de inputs de los que extraer el contenido
*/
Base.prototype.getFormValues = function (inputs) {
var _this = this;
return protractor_1.protractor.promise.all(inputs.map(function (input) { return _this.getInputValue(input); }));
};
/**
* Setea un formulario dando a cada input del array inputs el valor del array values que esté en la misma posición
* inputs[i].setValue = values[i]
* @param inputs lista de inputs a los que pasar valor
* @param values lista de valores a especificar
*/
Base.prototype.setFormValues = function (inputs, values) {
var _this = this;
var i = 0;
var promises = inputs.map(function (input) { return _this.setInputValue(input, values[i++], true); });
return protractor_1.protractor.promise.all(promises).then(function (values) {
return values;
});
};
Base.prototype.setFormNewValues = function (inputs, values) {
var _this = this;
var i = 0;
var promises = inputs.map(function (input) { return _this.setInputValue(input, values[i++], false); });
return protractor_1.protractor.promise.all(promises).then(function (values) {
return values;
});
};
/**
* Recupera el valor del elemento con idenficador especificado por parámetro
* @param input identificador del elemento del que queremos el valor
*/
Base.prototype.getInputValue = function (input) {
var _this = this;
return this.getElementById(input)
.getAttribute("innerHTML")
.then(function (html) {
//this.log(`${input} tiene el valor ${html}`); para emergencias
if (html.indexOf("dropdown") != -1) {
//es un dropdown
_this.log(input + " es un p-dropdown");
return _this.getDropDownValue(input);
}
else if (html.indexOf("editor ui-widget") != -1) {
//es un BitEditorComponent
_this.log(input + " es un BitEditorComponent");
return _this.getBitEditorValue(input);
}
else if (html.indexOf("ui-chkbox") != -1) {
//es un checkbox
_this.log(input + " es un checkbox");
var valor = _this.getCheckBoxValue(input);
_this.log(input + " es un checkbox con valor =>" + valor);
return valor;
}
else if (html.indexOf("ui-inputswitch") != -1) {
_this.log(input + " es un p-switch");
// si existe ui-inputswitch-checked = true, si no = false
return html.indexOf("ui-inputswitch-checked") != -1 ? "on" : "off";
}
else if (html.indexOf("input") != -1) {
//es un p-calendar
_this.log(input + " es un p-calendar");
return _this.getAttributeDateFromCalendar(input);
}
else if (html) {
_this.log(input + " no es ningun input");
return html;
}
else {
_this.log(input + " es un input text");
return _this.getAttributeValue(input);
}
});
};
/**
* Setea el valor especificado en el elemento con identificador indicado por parámetro. De momento
* la función está soportada para dropdowns e input text
* @param input identificador del elemento del que queremos setear un valor
* @param value valor a setear en el elemento
*/
Base.prototype.setInputValue = function (input, value, clear) {
var _this = this;
return this.getElementById(input)
.getAttribute("innerHTML")
.then(function (html) {
if (html.indexOf("dropdown") != -1) {
//es un dropdown
_this.log(input + " es un dropdown y le seteamos " + value);
var dd = _this.getDropDown(input);
return _this.getSelectOptionsByText(dd, value)
.first()
.click();
}
else if (html.indexOf("editor ui-widget") != -1) {
//es un BitEditorComponent
_this.log(input + " es un BitEditor y le seteamos " + value);
var editorElement = _this.getBitEditor(input);
_this.setBitEditorValue(editorElement, value);
}
else if (html.indexOf("ui-chkbox") != -1) {
//es un checkbox
_this.getCheckBoxValue(input).then(function (checked) {
_this.log(input + " es un checkbox con checked=>" + checked);
if (checked != value) {
_this.getCheckBox(input).click();
}
});
}
else if (html.indexOf("ui-inputswitch") != -1) {
// es un p-switch
_this.getInputValue(input).then(function (isOn) {
_this.log(input + " es un switch con activado=>" + isOn);
if (isOn != value) {
_this.getInputSwitch(input).click();
}
});
}
else {
var element_1 = _this.getElementByHtml(html, input);
if (value != null && value.length > 0) {
// si el valor tiene algo
_this.log(input + " le seteamos " + value);
if (clear) {
_this.log(input + " y borramos el campo");
// el .clear() de selenium ha dejado de funcionar en ciertos campos,
// hay que hacerlo más artesano (Seleccionar todo y borrar)
//element.clear();
element_1.sendKeys(protractor_1.Key.chord(protractor_1.Key.CONTROL, "a", protractor_1.Key.DELETE));
}
return element_1.sendKeys(value);
}
else {
//si no simplemente borramos el campo
if (clear) {
_this.log(input + " solo borramos el campo sin setear una mierda");
return element_1.clear();
}
}
}
});
};
/**
* Setea el valor especificado en el elemento BitEditor pasado por parámetro.
* @param element Elemento localizado que se correponde con un BitEditor
* @param value valor a setear
*/
Base.prototype.setBitEditorValue = function (element, value) {
function setInnerHTML(arg1, arg2) {
console.log("setInnerHTML => " + arg2);
// if (arg1 != null) {
arg1.innerHTML = arg2;
// }
}
return protractor_1.browser.executeScript(setInnerHTML, element, value);
};
/*
* Pulsa un botón. ESe comprueba primero que el botón es visible.
*/
Base.prototype.clickVisibleButton = function (textButton) {
var button = this.getVisibleButton(textButton);
button.then(function (r) { return r.click(); });
return button;
};
/**
* Pulsa la pestaña con el titulo pasado por parámetro.
*/
Base.prototype.clickTabByTitle = function (title) {
protractor_1.element
.all(protractor_1.by.css(".ui-tabview-title"))
.filter(function (elem, index) {
return elem.getText().then(function (text) {
return text === title;
});
})
.first()
.click();
};
/**
* Pulsa la pestaña con el índice (posición) pasado por parámetro.
*/
Base.prototype.clickTabByIndex = function (indice) {
protractor_1.element
.all(protractor_1.by.css(".ui-tabview-title"))
.filter(function (elem, index) {
return index === indice;
})
.first()
.click();
};
/**
* Selecciona una fecha dentro de un popup de un date picker. Es necesario cuando no se puede hacer un setter directamente
* del campo porque esta deshabilido y solo se puede cambiar clickando en el calendario.
*/
Base.prototype.chooseDatePickerDate = function (fieldName, day, month, year) {
this.log("chooseDatePickerDate of field " + fieldName + " to " + day + "-" + month + "-" + year);
this.getInputText(fieldName).click();
// element.all(by.cssContainingText("select.ui-datepicker-month option", "marzo")).first().click();
protractor_1.element
.all(protractor_1.by.css("select.ui-datepicker-month option"))
.get(month)
.click();
protractor_1.element
.all(protractor_1.by.cssContainingText("select.ui-datepicker-year option", "" + year))
.first()
.click();
//element.all(by.css("table.ui-datepicker-calendar td.ng-star-inserted:not(.ui-datepicker-other-month)")).get(day-1).click();
protractor_1.element
.all(protractor_1.by.css("table.ui-datepicker-calendar td:not(.ui-state-disabled) a"))
.get(day - 1)
.click();
// Lo siguinte falla si , por ejemplo, el dia es 1 y se encuentra con anterioridad el dia 31 ya que 31 contiene el numero 1
// element.all(by.cssContainingText("table.ui-datepicker-calendar a", ''+day)).first().click();
};
/**
* Sube un fichero con el nombre y indice (en caso de múltiples ficheros) pasado por parámetro
* El fichero se encuentra en la carpeta raiz de los tests (e2e).
*/
Base.prototype.uploadFile = function (filename, index) {
if (filename === void 0) { filename = "protractor.png"; }
if (index === void 0) { index = 0; }
var path = require("path");
var absolutePath = path.resolve(Base.path, filename);
var fileElem = protractor_1.element.all(protractor_1.by.css('input[type="file"]')).get(index);
// Unhide file input
protractor_1.browser.executeScript("arguments[0].style.visibility = 'visible'; arguments[0].style.height = '1px'; arguments[0].style.width = '1px'; arguments[0].style.opacity = 1", fileElem.getWebElement());
fileElem.sendKeys(absolutePath);
// take a breath
protractor_1.browser.driver.sleep(100);
this.getButton("Carrega").click();
};
/*** Funciones para acceder a listas de cosas *****/
/** Retornará las filas visibles (no hidden) de la tabla en la página. Solo usar cuando en la página hay una sola tabla. Típico de filtro + listado*/
Base.prototype.getTableRows = function () {
return protractor_1.element.all(protractor_1.by.tagName("table tbody tr")).filter(function (element) {
return element.isDisplayed().then(function (v) {
return v;
});
});
};
/** Retornará las filas visibles (no hidden) de una tabla que forme parte del tag especificado por parámetro
* @param tagName nombre del tag que contiene la tabla que nos interesa
*/
Base.prototype.getTableRowsByTagName = function (tagName) {
return protractor_1.element(protractor_1.by.tagName(tagName))
.all(protractor_1.by.tagName("table tbody tr:not(.ui-datatable-emptymessage-row)"))
.filter(function (element) {
return element.isDisplayed().then(function (v) {
return v;
});
});
};
/** Retornará las filas visibles (no hidden) de una tabla que forme parte del tag especificado por parámetro y que además tengan aplicada la clase específica
* @param tagName nombre del tag que contiene la tabla que nos interesa
* @param selector selector css a aplicar
*/
Base.prototype.getTableRowsByTagNameAndSelector = function (tagName, selector) {
return protractor_1.element(protractor_1.by.tagName(tagName))
.all(protractor_1.by.css(selector))
.filter(function (element) {
return element.isDisplayed().then(function (v) {
return v;
});
});
};
/** Retornará el indice de la fila dentro de la tabla con el tag especificado en el que coincida el valor de la columna con el indice y valor pasado por parámetro
* @param tagName nombre del tag que contiene la tabla que nos interesa
* @param index indice de la columna en la que se busca el valor
* @param value valor de la celda cuya fila se quiere buscar
*/
Base.prototype.getTableRowIndexByCellIndexValue = function (tagName, index, value) {
var indice = -1;
return protractor_1.element(protractor_1.by.tagName(tagName))
.all(protractor_1.by.tagName("table tbody tr"))
.each(function (element, indexRow) {
element.all(protractor_1.by.css("td:nth-child(" + (index + 1) + ") span")).each(function (elementCell, indexCell) {
elementCell.getAttribute("innerHTML").then(function (html) {
if (html == value && indice == -1)
indice = indexRow;
});
});
})
.then(function () {
return new protractor_1.promise.Promise(function (resolve, reject) { return resolve(indice); });
});
};
/**
* Elimina la fila en la posicion especificad y de la tabla con el tag especificado.
* Utilizado en los listados donde la primera columna es un checkbox para seleccionar la fila a eliminar.
* @param tagName nombre del tag que contiene la tabla que nos interesa
* @param index indice de la fila a eliminar
*/
Base.prototype.deleteTableRowByIndex = function (tagName, index) {
this.getTableRowsByTagName(tagName)
.get(index)
.all(protractor_1.by.css("div.ui-chkbox-box"))
.click();
// NOTA es posible que algunos formularios tengan mas de un boton Elimina y haga falta indicar que boton Elimina se pulsa
this.getAllButtons("Elimina")
.last()
.click();
this.acceptAlert();
};
/**
* Pulsa la fila de una tabla localizándola segun el indice y valor de columna pasados por parámetros.
* @param tagName nombre del tag que contiene la tabla que nos interesa
* @param index indice de la columna a buscar para saber la posición de la fila a eliminar
* @param value valor de la columna a buscar para saber la posición de la fila a eliminar
*/
Base.prototype.clickTableRowByCellIndexValue = function (tagName, index, value) {
var indice = this.getTableRowIndexByCellIndexValue(tagName, index, value);
expect(indice).toBeGreaterThan(-1);
this.getTableRowsByTagName(tagName)
.get(indice)
.click();
return indice;
};
/** Retornará una promesa con el número de elementos que estén visibles en la lista especificada
* @param list lista de elementos a analizar
*/
Base.prototype.getCountVisibleElements = function (list) {
return list
.filter(function (element) {
return element.isDisplayed().then(function (v) {
return v;
});
})
.count();
/* forma artesanal a modo de aprender :-)
let countVisibles: number = 0;
return list
.each(element => {
element.isDisplayed().then(v => {if (v) countVisibles++;}); //vamos anotando los visibles
})
.then(() => {
this.log(`List has ${countVisibles} visible elements`);
return new promise.Promise((resolve, reject) => resolve(countVisibles)); //retornamos una promesa con los visibles
});
*/
};
/**
* Retorna una promesa con true si todos los elementos de la lsita contienen el texto esperado y false en caso contrario
* @param list ElementArrayFinder con la lista de elementos del dom a analizar
* @param text texto que deberían contener todos los elementos del dom especificados
*/
Base.prototype.allElementsContainingText = function (list, text) {
var _this = this;
var contain = true; //asumimos que se cumple
var count = 0;
return list
.each(function (element) {
count++;
element.getText().then(function (elementText) {
if (!elementText.includes(text)) {
_this.log("texto que no cumple " + elementText);
contain = false;
}
});
})
.then(function () {
_this.log("elementos analizados totales " + count);
return new protractor_1.promise.Promise(function (resolve, reject) { return resolve(contain); }); //retornamos una promesa con el resultado
});
};
/*** Funciones varias *****/
Base.prototype.expectIsPresent = function (element, error) {
if (error === void 0) { error = null; }
element.isPresent().then(function (e) {
expect(e).toBeTruthy((error ? error : "element") + " should be present");
});
};
Base.prototype.expectIsNotPresent = function (element, error) {
if (error === void 0) { error = null; }
element.isPresent().then(function (e) {
expect(e).toBeFalsy((error ? error : "element") + " should not be present");
});
};
Base.prototype.expectVisibleButtonIsPresent = function (textButton) {
this.getVisibleButton(textButton).then(function (r) {
expect(r).toBeDefined("Element " + textButton + " should be present");
});
};
Base.prototype.expectTabIsActive = function (tabs) {
for (var _i = 0, tabs_1 = tabs; _i < tabs_1.length; _i++) {
var tab = tabs_1[_i];
expect(protractor_1.element(protractor_1.by.xpath("//li[contains(@class, 'ui-state-active')][.//span[contains(text(), '" + tab + "')]]")).isPresent()).toBeTruthy();
}
};
Base.prototype.expectTabIsEnabled = function (tabs) {
for (var _i = 0, tabs_2 = tabs; _i < tabs_2.length; _i++) {
var tab = tabs_2[_i];
expect(protractor_1.element(protractor_1.by.xpath("//li[contains(@class, 'ui-state-default')][.//span[contains(text(), '" + tab + "')]]")).isPresent()).toBeTruthy();
}
};
Base.prototype.expectTabIsDisabled = function (tabs) {
for (var _i = 0, tabs_3 = tabs; _i < tabs_3.length; _i++) {
var tab = tabs_3[_i];
expect(protractor_1.element(protractor_1.by.xpath("//li[contains(@class, 'ui-state-disabled')][.//span[contains(text(), '" + tab + "')]]")).isPresent()).toBeTruthy();
}
};
/** Retorna true si el DIV de error es visible */
Base.prototype.expectExisteError = function (errorMessage) {
if (errorMessage === void 0) { errorMessage = []; }
//let divError: ElementFinder = element(by.cssContainingText("div.ui-messages-error span.ui-messages-detail", "Error:"));
if (errorMessage.length > 0) {
for (var _i = 0, errorMessage_1 = errorMessage; _i < errorMessage_1.length; _i++) {
var error = errorMessage_1[_i];
var divError = protractor_1.element(protractor_1.by.cssContainingText("div.ui-messages-error span.ui-messages-detail", error));
expect(divError.isPresent()).toBeTruthy();
}
}
else {
var divError = protractor_1.element(protractor_1.by.css("div.ui-messages-error span.ui-messages-detail"));
expect(divError.isPresent());
}
};
Base.prototype.waitForAngular = function () {
return protractor_1.browser.waitForAngular();
};
/** Navegará a la url que indiquemos por parámetro
* @param url URL a la que navegar incluido el contextPath pero sin el host y puerto
*/
Base.prototype.navigateTo = function (url) {
return protractor_1.browser.get(url);
};
Base.prototype.reload = function () {
return protractor_1.browser.refresh();
};
Base.prototype.scrollDown = function (x, y) {
protractor_1.browser.executeScript("window.scrollTo(" + x + "," + y + ");");
};
Base.prototype.scrollBottom = function () {
protractor_1.browser.executeScript("window.scrollTo(0,document.body.scrollHeight);");
};
Base.prototype.maximize = function () {
protractor_1.browser.driver
.manage()
.window()
.maximize();
};
Base.prototype.getCurrentUrl = function () {
var _this = this;
return protractor_1.browser.getCurrentUrl().then(function (url) {
_this.log("navegando hacia " + url);
return url;
});
};
/**
* Retornará el ID de un objeto y que se encuentra al final de la URL actual.
*/
Base.prototype.getIdFromCurrentUrl = function () {
var _this = this;
return protractor_1.browser.getCurrentUrl().then(function (url) {
_this.log("hemos obtenido la url: " + url);
var indiceUltimaBarra = url.lastIndexOf("/");
return +url.substring(indiceUltimaBarra + 1);
});
};
Base.prototype.acceptAlert = function (texto) {
if (texto === void 0) { texto = null; }
var EC = protractor_1.protractor.ExpectedConditions;
protractor_1.browser.wait(EC.alertIsPresent(), 4000, "Alert no presente :(");
return protractor_1.browser
.switchTo()
.alert()
.accept();
/*var alertDialog = browser.switchTo().alert();
if (texto) {
return alertDialog.getText().then(textoAlert => {
if (textoAlert.indexOf(texto) == -1) {
fail("expected '" + textoAlert + "' to contain '" + texto + "'");
} else {
this.log("alert text matches");
return alertDialog.accept();
}
});
} else {
return alertDialog.accept();
}*/
};
/**
* Retornará true si el elemento pasado por parámetro tiene el atributo "disabled" a true.
* Util para comprobar si un botón está activo o no.
*/
Base.prototype.isDisabled = function (element) {
return element.getAttribute("disabled").then(function (attribute) {
return attribute == "true";
});
};
/**
* Sitúa el cursor sobre el elemento.
*/
Base.prototype.mouseOver = function (element) {
protractor_1.protractor.browser
.actions()
.mouseMove(element)
.perform();
};
/**
* Sitúa el cursor sobre el elemento.
*/
Base.prototype.mouseClick = function (element, offset) {
if (offset === void 0) { offset = { x: 0, y: 0 }; }
protractor_1.protractor.browser
.actions()
.mouseMove(element, offset)
.mouseDown()
.mouseUp()
.perform();
};
/**
* Sitúa el cursor sobre el elemento.
*/
Base.prototype.mouseCtrlClick = function (element, offset) {
if (offset === void 0) { offset = { x: 0, y: 0 }; }
protractor_1.protractor.browser
.actions()
.mouseMove(element, offset)
.keyDown(protractor_1.protractor.Key.CONTROL)
.mouseDown()
.mouseUp()
.perform();
};
Base.prototype.printOptionsCount = function (optionsCount) {
var _this = this;
optionsCount.then(function (count) {
_this.log("el dropdown tiene " + count + " opciones ");
});
};
Base.prototype.printHowManyRows = function (rowsCount) {
var _this = this;
rowsCount.then(function (count) {
_this.log("la tabla tiene " + count + " filas");
});
};
Base.prototype.log = function (texto) {
Base.environment && Base.environment.debug && console.log(texto);
};
return Base;
}());
exports.Base = Base;
//# sourceMappingURL=base.po.js.map