From b52dfa5348029a5cdf6bc7dfda7d94ecc0b5f0ec Mon Sep 17 00:00:00 2001 From: Yuya Ochiai Date: Sat, 21 May 2016 17:23:23 +0900 Subject: [PATCH 1/4] Use Spectron to execute test --- package.json | 3 +- test/modules/environment.js | 24 ++---- test/specs/app_test.js | 76 +++++++++--------- test/specs/browser/index_test.js | 118 ++++++++++++++-------------- test/specs/browser/settings_test.js | 104 ++++++++++++------------ 5 files changed, 152 insertions(+), 173 deletions(-) diff --git a/package.json b/package.json index 7dd61025..62c85629 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,6 @@ "babel-core": "^6.7.5", "babel-loader": "^6.2.4", "babel-preset-react": "^6.5.0", - "chromedriver": "^2.20.0", "del": "^2.2.0", "electron-builder": "^3.11.0", "electron-connect": "^0.3.7", @@ -48,10 +47,10 @@ "mocha": "^2.3.4", "mocha-circleci-reporter": "0.0.1", "should": "^8.0.1", + "spectron": "~3.0.0", "style-loader": "^0.13.0", "through2": "^2.0.1", "vinyl-named": "^1.1.0", - "webdriverio": "^3.3.0", "webpack": "^1.12.15", "webpack-stream": "^3.1.0" }, diff --git a/test/modules/environment.js b/test/modules/environment.js index db6417de..e5dd654d 100644 --- a/test/modules/environment.js +++ b/test/modules/environment.js @@ -1,7 +1,7 @@ 'use strict'; const path = require('path'); -const webdriverio = require('webdriverio'); +const Application = require('spectron').Application; const source_root_dir = path.join(__dirname, '../..'); const electron_binary_path = (function() { @@ -16,26 +16,14 @@ const electron_binary_path = (function() { const config_file_path = path.join(source_root_dir, 'test/test_config.json'); const mattermost_url = 'http://example.com/team'; -var options = { - host: 'localhost', // Use localhost as chrome driver server - port: 9515, // "9515" is the port opened by chrome driver. - desiredCapabilities: { - browserName: 'chrome', - chromeOptions: { - binary: electron_binary_path, // Path to your Electron binary. - args: ['app=' + path.join(source_root_dir, 'dist'), '--config-file=' + config_file_path] // Optional, perhaps 'app=' + /path/to/your/app/ - } - } -}; - module.exports = { sourceRootDir: source_root_dir, configFilePath: config_file_path, mattermostURL: mattermost_url, - spawnChromeDriver: function() { - return require('child_process').spawn('node_modules/chromedriver/lib/chromedriver/chromedriver', ['--url-base=wd/hub', '--port=9515']); - }, - getWebDriverIoClient: function() { - return webdriverio.remote(options); + getSpectronApp: function() { + return new Application({ + path: electron_binary_path, + args: [`${path.join(source_root_dir, 'dist')}`, '--config-file=' + config_file_path] + }); } } diff --git a/test/specs/app_test.js b/test/specs/app_test.js index b74c9bb2..5192707b 100644 --- a/test/specs/app_test.js +++ b/test/specs/app_test.js @@ -9,49 +9,42 @@ const env = require('../modules/environment'); describe('application', function() { this.timeout(10000); - var chromedriver; - var client; before(function(done) { - chromedriver = env.spawnChromeDriver(); - client = env.getWebDriverIoClient(); - - fs.unlink(env.configFilePath, function(err) { - // waiting for chromedriver - setTimeout(done, 1000); + this.app = env.getSpectronApp(); + fs.unlink(env.configFilePath, () => { + done() }); }); afterEach(function() { - return client.end(); - }); - - after(function() { - chromedriver.kill(); + if (this.app && this.app.isRunning()) { + return this.app.stop() + } }); it('should show settings.html when there is no config file', function() { - return client - .init() - .pause(1000) - .getUrl().then(function(url) { - var p = path.parse(url); - p.base.should.equal('settings.html'); - }) - .end(); + return this.app.start().then(() => { + this.app.client + .pause(1000) + .getUrl().then(function(url) { + var p = path.parse(url); + p.base.should.equal('settings.html'); + }) + }); }); it('should show index.html when there is config file', function() { fs.writeFileSync(env.configFilePath, JSON.stringify({ url: env.mattermostURL })); - return client - .init() - .pause(1000) - .getUrl().then(function(url) { - var p = path.parse(url); - p.base.should.equal('index.html'); - }) - .end(); + return this.app.start().then(() => { + this.app.client + .pause(1000) + .getUrl().then(function(url) { + var p = path.parse(url); + p.base.should.equal('index.html'); + }); + }); }); it('should upgrade v0 config file', function() { @@ -59,17 +52,18 @@ describe('application', function() { fs.writeFileSync(env.configFilePath, JSON.stringify({ url: env.mattermostURL })); - return client - .init() - .pause(1000) - .getUrl().then(function(url) { - var p = path.parse(url); - p.base.should.equal('index.html'); - }) - .end().then(function() { - var str = fs.readFileSync(env.configFilePath, 'utf8'); - var config = JSON.parse(str); - config.version.should.equal(settings.version); - }); + return this.app.start().then(() => { + this.app.client + .pause(1000) + .getUrl().then(function(url) { + var p = path.parse(url); + p.base.should.equal('index.html'); + }) + .end().then(function() { + var str = fs.readFileSync(env.configFilePath, 'utf8'); + var config = JSON.parse(str); + config.version.should.equal(settings.version); + }); + }); }); }); diff --git a/test/specs/browser/index_test.js b/test/specs/browser/index_test.js index 8449bcdb..2a0915e0 100644 --- a/test/specs/browser/index_test.js +++ b/test/specs/browser/index_test.js @@ -20,15 +20,10 @@ describe('browser/index.html', function() { }] }; - var chromedriver; - var client; before(function(done) { - chromedriver = env.spawnChromeDriver(); - client = env.getWebDriverIoClient(); - + this.app = env.getSpectronApp(); fs.unlink(env.configFilePath, function(err) { - // waiting for chromedriver - setTimeout(done, 1000); + done(); }); }); @@ -37,70 +32,72 @@ describe('browser/index.html', function() { }); afterEach(function() { - return client.end(); - }); - - after(function() { - chromedriver.kill(); + if (this.app && this.app.isRunning()) { + return this.app.stop() + } }); it('should NOT show tabs when there is one team', function() { fs.writeFileSync(env.configFilePath, JSON.stringify({ url: env.mattermostURL })); - return client - .init() - .isExisting('#tabBar').then(function(isExisting) { - isExisting.should.be.false(); - }) - .end(); + return this.app.start().then(() => { + this.app.client + .init() + .isExisting('#tabBar').then(function(isExisting) { + isExisting.should.be.false(); + }); + }); }); it('should set src of webview from config file', function() { - return client - .init() - .getAttribute('#mattermostView0', 'src').then(function(attribute) { - attribute.should.equal(config.teams[0].url); - }) - .getAttribute('#mattermostView1', 'src').then(function(attribute) { - attribute.should.equal(config.teams[1].url); - }) - .isExisting('#mattermostView2').then(function(isExisting) { - isExisting.should.be.false(); - }) - .end(); + return this.app.start().then(() => { + this.app.client + .init() + .getAttribute('#mattermostView0', 'src').then(function(attribute) { + attribute.should.equal(config.teams[0].url); + }) + .getAttribute('#mattermostView1', 'src').then(function(attribute) { + attribute.should.equal(config.teams[1].url); + }) + .isExisting('#mattermostView2').then(function(isExisting) { + isExisting.should.be.false(); + }); + }); }); it('should set name of tab from config file', function() { - return client - .init() - .getText('#teamTabItem0').then(function(text) { - text.should.equal(config.teams[0].name); - }) - .getText('#teamTabItem1').then(function(text) { - text.should.equal(config.teams[1].name); - }) - .isExisting('#teamTabItem2').then(function(isExisting) { - isExisting.should.be.false(); - }) - .end(); + return this.app.start().then(() => { + this.app.client + .init() + .getText('#teamTabItem0').then(function(text) { + text.should.equal(config.teams[0].name); + }) + .getText('#teamTabItem1').then(function(text) { + text.should.equal(config.teams[1].name); + }) + .isExisting('#teamTabItem2').then(function(isExisting) { + isExisting.should.be.false(); + }); + }); }); it('should show only the selected team', function() { - return client - .init() - .pause(1000) - .waitForVisible('#mattermostView0', 1000) - .isVisible('#mattermostView1').then(function(visility) { - visility.should.be.false(); - }) - .click('#teamTabItem1') - .pause(1000) - .waitForVisible('#mattermostView1', 1000) - .isVisible('#mattermostView0').then(function(visility) { - visility.should.be.false(); - }) - .end(); + return this.app.start().then(() => { + this.app.client + .init() + .pause(1000) + .waitForVisible('#mattermostView0', 1000) + .isVisible('#mattermostView1').then(function(visility) { + visility.should.be.false(); + }) + .click('#teamTabItem1') + .pause(1000) + .waitForVisible('#mattermostView1', 1000) + .isVisible('#mattermostView0').then(function(visility) { + visility.should.be.false(); + }); + }); }); it('should show error when using incorrect URL', function() { @@ -112,9 +109,10 @@ describe('browser/index.html', function() { url: 'http://false' }] })); - return client - .init() - .waitForVisible('#mattermostView0-fail', 20000) - .end(); + return this.app.start().then(() => { + this.app.client + .init() + .waitForVisible('#mattermostView0-fail', 20000) + }); }); }); diff --git a/test/specs/browser/settings_test.js b/test/specs/browser/settings_test.js index 1cdf7f24..8ff90853 100644 --- a/test/specs/browser/settings_test.js +++ b/test/specs/browser/settings_test.js @@ -29,12 +29,9 @@ describe('browser/settings.html', function() { var chromedriver; var client; before(function(done) { - chromedriver = env.spawnChromeDriver(); - client = env.getWebDriverIoClient(); - + this.app = env.getSpectronApp(); fs.unlink(env.configFilePath, function(err) { - // waiting for chromedriver - setTimeout(done, 1000); + done(); }); }); @@ -43,50 +40,51 @@ describe('browser/settings.html', function() { }); afterEach(function() { - return client.end(); - }); - - after(function() { - chromedriver.kill(); + if (this.app && this.app.isRunning()) { + return this.app.stop() + } }); it('should show index.thml when Cancel button is clicked', function() { - return initClient(client) - .waitForExist('#btnCancel') - .click('#btnCancel') - .pause(1000) - .getUrl().then(function(url) { - var url_split = url.split('/'); - url_split[url_split.length - 1].should.equal('index.html'); - }) - .end(); + return this.app.start().then(() => { + initClient(this.app.client) + .waitForExist('#btnCancel') + .click('#btnCancel') + .pause(1000) + .getUrl().then(function(url) { + var url_split = url.split('/'); + url_split[url_split.length - 1].should.equal('index.html'); + }); + }); }); it('should show index.thml when Save button is clicked', function() { - return initClient(client) - .waitForExist('#btnSave') - .click('#btnSave') - .pause(1000) - .getUrl().then(function(url) { - var url_split = url.split('/'); - url_split[url_split.length - 1].should.equal('index.html'); - }) - .end(); + return this.app.start().then(() => { + initClient(this.app.client) + .waitForExist('#btnSave') + .click('#btnSave') + .pause(1000) + .getUrl().then(function(url) { + var url_split = url.split('/'); + url_split[url_split.length - 1].should.equal('index.html'); + }); + }); }); describe('Options', function() { describe('Hide Menu Bar', function() { it('should appear on win32 or linux', function() { - return initClient(client) - .isExisting('#inputHideMenuBar').then(function(isExisting) { - if (process.platform === 'win32' || process.platform === 'linux') { - isExisting.should.be.true(); - } - else { - isExisting.should.be.false(); - } - }) - .end(); + return this.app.start().then(() => { + initClient(this.app.client) + .isExisting('#inputHideMenuBar').then(function(isExisting) { + if (process.platform === 'win32' || process.platform === 'linux') { + isExisting.should.be.true(); + } + else { + isExisting.should.be.false(); + } + }); + }); }); if (process.platform === 'win32' || process.platform === 'linux') { @@ -96,24 +94,26 @@ describe('browser/settings.html', function() { Object.assign(new_config, config); new_config.hideMenuBar = v; fs.writeFileSync(env.configFilePath, JSON.stringify(new_config)); - return initClient(client) - .isSelected('#inputHideMenuBar input').then(function(value) { - value.should.equal(v); - }) - .end(); + return this.app.start().then(() => { + initClient(this.app.client) + .isSelected('#inputHideMenuBar input').then(function(value) { + value.should.equal(v); + }); + }); }); }); it('should be saved as config.json', function() { - return initClient(client) - .click('#inputHideMenuBar input') - .click('#btnSave') - .pause(1000) - .then(function() { - const saved_config = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8')); - saved_config.hideMenuBar.should.be.true(); - }) - .end(); + return this.app.start().then(() => { + initClient(this.app.client) + .click('#inputHideMenuBar input') + .click('#btnSave') + .pause(1000) + .then(function() { + const saved_config = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8')); + saved_config.hideMenuBar.should.be.true(); + }); + }); }); } }); From 05bcda5eabd24792bdcd7b3c09b02c0ceaa5e7e1 Mon Sep 17 00:00:00 2001 From: Yuya Ochiai Date: Sat, 21 May 2016 20:57:59 +0900 Subject: [PATCH 2/4] Test actual behavior for Hide Menu Bar --- test/modules/environment.js | 8 +++++ test/specs/browser/settings_test.js | 49 +++++++++++++++-------------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/test/modules/environment.js b/test/modules/environment.js index e5dd654d..ec7bcd55 100644 --- a/test/modules/environment.js +++ b/test/modules/environment.js @@ -25,5 +25,13 @@ module.exports = { path: electron_binary_path, args: [`${path.join(source_root_dir, 'dist')}`, '--config-file=' + config_file_path] }); + }, + shouldTestForPlatforms: function(testCase, platforms) { + if (platforms.indexOf(process.platform) !== -1) { + return; + } + else { + testCase.skip(); + } } } diff --git a/test/specs/browser/settings_test.js b/test/specs/browser/settings_test.js index 8ff90853..e0877669 100644 --- a/test/specs/browser/settings_test.js +++ b/test/specs/browser/settings_test.js @@ -87,35 +87,36 @@ describe('browser/settings.html', function() { }); }); - if (process.platform === 'win32' || process.platform === 'linux') { - [true, false].forEach(function(v) { - it(`should be loaded from config: ${v}`, function() { - var new_config = {}; - Object.assign(new_config, config); - new_config.hideMenuBar = v; - fs.writeFileSync(env.configFilePath, JSON.stringify(new_config)); - return this.app.start().then(() => { - initClient(this.app.client) - .isSelected('#inputHideMenuBar input').then(function(value) { - value.should.equal(v); - }); - }); - }); - }); - - it('should be saved as config.json', function() { + [true, false].forEach(function(v) { + it(`should be loaded from config: ${v}`, function() { + env.shouldTestForPlatforms(this, ['win32', 'linux']); + var new_config = {}; + Object.assign(new_config, config); + new_config.hideMenuBar = v; + fs.writeFileSync(env.configFilePath, JSON.stringify(new_config)); return this.app.start().then(() => { initClient(this.app.client) - .click('#inputHideMenuBar input') - .click('#btnSave') - .pause(1000) - .then(function() { - const saved_config = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8')); - saved_config.hideMenuBar.should.be.true(); + .isSelected('#inputHideMenuBar input').then(function(value) { + value.should.equal(v); + this.app.browserWindow.isMenuBarAutoHide().should.equal(v); }); }); }); - } + }); + + it('should be saved as config.json', function() { + env.shouldTestForPlatforms(this, ['win32', 'linux']); + return this.app.start().then(() => { + initClient(this.app.client) + .click('#inputHideMenuBar input') + .click('#btnSave') + .pause(1000) + .then(function() { + const saved_config = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8')); + saved_config.hideMenuBar.should.be.true(); + }); + }); + }); }); }); }); From 29c53aa992e5369b7eee4cb411e41244134cd9ad Mon Sep 17 00:00:00 2001 From: Yuya Ochiai Date: Mon, 6 Jun 2016 00:38:17 +0900 Subject: [PATCH 3/4] Fix test command --- circle.yml | 3 --- package.json | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/circle.yml b/circle.yml index 04e77398..641d3863 100644 --- a/circle.yml +++ b/circle.yml @@ -31,9 +31,6 @@ dependencies: - cp release/*.deb $CIRCLE_ARTIFACTS/ test: - override: - - node_modules/.bin/mocha --reporter mocha-circleci-reporter - - node_modules/.bin/gulp prettify:verify post: - mv test-results.xml $CIRCLE_TEST_REPORTS/ diff --git a/package.json b/package.json index 62c85629..c15879d1 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "start": "electron dist", "watch": "gulp watch", "serve": "gulp watch", - "test": "gulp build && mocha --recursive test/specs && gulp prettify:verify", + "test": "gulp build && mocha --reporter mocha-circleci-reporter --recursive test/specs && gulp prettify:verify", "package": "gulp package", "package:windows": "gulp package:windows", "package:osx": "gulp package:osx", From e9f8140594507481eec531c2691c39271a26082d Mon Sep 17 00:00:00 2001 From: Yuya Ochiai Date: Mon, 6 Jun 2016 00:41:35 +0900 Subject: [PATCH 4/4] Rewrite tests with chai-as-promised --- package.json | 3 +- test/modules/environment.js | 11 +++- test/specs/app_test.js | 47 +++++++-------- test/specs/browser/index_test.js | 79 +++++++------------------- test/specs/browser/settings_test.js | 88 ++++++++++------------------- test/specs/settings_test.js | 1 - 6 files changed, 83 insertions(+), 146 deletions(-) diff --git a/package.json b/package.json index c15879d1..5e437366 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,8 @@ "babel-core": "^6.7.5", "babel-loader": "^6.2.4", "babel-preset-react": "^6.5.0", + "chai": "^3.5.0", + "chai-as-promised": "^5.3.0", "del": "^2.2.0", "electron-builder": "^3.11.0", "electron-connect": "^0.3.7", @@ -46,7 +48,6 @@ "json-loader": "^0.5.4", "mocha": "^2.3.4", "mocha-circleci-reporter": "0.0.1", - "should": "^8.0.1", "spectron": "~3.0.0", "style-loader": "^0.13.0", "through2": "^2.0.1", diff --git a/test/modules/environment.js b/test/modules/environment.js index ec7bcd55..fac7b1f5 100644 --- a/test/modules/environment.js +++ b/test/modules/environment.js @@ -1,5 +1,12 @@ 'use strict'; +const chai = require('chai'); +const chaiAsPromised = require('chai-as-promised'); + +chai.should(); +chai.use(chaiAsPromised); + + const path = require('path'); const Application = require('spectron').Application; @@ -21,10 +28,12 @@ module.exports = { configFilePath: config_file_path, mattermostURL: mattermost_url, getSpectronApp: function() { - return new Application({ + const app = new Application({ path: electron_binary_path, args: [`${path.join(source_root_dir, 'dist')}`, '--config-file=' + config_file_path] }); + chaiAsPromised.transferPromiseness = app.transferPromiseness + return app; }, shouldTestForPlatforms: function(testCase, platforms) { if (platforms.indexOf(process.platform) !== -1) { diff --git a/test/specs/app_test.js b/test/specs/app_test.js index 5192707b..a9660578 100644 --- a/test/specs/app_test.js +++ b/test/specs/app_test.js @@ -1,6 +1,5 @@ 'use strict'; -const should = require('should'); const path = require('path'); const fs = require('fs'); @@ -9,10 +8,10 @@ const env = require('../modules/environment'); describe('application', function() { this.timeout(10000); - before(function(done) { + beforeEach(function(done) { this.app = env.getSpectronApp(); fs.unlink(env.configFilePath, () => { - done() + done(); }); }); @@ -22,14 +21,19 @@ describe('application', function() { } }); + it('should show a window', function() { + return this.app.start().then(() => { + return this.app.client.waitUntilWindowLoaded() + .getWindowCount().should.eventually.equal(1) + .browserWindow.isDevToolsOpened().should.eventually.be.false + .browserWindow.isVisible().should.eventually.be.true + }); + }); + it('should show settings.html when there is no config file', function() { return this.app.start().then(() => { - this.app.client - .pause(1000) - .getUrl().then(function(url) { - var p = path.parse(url); - p.base.should.equal('settings.html'); - }) + return this.app.client.waitUntilWindowLoaded() + .getUrl().should.eventually.match(/\/settings.html$/) }); }); @@ -38,12 +42,8 @@ describe('application', function() { url: env.mattermostURL })); return this.app.start().then(() => { - this.app.client - .pause(1000) - .getUrl().then(function(url) { - var p = path.parse(url); - p.base.should.equal('index.html'); - }); + return this.app.client.waitUntilWindowLoaded() + .getUrl().should.eventually.match(/\/index.html$/) }); }); @@ -53,17 +53,12 @@ describe('application', function() { url: env.mattermostURL })); return this.app.start().then(() => { - this.app.client - .pause(1000) - .getUrl().then(function(url) { - var p = path.parse(url); - p.base.should.equal('index.html'); - }) - .end().then(function() { - var str = fs.readFileSync(env.configFilePath, 'utf8'); - var config = JSON.parse(str); - config.version.should.equal(settings.version); - }); + return this.app.client.waitUntilWindowLoaded() + .getUrl().should.eventually.match(/\/index.html$/) + }).then(function() { + var str = fs.readFileSync(env.configFilePath, 'utf8'); + var config = JSON.parse(str); + config.version.should.equal(settings.version); }); }); }); diff --git a/test/specs/browser/index_test.js b/test/specs/browser/index_test.js index 2a0915e0..8147294c 100644 --- a/test/specs/browser/index_test.js +++ b/test/specs/browser/index_test.js @@ -1,6 +1,5 @@ 'use strict'; -const should = require('should'); const path = require('path'); const fs = require('fs'); @@ -20,15 +19,10 @@ describe('browser/index.html', function() { }] }; - before(function(done) { - this.app = env.getSpectronApp(); - fs.unlink(env.configFilePath, function(err) { - done(); - }); - }); - beforeEach(function() { fs.writeFileSync(env.configFilePath, JSON.stringify(config)); + this.app = env.getSpectronApp(); + return this.app.start(); }); afterEach(function() { @@ -41,63 +35,33 @@ describe('browser/index.html', function() { fs.writeFileSync(env.configFilePath, JSON.stringify({ url: env.mattermostURL })); - return this.app.start().then(() => { - this.app.client - .init() - .isExisting('#tabBar').then(function(isExisting) { - isExisting.should.be.false(); - }); + return this.app.restart().then(() => { + return this.app.client.waitUntilWindowLoaded() + .isExisting('#tabBar').should.eventually.be.false }); }); it('should set src of webview from config file', function() { - return this.app.start().then(() => { - this.app.client - .init() - .getAttribute('#mattermostView0', 'src').then(function(attribute) { - attribute.should.equal(config.teams[0].url); - }) - .getAttribute('#mattermostView1', 'src').then(function(attribute) { - attribute.should.equal(config.teams[1].url); - }) - .isExisting('#mattermostView2').then(function(isExisting) { - isExisting.should.be.false(); - }); - }); + return this.app.client.waitUntilWindowLoaded() + .getAttribute('#mattermostView0', 'src').should.eventually.equal(config.teams[0].url) + .getAttribute('#mattermostView1', 'src').should.eventually.equal(config.teams[1].url) + .isExisting('#mattermostView2').should.eventually.be.false }); it('should set name of tab from config file', function() { - return this.app.start().then(() => { - this.app.client - .init() - .getText('#teamTabItem0').then(function(text) { - text.should.equal(config.teams[0].name); - }) - .getText('#teamTabItem1').then(function(text) { - text.should.equal(config.teams[1].name); - }) - .isExisting('#teamTabItem2').then(function(isExisting) { - isExisting.should.be.false(); - }); - }); + return this.app.client.waitUntilWindowLoaded() + .getText('#teamTabItem0').should.eventually.equal(config.teams[0].name) + .getText('#teamTabItem1').should.eventually.equal(config.teams[1].name) }); it('should show only the selected team', function() { - return this.app.start().then(() => { - this.app.client - .init() - .pause(1000) - .waitForVisible('#mattermostView0', 1000) - .isVisible('#mattermostView1').then(function(visility) { - visility.should.be.false(); - }) - .click('#teamTabItem1') - .pause(1000) - .waitForVisible('#mattermostView1', 1000) - .isVisible('#mattermostView0').then(function(visility) { - visility.should.be.false(); - }); - }); + return this.app.client.waitUntilWindowLoaded() + .isVisible('#mattermostView0').should.eventually.be.true + .isVisible('#mattermostView1').should.eventually.be.false + .click('#teamTabItem1') + .pause(1000) + .isVisible('#mattermostView1').should.eventually.be.true + .isVisible('#mattermostView0').should.eventually.be.false }); it('should show error when using incorrect URL', function() { @@ -109,9 +73,8 @@ describe('browser/index.html', function() { url: 'http://false' }] })); - return this.app.start().then(() => { - this.app.client - .init() + return this.app.restart().then(() => { + return this.app.client.waitUntilWindowLoaded() .waitForVisible('#mattermostView0-fail', 20000) }); }); diff --git a/test/specs/browser/settings_test.js b/test/specs/browser/settings_test.js index e0877669..0ebf9e28 100644 --- a/test/specs/browser/settings_test.js +++ b/test/specs/browser/settings_test.js @@ -1,6 +1,5 @@ 'use strict'; -const should = require('should'); const path = require('path'); const fs = require('fs'); @@ -8,8 +7,8 @@ const env = require('../../modules/environment'); function initClient(client) { return client - .init() - .url('file://' + path.join(env.sourceRootDir, 'dist/browser/settings.html')); + .url('file://' + path.join(env.sourceRootDir, 'dist/browser/settings.html')) + .waitUntilWindowLoaded(); } describe('browser/settings.html', function() { @@ -26,17 +25,10 @@ describe('browser/settings.html', function() { }] }; - var chromedriver; - var client; - before(function(done) { - this.app = env.getSpectronApp(); - fs.unlink(env.configFilePath, function(err) { - done(); - }); - }); - beforeEach(function() { fs.writeFileSync(env.configFilePath, JSON.stringify(config)); + this.app = env.getSpectronApp(); + return this.app.start(); }); afterEach(function() { @@ -46,45 +38,25 @@ describe('browser/settings.html', function() { }); it('should show index.thml when Cancel button is clicked', function() { - return this.app.start().then(() => { - initClient(this.app.client) - .waitForExist('#btnCancel') - .click('#btnCancel') - .pause(1000) - .getUrl().then(function(url) { - var url_split = url.split('/'); - url_split[url_split.length - 1].should.equal('index.html'); - }); - }); + return initClient(this.app.client) + .click('#btnCancel') + .pause(1000) + .getUrl().should.eventually.match(/\/index.html$/) }); it('should show index.thml when Save button is clicked', function() { - return this.app.start().then(() => { - initClient(this.app.client) - .waitForExist('#btnSave') - .click('#btnSave') - .pause(1000) - .getUrl().then(function(url) { - var url_split = url.split('/'); - url_split[url_split.length - 1].should.equal('index.html'); - }); - }); + return initClient(this.app.client) + .click('#btnSave') + .pause(1000) + .getUrl().should.eventually.match(/\/index.html$/) }); describe('Options', function() { describe('Hide Menu Bar', function() { it('should appear on win32 or linux', function() { - return this.app.start().then(() => { - initClient(this.app.client) - .isExisting('#inputHideMenuBar').then(function(isExisting) { - if (process.platform === 'win32' || process.platform === 'linux') { - isExisting.should.be.true(); - } - else { - isExisting.should.be.false(); - } - }); - }); + const expected = (process.platform === 'win32' || process.platform === 'linux'); + return initClient(this.app.client) + .isExisting('#inputHideMenuBar').should.eventually.equal(expected) }); [true, false].forEach(function(v) { @@ -94,28 +66,26 @@ describe('browser/settings.html', function() { Object.assign(new_config, config); new_config.hideMenuBar = v; fs.writeFileSync(env.configFilePath, JSON.stringify(new_config)); - return this.app.start().then(() => { - initClient(this.app.client) - .isSelected('#inputHideMenuBar input').then(function(value) { - value.should.equal(v); - this.app.browserWindow.isMenuBarAutoHide().should.equal(v); - }); + return this.app.restart().then(() => { + return initClient(this.app.client) + .isSelected('#inputHideMenuBar input').should.eventually.equal(v) + .browserWindow.isMenuBarAutoHide().should.eventually.equal(v); }); }); }); it('should be saved as config.json', function() { env.shouldTestForPlatforms(this, ['win32', 'linux']); - return this.app.start().then(() => { - initClient(this.app.client) - .click('#inputHideMenuBar input') - .click('#btnSave') - .pause(1000) - .then(function() { - const saved_config = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8')); - saved_config.hideMenuBar.should.be.true(); - }); - }); + return this.app.restart().then(() => { + return initClient(this.app.client) + .click('#inputHideMenuBar input') + .click('#btnSave') + .pause(1000) + }) + .then(() => { + const saved_config = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8')); + saved_config.hideMenuBar.should.be.true; + }); }); }); }); diff --git a/test/specs/settings_test.js b/test/specs/settings_test.js index 499dee9a..e647968e 100644 --- a/test/specs/settings_test.js +++ b/test/specs/settings_test.js @@ -1,4 +1,3 @@ -const should = require('should'); const fs = require('fs'); const settings = require('../../src/common/settings');