1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | const https = require("https");
|
9 | const q = require("q");
|
10 | const util = require("util");
|
11 | const exitCodes_1 = require("../exitCodes");
|
12 | const logger_1 = require("../logger");
|
13 | const driverProvider_1 = require("./driverProvider");
|
14 | let logger = new logger_1.Logger('browserstack');
|
15 | class BrowserStack extends driverProvider_1.DriverProvider {
|
16 | constructor(config) {
|
17 | super(config);
|
18 | }
|
19 | |
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | updateJob(update) {
|
26 | let deferredArray = this.drivers_.map((driver) => {
|
27 | let deferred = q.defer();
|
28 | driver.getSession().then((session) => {
|
29 | let headers = {
|
30 | 'Content-Type': 'application/json',
|
31 | 'Authorization': 'Basic ' +
|
32 | new Buffer(this.config_.browserstackUser + ':' + this.config_.browserstackKey)
|
33 | .toString('base64')
|
34 | };
|
35 | let options = {
|
36 | hostname: 'www.browserstack.com',
|
37 | port: 443,
|
38 | path: '/automate/sessions/' + session.getId() + '.json',
|
39 | method: 'GET',
|
40 | headers: headers
|
41 | };
|
42 | let req = https.request(options, (res) => {
|
43 | res.on('data', (data) => {
|
44 | let info = JSON.parse(data.toString());
|
45 | if (info && info.automation_session && info.automation_session.browser_url) {
|
46 | logger.info('BrowserStack results available at ' + info.automation_session.browser_url);
|
47 | }
|
48 | else {
|
49 | logger.info('BrowserStack results available at ' +
|
50 | 'https://www.browserstack.com/automate');
|
51 | }
|
52 | });
|
53 | });
|
54 | req.end();
|
55 | req.on('error', (e) => {
|
56 | logger.info('BrowserStack results available at ' +
|
57 | 'https://www.browserstack.com/automate');
|
58 | });
|
59 | let jobStatus = update.passed ? 'completed' : 'error';
|
60 | options.method = 'PUT';
|
61 | let update_req = https.request(options, (res) => {
|
62 | let responseStr = '';
|
63 | res.on('data', (data) => {
|
64 | responseStr += data.toString();
|
65 | });
|
66 | res.on('end', () => {
|
67 | logger.info(responseStr);
|
68 | deferred.resolve();
|
69 | });
|
70 | res.on('error', (e) => {
|
71 | throw new exitCodes_1.BrowserError(logger, 'Error updating BrowserStack pass/fail status: ' + util.inspect(e));
|
72 | });
|
73 | });
|
74 | update_req.write('{"status":"' + jobStatus + '"}');
|
75 | update_req.end();
|
76 | });
|
77 | return deferred.promise;
|
78 | });
|
79 | return q.all(deferredArray);
|
80 | }
|
81 | |
82 |
|
83 |
|
84 |
|
85 |
|
86 | setupDriverEnv() {
|
87 | let deferred = q.defer();
|
88 | this.config_.capabilities['browserstack.user'] = this.config_.browserstackUser;
|
89 | this.config_.capabilities['browserstack.key'] = this.config_.browserstackKey;
|
90 | this.config_.seleniumAddress = 'http://hub.browserstack.com/wd/hub';
|
91 |
|
92 |
|
93 | if (this.config_.capabilities.name && this.config_.capabilities.shardTestFiles) {
|
94 | this.config_.capabilities.name +=
|
95 | (':' + this.config_.specs.toString().replace(/^.*[\\\/]/, ''));
|
96 | }
|
97 | logger.info('Using BrowserStack selenium server at ' + this.config_.seleniumAddress);
|
98 | deferred.resolve();
|
99 | return deferred.promise;
|
100 | }
|
101 | }
|
102 | exports.BrowserStack = BrowserStack;
|
103 |
|
\ | No newline at end of file |