import {LoginModal} from './pages'; import {browser, protractor, element, by, ElementFinder, ElementArrayFinder} from 'protractor'; import {ECE, s} from '@superdesk/end-to-end-testing-helpers'; // construct url from uri and base url export function constructUrl(base, uri) { return base.replace(/\/$/, '') + uri; } // authenticate if needed export function login(username?, password?) { let usr = username || 'admin'; let pwd = password || 'admin'; var modal = new LoginModal(); return modal.btn.isDisplayed() .then((needLogin) => { if (needLogin) { return modal.login(usr, pwd); } }); } // open url export function changeUrl(url) { return browser.get(url).then(waitForSuperdesk); } // open url and authenticate export function openUrl(url) { return browser.get(url) .then(login) .then(waitForSuperdesk); } export function printLogs(prefix) { return browser.manage() .logs() .get('browser') .then((browserLog) => { var logs = browserLog.filter((log) => log.level.value >= 1000); console.info( (prefix ? prefix + ' ' : '') + 'log: ' + require('util').inspect(logs, {dept: 3}), ); }); } export function waitForSuperdesk() { return browser.driver.wait( () => browser.driver.executeScript('return window.superdeskIsReady || false'), 5000, '"window.superdeskIsReady" is not here', ).then((res) => { browser.executeScript('window.superdesk_e2e_tests_running = true;'); return res; }); } export function refresh() { browser.refresh().then(() => waitForSuperdesk()); } /** * Navigate to given location. * * Unlinke openUrl it doesn't reload the page, only changes #hash in url * * @param {string} location Location where to navigate without # (eg. users, workspace/content) * @return {Promise} */ export function nav(location) { return login().then(() => browser.setLocation(location)); } /** * Nav shortcut for beforeEach, use like `beforeEach(route('/workspace'));` * * @param {string} location * @return {function} */ export function route(location) { return function() { nav(location); }; } /** * Finds and returns the n-th