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

Commit

Permalink
Updated package json.
Browse files Browse the repository at this point in the history
Changed the test app.
Fixed test pass/fail update. (Was reporting pass for everything.)
Added sauce-utils to handle app upload.
Added desired caps to handle app uploads.
added test apps to the repo.
  • Loading branch information
mehmetg committed Mar 5, 2016
1 parent 5ae625c commit d1faf28
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 38 deletions.
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
### Node template
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
node_modules

# Created by .ignore support plugin (hsz.mobi)
.idea/
.DS_Store
9 changes: 6 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
'use strict';

var simAppFile = 'GuineaPig-sim-debug.app.zip';
var devAppFile = 'GuineaPig-dev-debug.app.zip';

module.exports = function (grunt) {
// configure tasks
grunt.initConfig({
Expand Down Expand Up @@ -45,16 +48,16 @@ module.exports = function (grunt) {

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

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');
grunt.option('app', 'sauce-storage:' + devAppFile);
});

// register tasks
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ This code is provided on an "AS-IS” basis without warranty of any kind, either
```
$ brew install node
```
* Install Grunt Globally
```
$ npm install -g grunt-cli
```
2. Sauce Credentials
* In the terminal export your Sauce Labs Credentials as environmental variables:
```
Expand All @@ -25,6 +21,10 @@ This code is provided on an "AS-IS” basis without warranty of any kind, either
```
$ npm install
```
4. Test Targets
* Simulator app: GuineaPig-sim-debug.app.zip located in <project root>/resources
* Device app: GuineaPig-dev-debug.app.zip located in <project root>/resources
* App names and paths are defined in ```Gruntfile.js``` and ```helpers.js``` in the ```test``` folder.
### Running Tests
Expand Down
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
"version": "0.0.0",
"description": "Parallel tests with Mocha and WD.js =============",
"main": "",
"scripts": {
"test": "./node_modules/grunt-cli/bin/grunt -d -v"
},
"devDependencies": {
"wd": "*",
"chai-as-promised": "~4.1.0",
"chai-as-promised": "~5.2.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"
"q": "~1.4.1",
"lodash": "~4.6.1",
"chai": "~3.5.0",
"mocha": "2.4.5",
"grunt-cli": "^0.1.13",
"nodeify": "*"
}
}
Binary file added resources/GuineaPig-dev-debug.app.zip
Binary file not shown.
Binary file added resources/GuineaPig-sim-debug.app.zip
Binary file not shown.
18 changes: 7 additions & 11 deletions test/example-spec.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
var makeSuite = require('./helpers').makeSuite;

makeSuite('Test Suite 2', function() {
makeSuite('Test Suite Email', 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);
it('enter and read email back correctly', function() {
return driver
.elementById('fbemail')
.sendKeys('[email protected]')
.elementById('fbemail')
.getValue().should.eventually.equal('[email protected]');
});

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

makeSuite('Test Suite 1', function() {
makeSuite('Test Suite Comments', 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);
});
it('enter comments, submit and read back correctly', function() {
return driver
.elementById('comments')
.sendKeys('I am a comment!')
.elementById('H1Text')
.click()
.elementById('submit')
.click()
.elementById('comments')
.getValue().should.eventually.equal('');
});

});
27 changes: 24 additions & 3 deletions test/helpers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var wd = require('wd'),
_ = require("lodash"),
chai = require("chai"),
chaiAsPromised = require("chai-as-promised");
chaiAsPromised = require("chai-as-promised"),
uploadToSauceStorage = require("./sauce-utils").uploadFileToSauceStorage,
path = require("path");

chai.use(chaiAsPromised);
chai.should();
Expand All @@ -13,6 +15,24 @@ wd.configureHttp({
retries: 5
});

function beforeAll(done){
uploadToSauceStorage(path.resolve("./resources/GuineaPig-dev-debug.app.zip"))
.then( function(res) {
if (res) {
uploadToSauceStorage(path.resolve("./resources/GuineaPig-dev-debug.app.zip")).then( function(res2) {
if (res2) {
done();
} else {
process.exit(-1);
}
});
} else {
console.error("Device app upload failed!")
process.exit(-1);
}
});
}

function beforeEachExample(done) {
var username = process.env.SAUCE_USERNAME;
var accessKey = process.env.SAUCE_ACCESS_KEY;
Expand All @@ -22,7 +42,7 @@ function beforeEachExample(done) {
.init({
name: this.currentTest.title,
browserName: '',
appiumVersion: '1.4.13',
appiumVersion: '1.5.0',
deviceName: process.env.deviceName,
platformVersion: process.env.platformVersion,
platformName: process.env.platformName,
Expand All @@ -35,7 +55,7 @@ function afterEachExample(done) {
// allPassed = allPassed && (this.currentTest.state === 'passed');
driver
.quit()
.sauceJobStatus(true)
.sauceJobStatus(this.currentTest.state === 'passed')
.nodeify(done);
};

Expand All @@ -45,6 +65,7 @@ function makeSuite(desc, cb) {

this.timeout(240000);

before(beforeAll);
beforeEach(beforeEachExample);
cb();
afterEach(afterEachExample);
Expand Down
89 changes: 89 additions & 0 deletions test/sauce-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
var request = require("request");
var util = require("util");
var fs = require("fs");
var crypto = require('crypto');

function getMD5(file) {
return new Promise( function(resolve, reject) {
try{
var hash = crypto.createHash('md5');
var stream = fs.createReadStream(file);
stream.on('data', function(data){
hash.update(data, 'utf8')
});

stream.on('end', function() {
resolve(hash.digest('hex'));
});
} catch (e) {
reject(e);
}
});
}

function getFilename(path) {
return new Promise( function(resolve, reject) {
try{
resolve(path.replace(/^.*[\\\/]/, ''));
} catch (e) {
console.error(e);
reject(e);
}
});
}

function uploadToSS(file) {
return new Promise( function(resolve, reject) {
try{

getFilename(file)
.then( function(fileName) {
var uriTemplate = "https://saucelabs.com/rest/v1/storage/%s/%s?overwrite=true";
var uri = util.format(uriTemplate, process.env.SAUCE_USERNAME, fileName)
//console.log(uri);
fs.createReadStream(file).pipe(request.post({
url: uri,
auth: {
user: process.env.SAUCE_USERNAME,
pass: process.env.SAUCE_ACCESS_KEY,
},
},
function (error, response, body) {
if (error) {
console.error("Upload failed:", error);
resolve(error);
} else {
//console.log("Upload successful! Server responded with:", body);
resolve(JSON.parse(body)["md5"]);
}
}));
});
} catch (e) {
reject(e);
}
});
}


function uploadFileToSauceStorage(file){
return new Promise(function(resolve, reject) {
try{
uploadToSS(file).then( function(md5) {
getMD5(file).then( function(localMd5) {
if (localMd5 === md5){
//console.log("Upload confirmed!");
resolve(true);
} else {
console.error("Checksum failed!");
resolve(false);
}
});
});
} catch (e){
console.error(e);
reject(e);
}
});
}

exports.uploadFileToSauceStorage = uploadFileToSauceStorage;

0 comments on commit d1faf28

Please sign in to comment.