From cb0cd770c2dfb4605e14743e9833dc3e3957e9cf Mon Sep 17 00:00:00 2001 From: "grant_gayed@ca.ibm.com grant_gayed@ca.ibm.com" Date: Wed, 3 Feb 2016 11:26:26 +0000 Subject: [PATCH] Revert "Revert "added tests to UI"" This reverts commit 5a398e46c4f4e91c62492abf9383b672acd0a8da. --- Gruntfile.js | 87 +++++++++++++++++++++++++++++++++ desireds.js | 7 +++ package.json | 24 ++++++++++ test/test-cases.js | 98 ++++++++++++++++++++++++++++++++++++++ tests_actual/test-cases.js | 98 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 314 insertions(+) create mode 100644 Gruntfile.js create mode 100644 desireds.js create mode 100644 package.json create mode 100644 test/test-cases.js create mode 100644 tests_actual/test-cases.js diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..1928678 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,87 @@ +'use strict'; + +var _ = require('lodash'); + +var desireds = require('./desireds'); + +var gruntConfig = { + env: { + // dynamically filled + }, + simplemocha: { + sauce: { + options: { + timeout: 60000, + reporter: 'spec-xunit-file', + }, + src: ['tests_actual/test-cases.js'] + }, + sauce_node: { + options: { + timeout: 60000, + reporter: 'spec-xunit-file', + }, + src: ['test/test-cases.js'] + } + }, + jshint: { + options: { + jshintrc: '.jshintrc' + }, + gruntfile: { + src: 'Gruntfile.js' + }, + test: { + options: { + jshintrc: 'test/.jshintrc' + }, + src: ['test/*.js'] + }, + }, + concurrent: { + 'test-sauce': [], // dynamically filled + }, + watch: { + gruntfile: { + files: '<%= jshint.gruntfile.src %>', + tasks: ['jshint:gruntfile'] + }, + test: { + files: '<%= jshint.test.src %>', + tasks: ['jshint:test'] + }, + }, + }; + +_.forIn(desireds,function(desired, key) { + gruntConfig.env[key] = { + DESIRED: JSON.stringify(desired) + }; + //gruntConfig.concurrent['test-sauce'].push('test:sauce:' + key); +}); + +//console.log(gruntConfig); + +module.exports = function(grunt) { + + // Project configuration. + grunt.initConfig(gruntConfig); + + // These plugins provide necessary tasks. + grunt.loadNpmTasks('grunt-env'); + grunt.loadNpmTasks('grunt-simple-mocha'); + grunt.loadNpmTasks('grunt-concurrent'); + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-contrib-watch'); + + // Default task. + grunt.registerTask('default', ['test:sauce:' + _(desireds).keys().first()]); + grunt.registerTask('test_real', ['env:chrome', 'simplemocha:sauce:' + _(desireds).keys().first()]); + grunt.registerTask('test_fake', ['env:chrome', 'simplemocha:sauce_node:' + _(desireds).keys().first()]); + + // _.forIn(desireds,function(desired, key) { + // grunt.registerTask('test:sauce:' + key, ['env:' + key, 'simplemocha:sauce']); + // }); + + // grunt.registerTask('test', ['concurrent:test-sauce']); +}; diff --git a/desireds.js b/desireds.js new file mode 100644 index 0000000..eeac1aa --- /dev/null +++ b/desireds.js @@ -0,0 +1,7 @@ +'use strict'; + +module.exports = { + chrome: {browserName: 'chrome'}, + firefox: {browserName: 'firefox'}, + explorer: {browserName: 'internet explorer'} +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..3be6767 --- /dev/null +++ b/package.json @@ -0,0 +1,24 @@ +{ + "name": "MicroUITests", + "version": "0.1.5", + "description": "tests", + "dependencies": { + "express": "~4.12.0", + "chai": "latest", + "chai-as-promised": "latest", + "colors": "latest", + "grunt": "~0.4.5", + "grunt-concurrent": "latest", + "grunt-contrib-jshint": "latest", + "grunt-contrib-watch": "latest", + "grunt-env": "latest", + "grunt-simple-mocha": "latest", + "lodash": "latest", + "mocha": "^2.3.3", + "spec-xunit-file": "0.0.1-3", + "wd": "latest" + }, + "engines": { + "node": "0.10.38" + } +} \ No newline at end of file diff --git a/test/test-cases.js b/test/test-cases.js new file mode 100644 index 0000000..66dac2a --- /dev/null +++ b/test/test-cases.js @@ -0,0 +1,98 @@ +var wd = require('wd'); +require('colors'); +var _ = require("lodash"); +var chai = require("chai"); +var chaiAsPromised = require("chai-as-promised"); +var url = "https://nodejs.org";//process.env.APP_URL; + +chai.use(chaiAsPromised); +chai.should(); +chaiAsPromised.transferPromiseness = wd.transferPromiseness; + +// checking sauce credential +if(!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY){ + console.warn( + '\nPlease configure your sauce credential:\n\n' + + 'export SAUCE_USERNAME=\n' + + 'export SAUCE_ACCESS_KEY=\n\n' + ); + throw new Error("Missing sauce credentials"); +} + +// http configuration, not needed for simple runs +wd.configureHttp( { + timeout: 60000, + retryDelay: 15000, + retries: 5 +}); + +var desired = JSON.parse(process.env.DESIRED || '{browserName: "chrome"}'); +desired.name = 'MicroUI with ' + desired.browserName; +desired.tags = ['MicroUI']; + +describe('MicroUI(' + desired.browserName + ')', function() { + var browser; + var allPassed = true; + + before(function(done) { + var username = process.env.SAUCE_USERNAME; + var accessKey = process.env.SAUCE_ACCESS_KEY; + browser = wd.promiseChainRemote(process.env.HOST, process.env.PORT, username, accessKey); + if(process.env.VERBOSE){ + // optional logging + browser.on('status', function(info) { + console.log(info.cyan); + }); + browser.on('command', function(meth, path, data) { + console.log(' > ' + meth.yellow, path.grey, data || ''); + }); + } + browser + .init(desired) + .nodeify(done); + }); + + afterEach(function(done) { + allPassed = allPassed && (this.currentTest.state === 'passed'); + done(); + }); + + after(function(done) { + browser + .quit() + .sauceJobStatus(allPassed) + .nodeify(done); + }); + + it("Have correct title", function(done) { + browser + .get(url) + .title() + .should.become("Node.js") + .nodeify(done); + }); + + it("should get main page", function(done) { + browser + .get(url) + .title() + .should.become("Node.js") + .nodeify(done); + }); + + it("should display loading icon", function(done) { + browser + .get(url) + .title() + .should.become("Node.js") + .nodeify(done); + }); + + it("should display correct microservices", function(done) { + browser + .get(url) + .title() + .should.become("Node.js") + .nodeify(done); + }); +}); diff --git a/tests_actual/test-cases.js b/tests_actual/test-cases.js new file mode 100644 index 0000000..39cd2f9 --- /dev/null +++ b/tests_actual/test-cases.js @@ -0,0 +1,98 @@ +var wd = require('wd'); +require('colors'); +var _ = require("lodash"); +var chai = require("chai"); +var chaiAsPromised = require("chai-as-promised"); +var url = process.env.APP_URL; + +chai.use(chaiAsPromised); +chai.should(); +chaiAsPromised.transferPromiseness = wd.transferPromiseness; + +// checking sauce credential +if(!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY){ + console.warn( + '\nPlease configure your sauce credential:\n\n' + + 'export SAUCE_USERNAME=\n' + + 'export SAUCE_ACCESS_KEY=\n\n' + ); + throw new Error("Missing sauce credentials"); +} + +// http configuration, not needed for simple runs +wd.configureHttp( { + timeout: 60000, + retryDelay: 15000, + retries: 5 +}); + +var desired = JSON.parse(process.env.DESIRED || '{browserName: "chrome"}'); +desired.name = 'MicroUI with ' + desired.browserName; +desired.tags = ['MicroUI']; + +describe('MicroUI(' + desired.browserName + ')', function() { + var browser; + var allPassed = true; + + before(function(done) { + var username = process.env.SAUCE_USERNAME; + var accessKey = process.env.SAUCE_ACCESS_KEY; + browser = wd.promiseChainRemote(process.env.HOST, process.env.PORT, username, accessKey); + if(process.env.VERBOSE){ + // optional logging + browser.on('status', function(info) { + console.log(info.cyan); + }); + browser.on('command', function(meth, path, data) { + console.log(' > ' + meth.yellow, path.grey, data || ''); + }); + } + browser + .init(desired) + .nodeify(done); + }); + + afterEach(function(done) { + allPassed = allPassed && (this.currentTest.state === 'passed'); + done(); + }); + + after(function(done) { + browser + .quit() + .sauceJobStatus(allPassed) + .nodeify(done); + }); + + it("Have correct title", function(done) { + browser + .get(url) + .title() + .should.become("Node.js") + .nodeify(done); + }); + + it("should get main page", function(done) { + browser + .get(url) + .title() + .should.become("Node.js") + .nodeify(done); + }); + + it("should display loading icon", function(done) { + browser + .get(url) + .title() + .should.become("Node.js") + .nodeify(done); + }); + + it("should display correct microservices", function(done) { + browser + .get(url) + .title() + .should.become("Node.js") + .nodeify(done); + }); +});