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

Commit

Permalink
Merge pull request #2 from saucelabs-sample-test-frameworks/fixing
Browse files Browse the repository at this point in the history
Removing extra logic and only uploading to sauce-storage once right before test suite
  • Loading branch information
ndmanvar authored Aug 23, 2016
2 parents d96345b + f4edf97 commit af04c1a
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 120 deletions.
15 changes: 11 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ var devAppFile = 'GuineaPig-dev-debug.app.zip';
module.exports = function (grunt) {
// configure tasks
grunt.initConfig({
execute: {
src: ['upload_to_sauce_storage.js']
},

mocha_parallel: {
options: {
args: function(suiteName) {
Expand All @@ -31,7 +35,7 @@ module.exports = function (grunt) {
mocha: './node_modules/.bin/mocha'
}
},

parallel: {
assets: {
options: {
Expand All @@ -43,6 +47,7 @@ module.exports = function (grunt) {
});

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

Expand All @@ -51,20 +56,22 @@ module.exports = function (grunt) {
grunt.option('platformVersion', '9.2');
grunt.option('deviceName', "iPhone 6");
grunt.option('app', 'sauce-storage:' + simAppFile);
process.env['appPath']= 'resources/' + 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:' + devAppFile);
process.env['appPath']= 'resources/' + devAppFile;
});

// 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']);
grunt.registerTask('run_iPhone_6_Simulator', ['iPhone_6_Simulator', 'execute', 'mocha_parallel']);
grunt.registerTask('run_iPhone_6_Real_Device', ['iPhone_6_Real_Device', 'execute', 'mocha_parallel']);

};

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"wd": "*",
"chai-as-promised": "~5.2.0",
"grunt": "0.4.5",
"grunt-execute": "*",
"grunt-mocha-parallel": "^0.1.7",
"grunt-parallel": "^0.4.1",
"q": "~1.4.1",
Expand Down
7 changes: 4 additions & 3 deletions test/example-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ var makeSuite = require('./helpers').makeSuite;

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

it('enter and read email back correctly', function() {
return driver
it('enter and read email back correctly', function(done) {
driver
.elementById('fbemail')
.sendKeys('[email protected]')
.elementById('fbemail')
.getValue().should.eventually.equal('[email protected]');
.getValue().should.eventually.equal('[email protected]')
.nodeify(done);
});

});
7 changes: 4 additions & 3 deletions test/example2-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ var makeSuite = require('./helpers').makeSuite;

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

it('enter comments, submit and read back correctly', function() {
return driver
it('enter comments, submit and read back correctly', function(done) {
driver
.elementById('comments')
.sendKeys('I am a comment!')
.elementById('H1Text')
.click()
.elementById('submit')
.click()
.elementById('comments')
.getValue().should.eventually.equal('');
.getValue().should.eventually.equal('')
.nodeify(done);
});

});
22 changes: 1 addition & 21 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ var wd = require('wd'),
_ = require("lodash"),
chai = require("chai"),
chaiAsPromised = require("chai-as-promised"),
uploadToSauceStorage = require("./sauce-utils").uploadFileToSauceStorage,
path = require("path");

chai.use(chaiAsPromised);
Expand All @@ -15,24 +14,6 @@ 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 @@ -46,7 +27,7 @@ function beforeEachExample(done) {
deviceName: process.env.deviceName,
platformVersion: process.env.platformVersion,
platformName: process.env.platformName,
app: process.env.app
app: "sauce-storage:" + process.env.app
})
.nodeify(done);
};
Expand All @@ -65,7 +46,6 @@ function makeSuite(desc, cb) {

this.timeout(240000);

before(beforeAll);
beforeEach(beforeEachExample);
cb();
afterEach(afterEachExample);
Expand Down
89 changes: 0 additions & 89 deletions test/sauce-utils.js

This file was deleted.

23 changes: 23 additions & 0 deletions upload_to_sauce_storage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var request = require("request"),
util = require("util"),
fs = require("fs"),
file = process.env.appPath,
fileName = file.replace(/^.*[\\\/]/, ''),
uriTemplate = "https://saucelabs.com/rest/v1/storage/%s/%s?overwrite=true",
uri = util.format(uriTemplate, process.env.SAUCE_USERNAME, fileName);

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);
} else {
console.log("Upload successful! Server responded with:", body);
}
})
);

0 comments on commit af04c1a

Please sign in to comment.