This repository was archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Copy pathsauce.ts
96 lines (85 loc) · 3.2 KB
/
sauce.ts
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
/*
* This is an implementation of the SauceLabs Driver Provider.
* It is responsible for setting up the account object, tearing
* it down, and setting up the driver correctly.
*/
import {WebDriver} from 'selenium-webdriver';
import * as util from 'util';
import {Config} from '../config';
import {Logger} from '../logger';
import {DriverProvider} from './driverProvider';
const SauceLabs = require('saucelabs');
const SAUCE_REGIONS: {[key: string]: string} = {
'us': '', // default endpoint
'eu': 'eu-central-1.'
};
let logger = new Logger('sauce');
export class Sauce extends DriverProvider {
sauceServer_: any;
constructor(config: Config) {
super(config);
}
/**
* Hook to update the sauce job.
* @public
* @param {Object} update
* @return {Promise} A promise that will resolve when the update is complete.
*/
updateJob(update: any): Promise<any> {
let mappedDrivers = this.drivers_.map(async (driver: WebDriver) => {
const session = await driver.getSession();
logger.info('SauceLabs results available at https://saucelabs.com/jobs/' + session.getId());
this.sauceServer_.updateJob(session.getId(), update, (err: Error) => {
if (err) {
throw new Error('Error updating Sauce pass/fail status: ' + util.inspect(err));
}
});
});
return Promise.all(mappedDrivers);
}
/**
* Configure and launch (if applicable) the object's environment.
* @public
* @return {Promise} A promise which will resolve when the environment is
* ready to test.
*/
protected async setupDriverEnv(): Promise<any> {
this.sauceServer_ = new SauceLabs({
hostname: this.getSauceEndpoint(this.config_.sauceRegion),
username: this.config_.sauceUser,
password: this.config_.sauceKey,
agent: this.config_.sauceAgent,
proxy: this.config_.sauceProxy
});
this.config_.capabilities['username'] = this.config_.sauceUser;
this.config_.capabilities['accessKey'] = this.config_.sauceKey;
this.config_.capabilities['build'] = this.config_.sauceBuild;
let protocol = this.config_.sauceSeleniumUseHttp ? 'http://' : 'https://';
let auth = protocol + this.config_.sauceUser + ':' + this.config_.sauceKey + '@';
this.config_.seleniumAddress = auth +
(this.config_.sauceSeleniumAddress ?
this.config_.sauceSeleniumAddress :
`ondemand.${this.getSauceEndpoint(this.config_.sauceRegion)}:443/wd/hub`);
// Append filename to capabilities.name so that it's easier to identify
// tests.
if (this.config_.capabilities.name && this.config_.capabilities.shardTestFiles) {
this.config_.capabilities.name +=
(':' + this.config_.specs.toString().replace(/^.*[\\\/]/, ''));
}
logger.info(
'Using SauceLabs selenium server at ' +
this.config_.seleniumAddress.replace(/\/\/.+@/, '//'));
}
/**
* Get the Sauce Labs endpoint
* @private
* @param {string} region
* @return {string} The endpoint that needs to be used
*/
private getSauceEndpoint(region: string): string {
const dc = region ?
typeof SAUCE_REGIONS[region] !== 'undefined' ? SAUCE_REGIONS[region] : (region + '.') :
'';
return `${dc}saucelabs.com`;
}
}