diff --git a/test/test.js b/test/test.js index 1e30ae5..3a19cff 100644 --- a/test/test.js +++ b/test/test.js @@ -45,59 +45,69 @@ describe('Application life cycle test', function () { var TEST_TIMEOUT = 10000; var app; - function exists(selector, callback) { - return browser.wait(until.elementLocated(selector), TEST_TIMEOUT).then(function () { - callback(); - }); + function exists(selector) { + return browser.wait(until.elementLocated(selector), TEST_TIMEOUT); } function visible(selector, callback) { - exists(selector, function () { - browser.wait(until.elementIsVisible(browser.findElement(selector)), TEST_TIMEOUT).then(function () { - callback(); - }); + return exists(selector).then(function () { + return browser.wait(until.elementIsVisible(browser.findElement(selector)), TEST_TIMEOUT); }); } function login(callback) { - browser.manage().deleteAllCookies(); - browser.get('https://' + app.fqdn); - - visible(by.id('loginButton'), function () { - browser.findElement(by.id('username')).sendKeys(username); - browser.findElement(by.id('passwordPlain')).sendKeys(password); - browser.findElement(by.id('loginButton')).click(); - browser.wait(until.elementLocated(by.id('dropdown-configure')), TEST_TIMEOUT).then(function () { callback(); }); + browser.manage().deleteAllCookies().then(function () { + return 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(); }); } function logout(callback) { var logout_btn = by.xpath('//ul[@class="dropdown-menu"]/li/a[@class="signout"]'); - browser.get('https://' + app.fqdn); - - visible(by.id('stream'), function () { - browser.findElement(by.className('dropdown-toggle')).click(); - visible(logout_btn, function () { - browser.findElement(logout_btn).click(); - - browser.wait(until.elementLocated(by.id('loginButton')), TEST_TIMEOUT).then(function () { callback(); }); - }); + 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(); }); } function addSubscription(callback) { var url = "https://cloudron.io/blog/rss.xml"; - browser.get('https://' + app.fqdn); - - visible(by.id('stream'), function () { - browser.findElement(by.xpath('//a[@href=".?c=subscription"]')).click(); - visible(by.id('add_rss'), function () { - browser.findElement(by.xpath('//input[@name="url_rss"]')).sendKeys(url); - browser.findElement(by.xpath('//form[@id="add_rss"]/div/button[@type="submit"]')).click(); - visible(by.xpath('//div[@id="notification" and @class="notification good"]'), function() { callback(); }); - }); + browser.get('https://' + app.fqdn).then(function () { + return visible(by.id('stream')); + }).then(function () { + return browser.findElement(by.xpath('//a[@href=".?c=subscription"]')).click(); + }).then(function () { + return visible(by.id('add_rss')); + }).then(function () { + 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 manage_users_btn = by.xpath('//a[@href=".?c=user&a=manage"]'); - browser.get('https://' + app.fqdn); - - visible(by.id('stream'), function () { - browser.findElement(by.className('dropdown-toggle')).click(); - visible(manage_users_btn, function () { - browser.findElement(manage_users_btn).click(); - visible(by.id('new_user_name'), function () { - browser.findElement(by.id('new_user_name')).sendKeys(test_username); - browser.findElement(by.id('new_user_passwordPlain')).sendKeys(password); - browser.findElement(by.xpath('//form[@action=".?c=user&a=create"]/div/div/button[@type="submit"]')).click(); - visible(by.xpath('//div[@id="notification" and @class="notification good"]'), function() { callback(); }); - }); - }); + 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(manage_users_btn); + }).then(function () { + return browser.findElement(manage_users_btn).click(); + }).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('//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(); }).then(function () { return browser.findElement(by.xpath('//form[@action=".?c=auth"]')).submit(); - }).then(callback); + }).then(function () { + callback(); + }); } function checkApiConfiguration(callback) { 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) { - browser.get('https://' + app.fqdn + '/p/i/?get=c_1'); - - visible(by.xpath('//a[text()="Cloudron.io"]'), callback); + browser.get('https://' + app.fqdn + '/p/i/?get=c_1').then(function () { + return visible(by.xpath('//a[text()="Cloudron.io"]')); + }).then(function () { + callback(); + }); } function getStaticExtensionFile(callback) {