فهرست منبع

test: refactor login logic

Girish Ramakrishnan 8 سال پیش
والد
کامیت
3737953465
1فایلهای تغییر یافته به همراه12 افزوده شده و 26 حذف شده
  1. 12 26
      test/test.js

+ 12 - 26
test/test.js

@@ -53,6 +53,14 @@ describe('Application life cycle test', function () {
         done();
     });
 
+    function login(done) {
+        browser.get('https://' + app.fqdn + '/wp-login.php');
+        browser.findElement(by.id('user_login')).sendKeys(username);
+        browser.findElement(by.id('user_pass')).sendKeys(password);
+        browser.findElement(by.tagName('form')).submit();
+        browser.wait(until.elementLocated(by.xpath('//h1[text()="Dashboard"]')), 4000).then(function () { done(); });
+    }
+
     xit('build app', function () {
         execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
     });
@@ -101,13 +109,7 @@ describe('Application life cycle test', function () {
         });
     });
 
-    it('can login', function (done) {
-        browser.get('https://' + app.fqdn + '/wp-login.php');
-        browser.findElement(by.id('user_login')).sendKeys(username);
-        browser.findElement(by.id('user_pass')).sendKeys(password);
-        browser.findElement(by.tagName('form')).submit();
-        browser.wait(until.elementLocated(by.xpath('//h1[text()="Dashboard"]')), 4000).then(function () { done(); });
-    });
+    it('can login', login);
 
     it('is an admin dashboard', function (done) {
         browser.wait(until.elementLocated(by.xpath('//div[@class="wp-menu-name" and contains(text(), "Plugins")]')), 4000).then(function () { done(); });
@@ -186,13 +188,7 @@ describe('Application life cycle test', function () {
         });
     });
 
-    it('can login', function (done) {
-        browser.get('https://' + app.fqdn + '/wp-login.php');
-        browser.findElement(by.id('user_login')).sendKeys(username);
-        browser.findElement(by.id('user_pass')).sendKeys(password);
-        browser.findElement(by.tagName('form')).submit();
-        browser.wait(until.elementLocated(by.xpath('//h1[text()="Dashboard"]')), 4000).then(function () { done(); });
-    });
+    it('can login', login);
 
     it('move to different location', function () {
         browser.manage().deleteAllCookies();
@@ -216,13 +212,7 @@ describe('Application life cycle test', function () {
         });
     });
 
-    it('can login', function (done) {
-        browser.get('https://' + app.fqdn + '/wp-login.php');
-        browser.findElement(by.id('user_login')).sendKeys(username);
-        browser.findElement(by.id('user_pass')).sendKeys(password);
-        browser.findElement(by.tagName('form')).submit();
-        browser.wait(until.elementLocated(by.xpath('//h1[text()="Dashboard"]')), 4000).then(function () { done(); });
-    });
+    it('can login', login);
 
     it('uninstall app', function () {
         execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
@@ -236,11 +226,7 @@ describe('Application life cycle test', function () {
         app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
         expect(app).to.be.an('object');
 
-        browser.get('https://' + app.fqdn + '/wp-login.php');
-        browser.findElement(by.id('user_login')).sendKeys(username);
-        browser.findElement(by.id('user_pass')).sendKeys(password);
-        browser.findElement(by.tagName('form')).submit();
-        browser.wait(until.elementLocated(by.xpath('//h1[text()="Dashboard"]')), 4000).then(function () {
+        login(function () {
             execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
             done();
         });