Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit f88523c

Browse files
committed
chore(typescript): driverProviders converted to typescript
1 parent a618bfd commit f88523c

21 files changed

+684
-682
lines changed

lib/configParser.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ export interface Config {
4343
troubleshoot?: boolean;
4444
exclude?: Array<string>|string;
4545
maxSessions?: number;
46+
seleniumAddress?: string;
47+
webDriverProxy?: string;
48+
disableEnvironmentOverrides?: boolean;
49+
browserstackUser?: string;
50+
browserstackKey?: string;
51+
firefoxPath?: string;
52+
seleniumServerJar?: string;
53+
seleniumPort?: number;
54+
localSeleniumStandaloneOpts?: {args?: any; port?: any;};
55+
sauceAgent?: string;
56+
sauceBuild?: string;
57+
sauceKey?: string;
58+
sauceSeleniumAddress?: string;
59+
sauceUser?: string;
4660
}
4761

4862
export class ConfigParser {

lib/driverProviders/attachSession.js

Lines changed: 0 additions & 57 deletions
This file was deleted.

lib/driverProviders/attachSession.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* This is an implementation of the Attach Session Driver Provider.
3+
* It is responsible for setting up the account object, tearing
4+
* it down, and setting up the driver correctly.
5+
*/
6+
import * as q from 'q';
7+
import {Config} from '../configParser';
8+
import {DriverProvider} from './driverProvider';
9+
import {Logger} from '../logger2';
10+
11+
let WebDriver = require('selenium-webdriver').WebDriver;
12+
let executors = require('selenium-webdriver/executors');
13+
14+
let logger = new Logger('attachSession');
15+
16+
export class AttachSession extends DriverProvider {
17+
constructor(config: Config) { super(config); }
18+
19+
/**
20+
* Configure and launch (if applicable) the object's environment.
21+
* @public
22+
* @return {q.promise} A promise which will resolve when the environment is
23+
* ready to test.
24+
*/
25+
setupEnv(): q.Promise<any> {
26+
logger.info('Using the selenium server at ' + this.config_.seleniumAddress);
27+
logger.info('Using session id - ' + this.config_.seleniumSessionId);
28+
return q(undefined);
29+
}
30+
31+
/**
32+
* Getting a new driver by attaching an existing session.
33+
*
34+
* @public
35+
* @return {WebDriver} webdriver instance
36+
*/
37+
getNewDriver(): WebDriver {
38+
var executor = executors.createExecutor(this.config_.seleniumAddress);
39+
var newDriver =
40+
WebDriver.attachToSession(executor, this.config_.seleniumSessionId);
41+
this.drivers_.push(newDriver);
42+
return newDriver;
43+
}
44+
45+
/**
46+
* Maintains the existing session and does not quit the driver.
47+
*
48+
* @public
49+
*/
50+
quitDriver(): q.Promise<WebDriver> {
51+
let defer = q.defer<WebDriver>();
52+
defer.resolve(null);
53+
return defer.promise;
54+
}
55+
}

lib/driverProviders/browserStack.ts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* This is an implementation of the Browserstack Driver Provider.
3+
* It is responsible for setting up the account object, tearing
4+
* it down, and setting up the driver correctly.
5+
*/
6+
import * as request from 'request';
7+
import * as q from 'q';
8+
import * as util from 'util';
9+
10+
import {Config} from '../configParser';
11+
import {DriverProvider} from './driverProvider';
12+
import {Logger} from '../logger2';
13+
14+
let logger = new Logger('browserstack');
15+
16+
export class BrowserStack extends DriverProvider {
17+
constructor(config: Config) { super(config); }
18+
19+
/**
20+
* Hook to update the BrowserStack job status.
21+
* @public
22+
* @param {Object} update
23+
* @return {q.promise} A promise that will resolve when the update is complete.
24+
*/
25+
updateJob(update: any): q.Promise<any> {
26+
let deferredArray = this.drivers_.map((driver: WebDriver) => {
27+
let deferred = q.defer();
28+
driver.getSession().then((session: Session) => {
29+
var jobStatus = update.passed ? 'completed' : 'error';
30+
logger.info(
31+
'BrowserStack results available at ' +
32+
'https://www.browserstack.com/automate');
33+
request(
34+
{
35+
url: 'https://www.browserstack.com/automate/sessions/' +
36+
session.getId() + '.json',
37+
headers: {
38+
'Content-Type': 'application/json',
39+
'Authorization': 'Basic ' +
40+
new Buffer(
41+
this.config_.browserstackUser + ':' +
42+
this.config_.browserstackKey)
43+
.toString('base64')
44+
},
45+
method: 'PUT',
46+
form: {'status': jobStatus}
47+
},
48+
(error: Error) => {
49+
if (error) {
50+
throw new Error(
51+
'Error updating BrowserStack pass/fail status: ' +
52+
util.inspect(error));
53+
}
54+
});
55+
deferred.resolve();
56+
});
57+
return deferred.promise;
58+
});
59+
return q.all(deferredArray);
60+
}
61+
62+
/**
63+
* Configure and launch (if applicable) the object's environment.
64+
* @public
65+
* @return {q.promise} A promise which will resolve when the environment is
66+
* ready to test.
67+
*/
68+
setupEnv(): q.Promise<any> {
69+
var deferred = q.defer();
70+
this.config_.capabilities['browserstack.user'] =
71+
this.config_.browserstackUser;
72+
this.config_.capabilities['browserstack.key'] =
73+
this.config_.browserstackKey;
74+
this.config_.seleniumAddress = 'http://hub.browserstack.com/wd/hub';
75+
76+
// Append filename to capabilities.name so that it's easier to identify
77+
// tests.
78+
if (this.config_.capabilities.name &&
79+
this.config_.capabilities.shardTestFiles) {
80+
this.config_.capabilities.name +=
81+
(':' + this.config_.specs.toString().replace(/^.*[\\\/]/, ''));
82+
}
83+
84+
logger.info(
85+
'Using BrowserStack selenium server at ' +
86+
this.config_.seleniumAddress);
87+
deferred.resolve();
88+
return deferred.promise;
89+
}
90+
}

lib/driverProviders/browserstack.js

Lines changed: 0 additions & 91 deletions
This file was deleted.

0 commit comments

Comments
 (0)