function checkSpec() {
return driver.executeScript("var search = []; if (typeof xmlDataSpeclist !== 'undefined') {" +
"$.each(xmlDataSpeclist, function (key, item) {" +
"search.push(" +
"'http://domain/?spec='" + " + item.id" +
");" +
"});" +
"};" +
"return search;"
).then((search) => {
return Promise.all(search.map(function(val, i) {
console.log(search.length); //debug printing
return new Promise((resolve, reject) => {
request(search[i], function(error, response, body){
if (error) {
reject(error);
}
resolve(body);
});
}).then((body) => {
console.log(body);
assert.include(body, 'class="someClass"');
});
}));
});
}
return checkSpec();
function testsHelper(driver) {
var _driver = driver;
function loadRegistrationForm() {
_driver.get('http:...');
_driver.getTitle().then(function(title){
if("..."===title){
_driver.findElement(web_driver.By.xpath('html/body/div/header/div/div/div[2]/div[2]/a[1]'))
.click();
};
});
_driver.wait(function(){
return _driver.isElementPresent(web_driver.By.name('fos_user_registration_form[email]'));
}, 3000, 'Failed to load Registration form');
}
// заполнение формы регистрации и проверка соответствия
function fillingRegistrationForm(inputEmail, inputPassword, errElement, errMessage) {
_driver.findElement(web_driver.By.name('fos_user_registration_form[email]'))
.sendKeys(inputEmail); //вводим уже зарегистрированный email
_driver.findElement(web_driver.By.name('fos_user_registration_form[plainPassword]'))
.sendKeys(inputPassword); //вводим валидный пароль
_driver.findElement(web_driver.By.id('btn-submit')).click();//сабмит
_driver.wait(function(){
return _driver.isElementPresent(web_driver.By.xpath(errElement));
}, 3000, 'Элемент не найден'); //ожидание загрузки текста ошибки
var flow = web_driver.promise.controlFlow();
function getErrObject(){
errObject = _driver.findElement(web_driver.By.xpath(errElement))
.getText()
} //берем объект элемента с текстом ошибки
flow.execute(getErrObject).then(function(){
if(errObject.value_ === errMessage){
assert.equal(errObject.value_, errMessage);
console.log('OK')
};
});
}
return {
fillingRegistrationForm: fillingRegistrationForm,
loadRegistrationForm: loadRegistrationForm
}
}
module.exports = testsHelper;
var Helper = require(testsHelper.js);
// инициализируем driver
var driver = ...
var helper = new Helper(driver);