forked from EchoAppsTeam/js-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
107 lines (104 loc) · 2.96 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
var wd = require('wd')
, Q = require('q')
, request = require('request')
, assert = require('assert')
, host = "ondemand.saucelabs.com"
, port = 80
, username = "echo-apps"
, accessKey = "cede2c15-c632-41bd-8bd9-1aac61fca87f"
// general rest call helper function using promises
var api = function (url, method, data) {
var deferred = Q.defer();
request(
{ method: method
, uri: ["https://", username, ":", accessKey, "@saucelabs.com/rest", url].join("")
, headers: {'Content-Type': 'application/json'}
, body: JSON.stringify(data)
}
, function (error, response, body) {
deferred.resolve(response.body);
}
);
return deferred.promise;
};
var platforms = [{
browserName: 'iphone',
version: '5.0',
platform: 'Mac 10.6',
tags: ["examples"],
name: "Echo testrs (iphone)",
build: "Testing enviroment"
}, {
browserName: 'firefox',
version: '21',
platform: 'Windows 7',
tags: ["examples"],
name: "Echo testrs (firefox)",
build: "Testing enviroment"
}, {
browserName: 'chrome',
version: '26',
platform: 'Windows 7',
tags: ["examples"],
name: "Echo testrs (chrome)",
build: "Testing enviroment"
}, {
browserName: 'internet explorer',
version: '9',
platform: 'Windows 7',
tags: ["examples"],
name: "Echo testrs (ie9)",
build: "Testing enviroment"
}, {
browserName: 'internet explorer',
version: '8',
platform: 'Windows 7',
tags: ["examples"],
name: "Echo testrs (ie8)",
build: "Testing enviroment"
}/*, {
browserName: 'android',
version: '4',
platform: 'Linux',
tags: ["examples"],
name: "Echo testrs (android)",
build: "Testing enviroment"
}*/];
platforms.forEach(function(platform, i) {
var browser = wd.promiseRemote(host, port, username, accessKey);
browser.on('status', function(info){
console.log('\x1b[36m%s\x1b[0m', info);
});
// test case
browser.init(platform).then(function () {
//return browser.get("http://saucelabs.com/test_helpers/front_tests/qunit.html")
return browser.get("http://proteamer.github.io/js-sdk/tests/?module=View");
}).then(function () {
return browser.waitForCondition("!!window.testResults", 1000 * 60 * 5, 5000);
//}).then(function () {
// return browser.title();
//}).then(function (title) {
// are we on the right page?
// assert.ok(~title.indexOf("Refactored date examples"), 'Wrong title!');
}).then(function () {
// get jasmine output as JSON
return browser.eval("window.testResults");
}).then(function (jsreport) {
// make an API call to Sauce - set custom-data with 'jasmine' data
var data = {
'custom-data': {qunit: jsreport},
'passed': jsreport.failed == 0
};
return api(["/v1/", username, "/jobs/", browser.sessionID].join(""), "PUT", data);
}).then(function (body) {
//console.log("CONGRATS - WE'RE DONE", body);
}).fin(function () {
browser.quit();
}).fail(function (error) {
var data = {
'passed': false
};
return api(["/v1/", username, "/jobs/", browser.sessionID].join(""), "PUT", data);
console.error("Error:", error);
}).done();
});