forked from LearnBoost/soda
/
sauce.js
158 lines (136 loc) · 3.8 KB
/
sauce.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*!
* Soda - Sauce
* Copyright(c) 2010 LearnBoost <tj@learnboost.com>
* MIT Licensed
*/
/**
* Module dependencies.
*/
var Client = require('./client');
/**
* Initialize a `SauceClient` with the given `options`. A suite of environment
* variables are also supported in place of the options described below.
*
* Options:
*
* - `username` Sauce Labs username
* - `access-key` Account access key
* - `os` Operating system ex "Linux"
* - `browser` Browser name, ex "firefox"
* - `browser-version` Browser version, ex "3.0.", "7."
* - `max-duration` Maximum test duration in seconds, ex 300 (5 minutes)
*
* Environment Variables:
*
* - `SAUCE_HOST` Defaulting to "ondemand.saucelabs.com"
* - `SAUCE_PORT` Defaulting to 80
* - `SAUCE_OS`
* - `SAUCE_BROWSER`
* - `SAUCE_USERNAME`
* - `SAUCE_ACCESS_KEY`
* - `SAUCE_BROWSER_VERSION`
*
* @params {Object} options
* @api public
*/
var SauceClient = exports = module.exports = function SauceClient(options) {
options = options || {};
this.host = process.env.SAUCE_HOST || 'ondemand.saucelabs.com';
this.port = process.env.SAUCE_PORT || 80;
// Check sauce env variables, and provide defaults
options.os = options.os || process.env.SAUCE_OS || 'Linux';
options.url = options.url || process.env.SAUCE_BROWSER_URL;
options.browser = options.browser || process.env.SAUCE_BROWSER || 'firefox';
options.username = options.username || process.env.SAUCE_USERNAME;
options['access-key'] = options['access-key'] || process.env.SAUCE_ACCESS_KEY;
options['max-duration'] = options['max-duration'] || 300;
// Allow users to specify an empty browser-version
options['browser-version'] = options['browser-version'] == undefined
? (process.env.SAUCE_BROWSER_VERSION || '')
: (options['browser-version'] || '');
this.url = options.url;
this.username = options.username;
this.accessKey = options['access-key'];
this.options = options;
this.browser = JSON.stringify(options);
};
/**
* Interit from `Client`.
*/
SauceClient.prototype.__proto__ = Client.prototype;
/**
* Return saucelabs job url.
*
* @return {String}
* @api public
*/
SauceClient.prototype.__defineGetter__('jobUrl', function(){
return 'https://saucelabs.com/jobs/' + this.sid;
});
/**
* Return saucelabs video flv url.
*
* @return {String}
* @api public
*/
SauceClient.prototype.__defineGetter__('videoUrl', function(){
return exports.url(this.username, this.sid, 'video.flv');
});
/**
* Return saucelabs log file url.
*
* @return {String}
* @api public
*/
SauceClient.prototype.__defineGetter__('logUrl', function(){
return exports.url(this.username, this.sid, 'selenium-server.log');
});
/**
* Return saucelabs video embed script.
*
* @return {String}
* @api public
*/
SauceClient.prototype.__defineGetter__('video', function(){
return exports.video(this.username, this.accessKey, this.sid);
});
/**
* Shortcut for `new soda.SauceClient()`.
*
* @param {Object} options
* @return {Client}
* @api public
*/
exports.createClient = function(options){
return new SauceClient(options);
};
/**
* Return saucelabs url to `jobId`'s `filename`.
*
* @param {String} username
* @param {String} jobId
* @param {String} filename
* @return {String}
* @api public
*/
exports.url = function(username, jobId, filename){
return 'https://saucelabs.com/rest/'
+ username + '/jobs/'
+ jobId + '/results/'
+ filename;
};
/**
* Return saucelabs video embed script.
*
* @param {String} username
* @param {String} accessKey
* @param {String} jobId
* @return {String}
* @api public
*/
exports.video = function(username, accessKey, jobId){
return '<script src="http://saucelabs.com/video-embed/'
+ jobId + '.js?username='
+ username + '&access_key='
+ accessKey + '"/>';
};