Skip to content

Commit

Permalink
chore(tests): e2e tests
Browse files Browse the repository at this point in the history
Travis only runs a subset of tests via `npm run test_travis`, but `npm test` runs a full suite.
See angular#165 for details on why travis cannot run
all tests.
  • Loading branch information
sjelin committed Nov 25, 2016
1 parent 27e9413 commit 73c27e8
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ lib/
selenium/
spec/
built/spec/
e2e_spec/
built/e2e_spec/

.clang-format
.gitattributes
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ before_install:

script:
- npm run check_format
- npm test
- npm run test_travis
56 changes: 56 additions & 0 deletions e2e_spec/browser_spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import * as os from 'os';
import * as webdriver from 'selenium-webdriver';
import {AndroidSDK} from '../lib/binaries'

let browsers: string[] = require('./target_browsers')[os.type()];
let versions: {androidsdk: string, appium: string} = require('../config.json').webdriverVersions;


describe('browser smoke tests', () => {
browsers.forEach((browserName) => {
if (browserName == 'android') {
it('should be able to boot up android chrome', (done) => {
let driver =
new webdriver.Builder()
.usingServer('http://localhost:4723/wd/hub')
.withCapabilities({
browserName: 'chrome',
platformName: 'Android',
platformVersion:
AndroidSDK.VERSIONS[parseInt(AndroidSDK.DEFAULT_API_LEVELS.split(',')[0])],
deviceName: 'Android Emulator'
})
.build();
driver.get('http://10.0.2.2:4723/wd/hub/status')
.then(() => {
return driver.getPageSource();
})
.then((source: string) => {
expect(source).toContain('"status":0');
return driver.quit();
})
.then(() => {
done();
});
}, 60 * 1000);
} else {
it('should be able to boot up ' + browserName, (done) => {
let driver = new webdriver.Builder()
.usingServer('http://localhost:4444/wd/hub')
.withCapabilities({browserName: browserName})
.build();
driver.get('http://localhost:4444/selenium-server/driver/?cmd=getLogMessages')
.then(() => {
return driver.getPageSource();
})
.then((source: string) => {
expect(source).toContain('OK');
return driver.quit();
})
.then(() => {
done();
});
});
}
});
});
28 changes: 28 additions & 0 deletions e2e_spec/server_spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as http from 'http';


describe('sever smoke tests', () => {
it('should be able to ping selenium server', (done) => {
http.get('http://localhost:4444/selenium-server/driver/?cmd=getLogMessages', (resp) => {
expect(resp.statusCode).toBe(200);
let logs = '';
resp.on('data', (chunk) => logs += chunk);
resp.on('end', () => {
expect(logs).toContain('OK');
done()
});
});
});

it('should be able to ping appium server', (done) => {
http.get('http://localhost:4723/wd/hub/status', (resp) => {
expect(resp.statusCode).toBe(200);
let data = '';
resp.on('data', (chunk) => data += chunk);
resp.on('end', () => {
expect(JSON.parse(data).status).toBe(0);
done()
});
});
});
});
8 changes: 8 additions & 0 deletions e2e_spec/support/jasmine.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"spec_dir": "built/e2e_spec",
"spec_files": [
"**/*_spec.js"
],
"stopSpecOnExpectationFailure": false,
"random": false
}
8 changes: 8 additions & 0 deletions e2e_spec/support/no_screen.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"spec_dir": "built/e2e_spec",
"spec_files": [
"**/server_spec.js"
],
"stopSpecOnExpectationFailure": false,
"random": false
}
3 changes: 3 additions & 0 deletions e2e_spec/target_browsers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export let Linux = ['chrome', 'firefox', 'android'];
export let Darwin = ['chrome', 'firefox', 'android'];
export let Windows_NT = ['chrome', 'firefox', 'internet explorer'];
72 changes: 57 additions & 15 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
'use strict';

var path = require('path');
var gulp = require('gulp');
var runSequence = require('run-sequence');
var spawn = require('child_process').spawn;

