Skip to content
This repository has been archived by the owner on Feb 18, 2021. It is now read-only.

Commit

Permalink
Merge pull request #121 from protonmail-desktop/travis-customization
Browse files Browse the repository at this point in the history
Run e2e tests with Travis
  • Loading branch information
mtaberna committed Sep 8, 2017
2 parents 167ded6 + 34eb85a commit 4082d3f
Show file tree
Hide file tree
Showing 10 changed files with 1,782 additions and 1,575 deletions.
1 change: 0 additions & 1 deletion .dockerignore

This file was deleted.

30 changes: 23 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,33 @@ os:
- linux
- osx

node_js:
- "4"
osx_image: xcode8.3

language: node_js

node_js: 8

before_script:
- chmod +x ./scripts/travis-build.sh
# Workaround for prevent MacOS job failure, https://github.com/travis-ci/travis-ci/issues/6307
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then rvm get stable; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install rpm; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export DISPLAY=:99.0; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sh -e /etc/init.d/xvfb start; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sleep 3; fi

after_failure:
- curl -sL https://raw.githubusercontent.com/travis-ci/artifacts/master/install | bash
- artifacts upload $(git ls-files -o | grep -Fv -e node_modules -e dist -e app -e e2e)
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then artifacts upload $(ls $(npm config get cache)/_logs/); fi

script: ./scripts/travis-build.sh
install:
- npm install

cache:
directories:
- node_modules
script:
- node --version
- npm --version
- npm run e2e

notifications:
email:
Expand Down
15 changes: 0 additions & 15 deletions Dockerfile

This file was deleted.

15 changes: 8 additions & 7 deletions e2e/multiple-accounts.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,32 @@ import { AddCommands } from './commands';

describe('multiple accounts', function () {
this.timeout(20000);

beforeEach(testUtils.beforeEach);
afterEach(testUtils.afterEach);

it('creates a new tab when account is added', function () {
const accountName = 'awesomeMail';

return this.app.client.waitUntilWindowLoaded()
.waitForVisible('button.add-account', 10000)
.then(() => this.app.client.waitForVisible('button.add-account', 10000))
.click('button.add-account')
.waitForVisible('.sweet-alert input[type=text]')
.then(() => this.app.client.waitForVisible('.sweet-alert input[type=text]'))
.setValue('.sweet-alert input[type=text]', accountName)
.pause(200)
.pause(500)
.click('button.confirm')
.pause(200)
.pause(500)
.getText('.etabs-tabs .etabs-tab-title')
.then(text => {
expect(typeof text).equal('string');
expect(text.toLowerCase()).equal(accountName.slice(0, 1).toLowerCase());
})
.windowByIndex(1)
.waitForVisible('#pm_login #username')
.then(() => this.app.client.waitForVisible('#pm_login #username'))
.getValue('#pm_login #username')
.then(username => {
expect(username).equal(accountName);
});
})
.catch(testUtils.saveErrorShot.bind(this));
});
});
21 changes: 10 additions & 11 deletions e2e/unread-notifications-count.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import { expect } from 'chai';
import testUtils from './utils';
import { AddCommands } from './commands';

const path = require('path');

(process.env.PROTONMAIL_TEST_USERNAME ? describe : describe.skip)('unread notifications', function () {
const expectUnreadEmails = 2;
this.timeout(200000);

beforeEach(testUtils.beforeEach);
afterEach(testUtils.afterEach);

it('should display accurate unread emails in the sidebar', async function () {
AddCommands.addAccount.call(this);
/**
Expand All @@ -19,28 +17,29 @@ const path = require('path');
*/
await this.app.client.addAccount(process.env.PROTONMAIL_TEST_USERNAME);
await this.app.client.addAccount(process.env.PROTONMAIL_TEST_USERNAME);

return this.app.client
.click('.etabs-tabs .etabs-tab:first-child')
.pause(1000)
.pause(5000)
.keys(['Tab'])
.pause(1000)
.keys(process.env.PROTONMAIL_TEST_PASSWORD)
.pause(1000)
.keys(['Enter'])
.pause(5000)
.pause(10000)
/**
* Protonmail wont show unread emails in the title immediately,
* therefore we need to visit the draft folder first
*/
.keys('gd')
.pause(1000)
.pause(2000)
.keys('gi')
.waitForVisible('.etabs-tabs .etabs-tab-badge')
.getText('.etabs-tabs .etabs-tab-badge')
.then(() => this.app.client.waitForVisible('.etabs-tabs .etabs-tab-badge'))
.then(() => this.app.client.getText('.etabs-tabs .etabs-tab-badge'))
.then(text => {
expect(Number(text[0])).equal(expectUnreadEmails);
expect(text[1]).equal('');
});
})
.catch(testUtils.saveErrorShot.bind(this));
});
});
23 changes: 22 additions & 1 deletion e2e/utils.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { Application } from 'spectron';

const path = require('path');
const fs = require('fs');
const electron = require('electron');

const beforeEach = function (env = {}) {
this.timeout(50000);
this.app = new Application({
path: path.resolve('dist/linux-unpacked/protonmail-desktop'),
path: electron,
args: ['.'],
startTimeout: 50000,
waitTimeout: 50000,
chromeDriverLogPath: process.cwd().concat('chrome-driver.log'),
webdriverLogPath: process.cwd(),
env: Object.assign(env, {
DEBUG: 'false',
NAME: 'test',
Expand All @@ -26,7 +30,24 @@ const afterEach = function () {
return undefined;
};

const saveErrorShot = function (e) {
const filename = `errorShot-${this.test.parent.title}-${this.test.title}-${new Date().toISOString()}.png`
.replace(/\s/g, '_')
.replace(/:/g, '');

this.app.browserWindow.capturePage().then(imageBuffer => {
fs.writeFile(filename, imageBuffer, error => {
if (error) throw error;

console.info(`Screenshot saved: ${process.cwd()}/${filename}`);
});
});

throw e;
};

export default {
beforeEach,
afterEach,
saveErrorShot,
};
Loading

0 comments on commit 4082d3f

Please sign in to comment.