Asyncify tests

This commit is contained in:
Johannes Zellner 2022-01-03 11:45:00 +01:00
parent 1bd952c9f9
commit c11b32c15b
1 changed files with 42 additions and 97 deletions

View File

@ -46,129 +46,74 @@ describe('Application life cycle test', function () {
expect(app).to.be.an('object');
}
function exists(selector) {
return browser.wait(until.elementLocated(selector), TEST_TIMEOUT);
}
function visible(selector) {
return exists(selector).then(function () {
return browser.wait(until.elementIsVisible(browser.findElement(selector)), TEST_TIMEOUT);
});
}
function baseUrl() {
if (app.manifest.version === '1.4.0') return `https://${app.fqdn}/p`;
return `https://${app.fqdn}`;
}
// we do this because it perm redirects to /p/ in old versions
function clearCache() {
// https://stackoverflow.com/questions/49614217/selenium-clear-chrome-cache
// defaut clearance is 1 hour of cache
return browser.get('chrome://settings/clearBrowserData').then(function () {
return visible(By.css('* /deep/ #clearBrowsingDataConfirm'));
}).then(function () {
return browser.findElement(By.css('* /deep/ #clearBrowsingDataConfirm')).click();
}).then(function () {
return browser.sleep(5000);
});
async function waitForElement(elem) {
await browser.wait(until.elementLocated(elem), TEST_TIMEOUT);
await browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);
}
function login(password, callback) {
browser.get('https://' + app.fqdn).then(function () {
return visible(By.id('loginButton'));
}).then(function () {
return browser.findElement(By.id('username')).sendKeys(username);
}).then(function () {
return browser.findElement(By.id('passwordPlain')).sendKeys(password);
}).then(function () {
return browser.findElement(By.id('loginButton')).click();
}).then(function () {
return browser.wait(until.elementLocated(By.id('dropdown-configure')), TEST_TIMEOUT);
}).then(function () {
callback();
});
async function login(password) {
await browser.get('https://' + app.fqdn);
await waitForElement(By.id('loginButton'));
await browser.findElement(By.id('username')).sendKeys(username);
await browser.findElement(By.id('passwordPlain')).sendKeys(password);
await browser.findElement(By.id('loginButton')).click();
await waitForElement(By.id('btn-subscription'));
}
function logout(callback) {
async function logout() {
var logout_btn = By.xpath('//li/a[@class="signout"]');
browser.get('https://' + app.fqdn).then(function () {
return visible(By.id('stream'));
}).then(function () {
return browser.findElement(By.className('dropdown-toggle')).click();
}).then(function () {
return visible(logout_btn);
}).then(function () {
return browser.findElement(logout_btn).click();
}).then(function () {
return browser.wait(until.elementLocated(By.id('loginButton')), TEST_TIMEOUT);
}).then(function () {
callback();
});
await browser.get('https://' + app.fqdn);
await waitForElement(By.id('stream'));
await browser.findElement(By.className('dropdown-toggle')).click();
await waitForElement(logout_btn);
await browser.findElement(logout_btn).click();
await waitForElement(By.id('loginButton'));
}
function addSubscription(callback) {
async function addSubscription() {
var url = 'https://blog.cloudron.io/rss/';
const addUrl = app.manifest.version === '1.10.0' ? `${baseUrl()}/i/?c=subscription` : `${baseUrl()}/i/?c=subscription&a=add`;
browser.get(addUrl).then(function () {
return visible(By.xpath('//input[@name="url_rss"]'));
}).then(function () {
return browser.findElement(By.xpath('//input[@name="url_rss"]')).sendKeys(url);
}).then(function () {
return browser.findElement(By.xpath('//button[@type="submit"]/ancestor::form[@id="add_rss"]')).submit();
}).then(function () {
return visible(By.xpath('//div[@id="notification" and @class="notification good"]'));
}).then(function () {
callback();
});
await browser.get(addUrl);
await waitForElement(By.xpath('//input[@name="url_rss"]'));
await browser.findElement(By.xpath('//input[@name="url_rss"]')).sendKeys(url);
await browser.findElement(By.xpath('//form[@id="add_rss"]//button[text()="Add"]')).click();
await waitForElement(By.xpath('//div[@id="notification" and @class="notification good"]'));
}
function addUser(password, callback) {
async function addUser(password) {
var test_username = 'test';
browser.get(`${baseUrl()}/i/?c=user&a=manage`).then(function () {
return visible(By.id('new_user_name'));
}).then(function () {
return browser.findElement(By.id('new_user_name')).sendKeys(test_username);
}).then(function () {
return browser.findElement(By.id('new_user_passwordPlain')).sendKeys(password);
}).then(function () {
return browser.findElement(By.xpath('//button[text()="Create"]')).click();
}).then(function () {
return visible(By.xpath('//div[@id="notification" and @class="notification good"]'));
}).then(function () {
callback();
});
await browser.get(`${baseUrl()}/i/?c=user&a=manage`);
await waitForElement(By.id('new_user_name'));
await browser.findElement(By.id('new_user_name')).sendKeys(test_username);
await browser.findElement(By.id('new_user_passwordPlain')).sendKeys(password);
await browser.findElement(By.xpath('//button[text()="Create"]')).click();
await waitForElement(By.xpath('//div[@id="notification" and @class="notification good"]'));
}
function enableApi(callback) {
browser.get(`${baseUrl()}/i/?c=auth`).then(function () {
return browser.findElement(By.id('api_enabled')).click();
}).then(function () {
return browser.findElement(By.xpath('//button[text()="Submit"]')).click();
}).then(function () {
callback();
});
async function enableApi() {
await browser.get(`${baseUrl()}/i/?c=auth`);
await waitForElement(By.id('api_enabled'));
await browser.findElement(By.id('api_enabled')).click();
await browser.findElement(By.xpath('//button[text()="Submit"]')).click();
}
function checkApiConfiguration(callback) {
browser.get(`${baseUrl()}/api/`).then(function () {
return exists(By.xpath('//dd[@id="greaderOutput" and contains(text(), "PASS")]'));
}).then(function () {
return exists(By.xpath('//dd[@id="feverOutput" and contains(text(), "PASS")]'));
}).then(function () {
callback();
});
async function checkApiConfiguration() {
await browser.get(`${baseUrl()}/api/`);
await waitForElement(By.xpath('//dd[@id="greaderOutput" and contains(text(), "PASS")]'));
await waitForElement(By.xpath('//dd[@id="feverOutput" and contains(text(), "PASS")]'));
}
function subscriptionExists(callback) {
browser.get(`${baseUrl()}/i/?get=c_1`).then(function () {
return visible(By.xpath('//span[text()="Cloudron"]'));
}).then(function () {
callback();
});
async function subscriptionExists() {
await browser.get(`${baseUrl()}/i/?get=c_1`);
return waitForElement(By.xpath('//span[text()="Cloudron"]'));
}
function getStaticExtensionFile(callback) {