var runSpawn = function(done, task, opt_arg) {
opt_arg = typeof opt_arg !== 'undefined' ? opt_arg : [];
var child = spawn(task, opt_arg, {stdio: 'inherit'});
var runSpawn = function(task, args, done) {
done = done || function() {};
var child = spawn(task, args, {stdio: 'inherit'});
var running = false;
child.on('close', function() {
child.on('close', function(code) {
if (!running) {
running = true;
done();
done(code);
}
});
child.on('error', function() {
child.on('error', function(err) {
if (!running) {
console.error('gulp encountered a child error');
running = true;
done();
done(err || 1);
}
});
return child;
};

// Build
gulp.task('copy', function() {
return gulp.src(['config.json', 'package.json'])
.pipe(gulp.dest('built/'));
});

var tsGlobs = ['lib/**/*.ts', 'spec/**/*.ts'];
var tsGlobs = ['lib/**/*.ts', '*spec/**/*.ts'];

gulp.task('format:enforce', () => {
const format = require('gulp-clang-format');
Expand All @@ -45,18 +48,57 @@ gulp.task('format', () => {
});

gulp.task('tsc', function(done) {
runSpawn(done, process.execPath, ['node_modules/typescript/bin/tsc']);
runSpawn(process.execPath, ['node_modules/typescript/bin/tsc'], done);
});

gulp.task('prepublish', function(done) {
runSequence('tsc', 'copy', done);
});

gulp.task('default',['prepublish']);
gulp.task('build',['prepublish']);
gulp.task('default', ['prepublish']);
gulp.task('build', ['prepublish']);

gulp.task('test', ['format', 'build'], function(done) {
var opt_arg = [];
opt_arg.push('node_modules/jasmine/bin/jasmine.js');
runSpawn(done, process.execPath, opt_arg);
// Command line commands
gulp.task('update', ['build'], function(done) {
runSpawn(process.execPath, ['bin/webdriver-manager', 'update', '--android',
'--android-accept-licenses'], done);
});
gulp.task('start', ['build', 'shutdown'], function(done) {
runSpawn(process.execPath, ['bin/webdriver-manager', 'start', '--detach', '--seleniumPort',
'4444', '--android', '--appium-port', '4723', '--quiet'], done);
});
gulp.task('start:no_screen', ['build', 'shutdown'], function(done) {
runSpawn(process.execPath, ['bin/webdriver-manager', 'start', '--detach', '--seleniumPort',
'4444', '--android', '--appium-port', '4723', '--quiet', '--avds', 'none'], done);
});
gulp.task('shutdown', ['build'], function(done) {
runSpawn(process.execPath, ['bin/webdriver-manager', 'shutdown'], done);
});

// Test
gulp.task('test:unit', ['build'], function(done) {
runSpawn(process.execPath, ['node_modules/jasmine/bin/jasmine.js'], done);
});

gulp.task('test:e2e:inner', ['build'], function(done) {
runSpawn(process.execPath, ['node_modules/jasmine/bin/jasmine.js', 'JASMINE_CONFIG_PATH=' +
path.join('e2e_spec', 'support', 'jasmine.json')], done);
});
gulp.task('test:e2e:inner:no_screen', ['build'], function(done) {
runSpawn(process.execPath, ['node_modules/jasmine/bin/jasmine.js', 'JASMINE_CONFIG_PATH=' +
path.join('e2e_spec', 'support', 'no_screen.json')], done);
});
gulp.task('test:e2e:no_update', function(done) {
runSequence('start', 'test:e2e:inner', 'shutdown', done);
});
gulp.task('test:e2e', function(done) {
runSequence('update', 'test:e2e:no_update', done);
});
gulp.task('test:e2e:no_screen', function(done) {
runSequence('update', 'start:no_screen', 'test:e2e:inner:no_screen', 'shutdown', done);
});


gulp.task('test', ['format', 'test:unit', 'test:e2e']);
gulp.task('test:no_update', ['format', 'test:unit', 'test:e2e:no_update']);
gulp.task('test:no_screen', ['format', 'test:unit', 'test:e2e:no_screen']);
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"check_format": "gulp format:enforce",
"format": "gulp format",
"prepublish": "gulp prepublish",
"test": "gulp test"
"test": "gulp test",
"test_travis": "gulp test:no_screen"
},
"keywords": [
"angular",
Expand Down Expand Up @@ -53,12 +54,14 @@
"@types/q": "^0.0.32",
"@types/request": "^0.0.33",
"@types/rimraf": "^0.0.28",
"@types/selenium-webdriver": "^2.53.35",
"@types/semver": "^5.3.30",
"clang-format": "^1.0.35",
"gulp": "^3.9.1",
"gulp-clang-format": "^1.0.23",
"jasmine": "^2.4.1",
"run-sequence": "^1.1.5",
"selenium-webdriver": "2.53.1",
"typescript": "^2.1.1"
}
}

0 comments on commit 73c27e8

Please sign in to comment.