fix promise use

This commit is contained in:
Girish Ramakrishnan 2018-09-09 18:31:57 -07:00
parent 2bc2cf8292
commit 5bb5fae5c8
1 changed files with 75 additions and 52 deletions

View File

@ -45,59 +45,69 @@ describe('Application life cycle test', function () {
var TEST_TIMEOUT = 10000; var TEST_TIMEOUT = 10000;
var app; var app;
function exists(selector, callback) { function exists(selector) {
return browser.wait(until.elementLocated(selector), TEST_TIMEOUT).then(function () { return browser.wait(until.elementLocated(selector), TEST_TIMEOUT);
callback();
});
} }
function visible(selector, callback) { function visible(selector, callback) {
exists(selector, function () { return exists(selector).then(function () {
browser.wait(until.elementIsVisible(browser.findElement(selector)), TEST_TIMEOUT).then(function () { return browser.wait(until.elementIsVisible(browser.findElement(selector)), TEST_TIMEOUT);
callback();
});
}); });
} }
function login(callback) { function login(callback) {
browser.manage().deleteAllCookies(); browser.manage().deleteAllCookies().then(function () {
browser.get('https://' + app.fqdn); return browser.get('https://' + app.fqdn);
}).then(function () {
visible(by.id('loginButton'), function () { return visible(by.id('loginButton'));
browser.findElement(by.id('username')).sendKeys(username); }).then(function () {
browser.findElement(by.id('passwordPlain')).sendKeys(password); return browser.findElement(by.id('username')).sendKeys(username);
browser.findElement(by.id('loginButton')).click(); }).then(function () {
browser.wait(until.elementLocated(by.id('dropdown-configure')), TEST_TIMEOUT).then(function () { callback(); }); 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();
}); });
} }
function logout(callback) { function logout(callback) {
var logout_btn = by.xpath('//ul[@class="dropdown-menu"]/li/a[@class="signout"]'); var logout_btn = by.xpath('//ul[@class="dropdown-menu"]/li/a[@class="signout"]');
browser.get('https://' + app.fqdn); browser.get('https://' + app.fqdn).then(function () {
return visible(by.id('stream'));
visible(by.id('stream'), function () { }).then(function () {
browser.findElement(by.className('dropdown-toggle')).click(); return browser.findElement(by.className('dropdown-toggle')).click();
visible(logout_btn, function () { }).then(function () {
browser.findElement(logout_btn).click(); return visible(logout_btn);
}).then(function () {
browser.wait(until.elementLocated(by.id('loginButton')), TEST_TIMEOUT).then(function () { callback(); }); return browser.findElement(logout_btn).click();
}); }).then(function () {
return browser.wait(until.elementLocated(by.id('loginButton')), TEST_TIMEOUT);
}).then(function () {
callback();
}); });
} }
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); browser.get('https://' + app.fqdn).then(function () {
return visible(by.id('stream'));
visible(by.id('stream'), function () { }).then(function () {
browser.findElement(by.xpath('//a[@href=".?c=subscription"]')).click(); return browser.findElement(by.xpath('//a[@href=".?c=subscription"]')).click();
visible(by.id('add_rss'), function () { }).then(function () {
browser.findElement(by.xpath('//input[@name="url_rss"]')).sendKeys(url); return visible(by.id('add_rss'));
browser.findElement(by.xpath('//form[@id="add_rss"]/div/button[@type="submit"]')).click(); }).then(function () {
visible(by.xpath('//div[@id="notification" and @class="notification good"]'), function() { callback(); }); return browser.findElement(by.xpath('//input[@name="url_rss"]')).sendKeys(url);
}); }).then(function () {
return browser.findElement(by.xpath('//form[@id="add_rss"]/div/button[@type="submit"]')).click();
}).then(function () {
return visible(by.xpath('//div[@id="notification" and @class="notification good"]'));
}).then(function () {
callback();
}); });
} }
@ -105,19 +115,26 @@ describe('Application life cycle test', function () {
var test_username = 'test'; var test_username = 'test';
var manage_users_btn = by.xpath('//a[@href=".?c=user&a=manage"]'); var manage_users_btn = by.xpath('//a[@href=".?c=user&a=manage"]');
browser.get('https://' + app.fqdn); browser.get('https://' + app.fqdn).then(function () {
return visible(by.id('stream'));
visible(by.id('stream'), function () { }).then(function () {
browser.findElement(by.className('dropdown-toggle')).click(); return browser.findElement(by.className('dropdown-toggle')).click();
visible(manage_users_btn, function () { }).then(function () {
browser.findElement(manage_users_btn).click(); return visible(manage_users_btn);
visible(by.id('new_user_name'), function () { }).then(function () {
browser.findElement(by.id('new_user_name')).sendKeys(test_username); return browser.findElement(manage_users_btn).click();
browser.findElement(by.id('new_user_passwordPlain')).sendKeys(password); }).then(function () {
browser.findElement(by.xpath('//form[@action=".?c=user&a=create"]/div/div/button[@type="submit"]')).click(); return visible(by.id('new_user_name'));
visible(by.xpath('//div[@id="notification" and @class="notification good"]'), function() { callback(); }); }).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('//form[@action=".?c=user&a=create"]/div/div/button[@type="submit"]')).click();
}).then(function () {
return visible(by.xpath('//div[@id="notification" and @class="notification good"]'));
}).then(function () {
callback();
}); });
} }
@ -126,12 +143,16 @@ describe('Application life cycle test', 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('//form[@action=".?c=auth"]')).submit(); return browser.findElement(by.xpath('//form[@action=".?c=auth"]')).submit();
}).then(callback); }).then(function () {
callback();
});
} }
function checkApiConfiguration(callback) { function checkApiConfiguration(callback) {
browser.get('https://' + app.fqdn + '/p/api/greader.php/check%2Fcompatibility').then(function () { browser.get('https://' + app.fqdn + '/p/api/greader.php/check%2Fcompatibility').then(function () {
exists(by.xpath('//pre[text()="PASS"]'), callback); return exists(by.xpath('//pre[text()="PASS"]'));
}).then(function () {
callback();
}); });
} }
@ -142,9 +163,11 @@ describe('Application life cycle test', function () {
} }
function subscriptionExists(callback) { function subscriptionExists(callback) {
browser.get('https://' + app.fqdn + '/p/i/?get=c_1'); browser.get('https://' + app.fqdn + '/p/i/?get=c_1').then(function () {
return visible(by.xpath('//a[text()="Cloudron.io"]'));
visible(by.xpath('//a[text()="Cloudron.io"]'), callback); }).then(function () {
callback();
});
} }
function getStaticExtensionFile(callback) { function getStaticExtensionFile(callback) {