瀏覽代碼

fix promise usage

Girish Ramakrishnan 7 年之前
父節點
當前提交
485c860ff6
共有 1 個文件被更改,包括 80 次插入47 次删除
  1. 80 47
      test/test.js

+ 80 - 47
test/test.js

@@ -62,12 +62,19 @@ describe('Application life cycle test', function () {
     }
 
     function login(done) {
-        browser.manage().deleteAllCookies();
-        browser.get('https://' + app.fqdn + '/user/login');
-        browser.findElement(by.id('user_name')).sendKeys(username);
-        browser.findElement(by.id('password')).sendKeys(password);
-        browser.findElement(by.tagName('form')).submit();
-        browser.wait(until.elementLocated(by.linkText('Dashboard')), TIMEOUT).then(function () { done(); });
+        browser.manage().deleteAllCookies().then(function () {
+            return browser.get('https://' + app.fqdn + '/user/login');
+        }).then(function () {
+            return browser.findElement(by.id('user_name')).sendKeys(username);
+        }).then(function () {
+            return browser.findElement(by.id('password')).sendKeys(password);
+        }).then(function () {
+            return browser.findElement(by.tagName('form')).submit();
+        }).then(function () {
+            return browser.wait(until.elementLocated(by.linkText('Dashboard')), TIMEOUT);
+        }).then(function () {
+            done();
+        });
     }
 
     function waitForUrl(url, done) {
@@ -79,12 +86,14 @@ describe('Application life cycle test', function () {
     }
 
     function setAvatar(done) {
-        browser.get('https://' + app.fqdn + '/user/settings/avatar');
-
-        browser.findElement(by.xpath('//input[@type="file" and @name="avatar"]')).sendKeys(path.resolve(__dirname, '../logo.png')).then(function () {
-            browser.findElement(by.xpath('//button[contains(text(), "Update Avatar Setting")]')).click();
-
-            browser.wait(until.elementLocated(by.xpath('//p[contains(text(),"updated successfully")]')), TIMEOUT).then(function () { done(); });
+        browser.get('https://' + app.fqdn + '/user/settings/avatar').then(function () {
+            return browser.findElement(by.xpath('//input[@type="file" and @name="avatar"]')).sendKeys(path.resolve(__dirname, '../logo.png'));
+        }).then(function () {
+            return browser.findElement(by.xpath('//button[contains(text(), "Update Avatar Setting")]')).click();
+        }).then(function () {
+            return browser.wait(until.elementLocated(by.xpath('//p[contains(text(),"updated successfully")]')), TIMEOUT);
+        }).then(function () {
+            done();
         });
     }
 
@@ -97,17 +106,25 @@ describe('Application life cycle test', function () {
     }
 
     function createRepo(done) {
-        browser.get('https://' + app.fqdn);
-        browser.findElement(by.linkText('New Repository')).click();
-        browser.wait(until.elementLocated(by.xpath('//*[contains(text(), "New Repository")]')), TIMEOUT);
-        browser.findElement(by.id('repo_name')).sendKeys(reponame);
-        browser.findElement(by.id('auto-init')).click();
-        browser.findElement(by.xpath('//button[contains(text(), "Create Repository")]')).click();
-        browser.wait(function () {
-            return browser.getCurrentUrl().then(function (url) {
-                return url === 'https://' + app.fqdn + '/' + username + '/' + reponame;
-            });
-        }, TIMEOUT).then(function () { done(); });
+        browser.get('https://' + app.fqdn).then(function () {
+            return browser.findElement(by.linkText('New Repository')).click();
+        }).then(function () {
+            return browser.wait(until.elementLocated(by.xpath('//*[contains(text(), "New Repository")]')), TIMEOUT);
+        }).then(function () {
+            return browser.findElement(by.id('repo_name')).sendKeys(reponame);
+        }).then(function () {
+            return browser.findElement(by.id('auto-init')).click();
+        }).then(function () {
+            return browser.findElement(by.xpath('//button[contains(text(), "Create Repository")]')).click();
+        }).then(function () {
+            return browser.wait(function () {
+                return browser.getCurrentUrl().then(function (url) {
+                    return url === 'https://' + app.fqdn + '/' + username + '/' + reponame;
+                });
+            }, TIMEOUT);
+        }).then(function () {
+            done();
+        });
     }
 
     function cloneRepo() {
@@ -124,14 +141,15 @@ describe('Application life cycle test', function () {
     }
 
     function editFile(done) {
-        browser.get('https://' + app.fqdn + '/' + username + '/' + reponame + '/_edit/master/newfile');
-
-        var cm = browser.findElement(by.xpath('//div[contains(@class,"CodeMirror")]'));
-        var text = 'yo';
-        browser.executeScript('arguments[0].CodeMirror.setValue("' + text + '");', cm).then(function () {
-            browser.findElement(by.xpath('//input[@name="commit_summary"]')).sendKeys('Dummy edit');
-            browser.findElement(by.xpath('//button[contains(text(), "Commit Changes")]')).click();
-
+        browser.get('https://' + app.fqdn + '/' + username + '/' + reponame + '/_edit/master/newfile').then(function () {
+            var cm = browser.findElement(by.xpath('//div[contains(@class,"CodeMirror")]'));
+            var text = 'yo';
+            return browser.executeScript('arguments[0].CodeMirror.setValue("' + text + '");', cm);
+        }).then(function () {
+            return browser.findElement(by.xpath('//input[@name="commit_summary"]')).sendKeys('Dummy edit');
+        })..then(function () {
+            return browser.findElement(by.xpath('//button[contains(text(), "Commit Changes")]')).click();
+        }).then(function () {
             waitForUrl('https://' + app.fqdn + '/' + username + '/' + reponame + '/src/master/newfile', done);
         });
     }
@@ -141,23 +159,32 @@ describe('Application life cycle test', function () {
     }
 
     function checkCloneUrl(done) {
-        browser.get('https://' + app.fqdn + '/' + username + '/' + reponame);
-        browser.findElement(by.id('repo-clone-ssh')).click();
-        browser.findElement(by.id('repo-clone-url')).getAttribute('value').then(function (cloneUrl) {
+        browser.get('https://' + app.fqdn + '/' + username + '/' + reponame).then(function () {
+            return browser.findElement(by.id('repo-clone-ssh')).click();
+        }).then(function () {
+            return browser.findElement(by.id('repo-clone-url')).getAttribute('value');
+        }).then(function (cloneUrl) {
             expect(cloneUrl).to.be('ssh://git@' + app.fqdn + ':29418/' + username + '/' + reponame + '.git');
             done();
         });
     }
 
     function addPublicKey(done) {
-        browser.get('https://' + app.fqdn + '/user/settings/ssh');
-        var publicKey = fs.readFileSync(__dirname + '/id_rsa.pub', 'utf8');
-
-        browser.findElement(by.xpath('//div[text()="Add Key"]')).click();
-        browser.findElement(by.id('title')).sendKeys('testkey');
-        browser.findElement(by.id('content')).sendKeys(publicKey.trim()); // #3480
-        browser.findElement(by.xpath('//button[contains(text(), "Add Key")]')).click();
-        browser.wait(until.elementLocated(by.xpath('//p[contains(text(), "added successfully!")]')), TIMEOUT).then(function () { done(); });
+        browser.get('https://' + app.fqdn + '/user/settings/ssh').then(function () {
+            var publicKey = fs.readFileSync(__dirname + '/id_rsa.pub', 'utf8');
+
+            return browser.findElement(by.xpath('//div[text()="Add Key"]')).click();
+        }).then(function () {
+            return browser.findElement(by.id('title')).sendKeys('testkey');
+        }).then(function () {
+            return browser.findElement(by.id('content')).sendKeys(publicKey.trim()); // #3480
+        }).then(function () {
+            return browser.findElement(by.xpath('//button[contains(text(), "Add Key")]')).click();
+        }).then(function () {
+            return browser.wait(until.elementLocated(by.xpath('//p[contains(text(), "added successfully!")]')), TIMEOUT);
+        }).then(function () {
+            done();
+        });
     }
 
     xit('build app', function () {
@@ -221,11 +248,17 @@ describe('Application life cycle test', function () {
     it('can get app information', getAppInfo);
 
     it('can login via email', function (done) {
-        browser.get('https://' + app.fqdn + '/user/login');
-        browser.findElement(by.id('user_name')).sendKeys(email);
-        browser.findElement(by.id('password')).sendKeys(password);
-        browser.findElement(by.tagName('form')).submit();
-        browser.wait(until.elementLocated(by.linkText('Dashboard')), TIMEOUT).then(function () { done(); });
+        browser.get('https://' + app.fqdn + '/user/login').then(function () {
+            return browser.findElement(by.id('user_name')).sendKeys(email);
+        }).then(function () {
+            return browser.findElement(by.id('password')).sendKeys(password);
+        }).then(function () {
+            return browser.findElement(by.tagName('form')).submit();
+        }).then(function () {
+            return browser.wait(until.elementLocated(by.linkText('Dashboard')), TIMEOUT);
+        }).then(function () {
+            done();
+        });
     });
 
     it('uninstall app', function () {