Skip to content
This repository has been archived by the owner on Dec 30, 2019. It is now read-only.

Commit

Permalink
Adding JS-Grunt-Mocha-Parallel-Appium-iOS test framework
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil authored and Neil committed Dec 7, 2015
0 parents commit 2cc5854
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 0 deletions.
67 changes: 67 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'use strict';

module.exports = function (grunt) {
// configure tasks
grunt.initConfig({
mocha_parallel: {
options: {
args: function(suiteName) {
return [];
},
env: function(suiteName) {
process.env.platformName = grunt.option('platformName');
process.env.platformVersion = grunt.option('platformVersion');
process.env.deviceName = grunt.option('deviceName');
process.env.app = grunt.option('app');
return process.env;
},
report: function(suite, code, stdout, stderr) {
if (stdout.length) {
process.stdout.write(stdout);
}
if (stderr.length) {
process.stderr.write(stderr);
}
},
done: function(success, results) {
},
mocha: './node_modules/.bin/mocha'
}
},

parallel: {
assets: {
options: {
grunt: true
},
tasks: ['run_iPhone_6_Simulator', 'run_iPhone_6_Real_Device']
}
}
});

// load tasks
grunt.loadNpmTasks('grunt-mocha-parallel');
grunt.loadNpmTasks('grunt-parallel');

grunt.registerTask('iPhone_6_Simulator', function(n) {
grunt.option('platformName', 'iOS');
grunt.option('platformVersion', '8.4');
grunt.option('deviceName', "iPhone 6");
grunt.option('app', 'https://s3.amazonaws.com/appium/TestApp8.4.app.zip');
});

grunt.registerTask('iPhone_6_Real_Device', function(n) {
grunt.option('platformName', 'iOS');
grunt.option('platformVersion', '8.4');
grunt.option('deviceName', "iPhone 6 Device");
grunt.option('app', 'sauce-storage:TestApp-iphoneos.app.zip');
});

// register tasks
grunt.registerTask('default', ['parallel']);

grunt.registerTask('run_iPhone_6_Simulator', ['iPhone_6_Simulator', 'mocha_parallel']);
grunt.registerTask('run_iPhone_6_Real_Device', ['iPhone_6_Real_Device', 'mocha_parallel']);

};

29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Description
Uses the following technologies / packages
- mocha (https://mochajs.org/)
- grunt-mocha-parallel (https://www.npmjs.com/package/grunt-mocha-parallel) for parallel execution of test suites
- grunt-parallel (https://github.com/iammerrick/grunt-parallel) for parallel execution against multilevel browser / OS configurations.
- wd.js for Appium JS binding

# Usage

## Set Sauce Variables:
```
$ export SAUCE_USERNAME=sauce_username
$ export SAUCE_ACCESS_KEY=sauce_access_key
```

## Install Grunt
```
$ npm install -g grunt # use sudo if necessary
```

## Download Node Modules:
```
$ npm install
```

## Run the tests:
```
$ grunt
```
17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "mocha-wd-parallel",
"version": "0.0.0",
"description": "Parallel tests with Mocha and WD.js =============",
"main": "",
"devDependencies": {
"wd": "*",
"chai-as-promised": "~4.1.0",
"grunt": "0.4.5",
"grunt-mocha-parallel": "^0.1.7",
"grunt-parallel": "^0.4.1",
"q": "~0.9.7",
"lodash": "~2.4.1",
"chai": "~1.8.1",
"mocha": "1.18.2"
}
}
17 changes: 17 additions & 0 deletions test/example-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var makeSuite = require('./helpers').makeSuite;

makeSuite('Test Suite 2', function() {

it('should compute different sum', function() {
driver
.elementByAccessibilityId('TextField1')
.sendKeys(13)
.elementByClassName('UIATextField')
.sendKeys(8)
.elementByAccessibilityId('ComputeSumButton')
.click()
.elementByClassName('UIAStaticText')
.should.eventually.equal(21);
});

});
17 changes: 17 additions & 0 deletions test/example2-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var makeSuite = require('./helpers').makeSuite;

makeSuite('Test Suite 1', function() {

it('should compute a sum', function() {
driver
.elementByAccessibilityId('TextField1')
.sendKeys(12)
.elementByClassName('UIATextField')
.sendKeys(8)
.elementByAccessibilityId('ComputeSumButton')
.click()
.elementByClassName('UIAStaticText')
.should.eventually.equal(20);
});

});
54 changes: 54 additions & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
var wd = require('wd'),
_ = require("lodash"),
chai = require("chai"),
chaiAsPromised = require("chai-as-promised");

chai.use(chaiAsPromised);
chai.should();
chaiAsPromised.transferPromiseness = wd.transferPromiseness;

wd.configureHttp({
timeout: 240000,
retryDelay: 15000,
retries: 5
});

function beforeEachExample(done) {
var username = process.env.SAUCE_USERNAME;
var accessKey = process.env.SAUCE_ACCESS_KEY;
driver = wd.promiseChainRemote("ondemand.saucelabs.com", 80, username, accessKey);

driver
.init({
name: this.currentTest.title,
browserName: '',
appiumVersion: '1.4.13',
deviceName: process.env.deviceName,
platformVersion: process.env.platformVersion,
platformName: process.env.platformName,
app: process.env.app
})
.nodeify(done);
};

function afterEachExample(done) {
// allPassed = allPassed && (this.currentTest.state === 'passed');
driver
.quit()
.sauceJobStatus(true)
.nodeify(done);
};

function makeSuite(desc, cb) {
describe(desc, function() {
var driver;

this.timeout(240000);

beforeEach(beforeEachExample);
cb();
afterEach(afterEachExample);
});
};

exports.makeSuite = makeSuite;

0 comments on commit 2cc5854

Please sign in to comment.