Fixup tests for base url and password

This commit is contained in:
Girish Ramakrishnan 2019-01-03 16:36:12 -08:00
parent 9ca04c0e8c
commit 213e1e740f
1 changed files with 35 additions and 18 deletions

View File

@ -14,8 +14,7 @@ var by = webdriver.By,
until = webdriver.until; until = webdriver.until;
var username = 'admin', var username = 'admin',
password = 'password'; password = 'changeme';
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
@ -55,8 +54,26 @@ describe('Application life cycle test', function () {
}); });
} }
function login(callback) { function baseUrl() {
browser.manage().deleteAllCookies().then(function () { 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);
});
}
function login(password, callback) {
clearCache().then(function () {
return browser.get('https://' + app.fqdn); return browser.get('https://' + app.fqdn);
}).then(function () { }).then(function () {
return visible(by.id('loginButton')); return visible(by.id('loginButton'));
@ -94,7 +111,7 @@ describe('Application life cycle test', function () {
function addSubscription(callback) { function addSubscription(callback) {
var url = "https://cloudron.io/blog/rss.xml"; var url = "https://cloudron.io/blog/rss.xml";
browser.get(`https://${app.fqdn}/p/i/?c=subscription`).then(function () { browser.get(`${baseUrl()}/i/?c=subscription`).then(function () {
return visible(by.xpath('//input[@name="url_rss"]')); return visible(by.xpath('//input[@name="url_rss"]'));
}).then(function () { }).then(function () {
return browser.findElement(by.xpath('//input[@name="url_rss"]')).sendKeys(url); return browser.findElement(by.xpath('//input[@name="url_rss"]')).sendKeys(url);
@ -107,10 +124,10 @@ describe('Application life cycle test', function () {
}); });
} }
function addUser(callback) { function addUser(password, callback) {
var test_username = 'test'; var test_username = 'test';
browser.get(`https://${app.fqdn}/p/i/?c=user&a=manage`).then(function () { browser.get(`${baseUrl()}/i/?c=user&a=manage`).then(function () {
return visible(by.id('new_user_name')); return visible(by.id('new_user_name'));
}).then(function () { }).then(function () {
return browser.findElement(by.id('new_user_name')).sendKeys(test_username); return browser.findElement(by.id('new_user_name')).sendKeys(test_username);
@ -126,7 +143,7 @@ describe('Application life cycle test', function () {
} }
function enableApi(callback) { function enableApi(callback) {
browser.get('https://' + app.fqdn + '/p/i/?c=auth').then(function () { browser.get(`${baseUrl()}/i/?c=auth`).then(function () {
return browser.findElement(by.id('api_enabled')).click(); return browser.findElement(by.id('api_enabled')).click();
}).then(function () { }).then(function () {
return browser.findElement(by.xpath('//button[text()="Submit"]')).submit(); return browser.findElement(by.xpath('//button[text()="Submit"]')).submit();
@ -136,7 +153,7 @@ describe('Application life cycle test', function () {
} }
function checkApiConfiguration(callback) { function checkApiConfiguration(callback) {
browser.get('https://' + app.fqdn + '/p/api/greader.php/check%2Fcompatibility').then(function () { browser.get(`${baseUrl()}/api/greader.php/check%2Fcompatibility`).then(function () {
return exists(by.xpath('//pre[text()="PASS"]')); return exists(by.xpath('//pre[text()="PASS"]'));
}).then(function () { }).then(function () {
callback(); callback();
@ -150,7 +167,7 @@ describe('Application life cycle test', function () {
} }
function subscriptionExists(callback) { function subscriptionExists(callback) {
browser.get('https://' + app.fqdn + '/p/i/?get=c_1').then(function () { browser.get(`${baseUrl()}/i/?get=c_1`).then(function () {
return visible(by.xpath('//a[text()="Cloudron.io"]')); return visible(by.xpath('//a[text()="Cloudron.io"]'));
}).then(function () { }).then(function () {
callback(); callback();
@ -158,7 +175,7 @@ describe('Application life cycle test', function () {
} }
function getStaticExtensionFile(callback) { function getStaticExtensionFile(callback) {
superagent.get(`https://${app.fqdn}/p/ext.php?f=xExtension-StickyFeeds/static/script.js&t=js`) superagent.get(`${baseUrl()}/ext.php?f=xExtension-StickyFeeds/static/script.js&t=js`)
.buffer(true) .buffer(true)
.end(function (err, res) { .end(function (err, res) {
expect(err).to.be(null); expect(err).to.be(null);
@ -178,9 +195,9 @@ describe('Application life cycle test', function () {
it('can get app information', getAppInfo); it('can get app information', getAppInfo);
it('can login', login); it('can login', login.bind(null, password));
it('can subscribe', addSubscription); it('can subscribe', addSubscription);
it('can add users', addUser); it('can add users', addUser.bind(null, password));
it('can enable API', enableApi); it('can enable API', enableApi);
it('can check configuration', checkApiConfiguration); it('can check configuration', checkApiConfiguration);
it('subscription exists', subscriptionExists); it('subscription exists', subscriptionExists);
@ -195,7 +212,7 @@ describe('Application life cycle test', function () {
execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
}); });
it('can login', login); it('can login', login.bind(null, password));
it('can check configuration', checkApiConfiguration); it('can check configuration', checkApiConfiguration);
it('subscription exists', subscriptionExists); it('subscription exists', subscriptionExists);
it('can get static extension file', getStaticExtensionFile); it('can get static extension file', getStaticExtensionFile);
@ -209,7 +226,7 @@ describe('Application life cycle test', function () {
expect(app).to.be.an('object'); expect(app).to.be.an('object');
}); });
it('can login', login); it('can login', login.bind(null, password));
it('can check configuration', checkApiConfiguration); it('can check configuration', checkApiConfiguration);
it('subscription exists', subscriptionExists); it('subscription exists', subscriptionExists);
it('can get static extension file', getStaticExtensionFile); it('can get static extension file', getStaticExtensionFile);
@ -225,9 +242,9 @@ describe('Application life cycle test', function () {
}); });
it('can get app information', getAppInfo); it('can get app information', getAppInfo);
it('can login', login); it('can login', login.bind(null, 'password'));
it('can subscribe', addSubscription); it('can subscribe', addSubscription);
it('can add users', addUser); it('can add users', addUser.bind(null, password));
it('can update', function () { it('can update', function () {
execSync('cloudron install --wait --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); execSync('cloudron install --wait --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
@ -236,7 +253,7 @@ describe('Application life cycle test', function () {
expect(app).to.be.an('object'); expect(app).to.be.an('object');
}); });
it('can login', login); it('can login', login.bind(null, 'password'));
it('subscription exists', subscriptionExists); it('subscription exists', subscriptionExists);
it('can get static extension file', getStaticExtensionFile); it('can get static extension file', getStaticExtensionFile);