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 pathlambdaTest.ts
64 lines (55 loc) · 2.31 KB
/
lambdaTest.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
/*
* This is an implementation of the LambdaTest 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';
Logger.setWrite(2, 'lambda_protractor.log');
const lambdaRestClient = require('@lambdatest/node-rest-client');
let logger = new Logger('lambdatest');
export class LambdaTest extends DriverProvider {
lambdaAutomationClient: any;
constructor(config: Config) {
super(config);
}
/**
* Hook to update the LambdaTest job status.
* @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();
const statusObj = {status_ind: update.passed ? 'passed' : 'failed'};
this.lambdaAutomationClient.updateSessionById(session.getId(), statusObj, (error: Error) => {
if (error) {
throw new Error(
'Error while updating LambdaTest passed/failed status: ' + util.inspect(error));
}
});
});
return Promise.all(mappedDrivers);
}
/**
* Configure and launch (if applicable) the object's environment.
* @return {promise} A promise which will resolve when the environment is
* ready to test.
*/
protected async setupDriverEnv(): Promise<any> {
this.config_.capabilities['user'] = this.config_.lambdaUsername;
this.config_.capabilities['accessKey'] = this.config_.lambdaAccessKey;
this.config_.seleniumAddress = 'https://hub.lambdatest.com/wd/hub';
this.lambdaAutomationClient = lambdaRestClient.AutomationClient(
{username: this.config_.lambdaUsername, accessKey: this.config_.lambdaAccessKey});
// Append filename to capabilities.name so that it's easier to identify
// tests.
this.config_.capabilities.name = this.config_.capabilities.name || '';
this.config_.capabilities.name += ':' + this.config_.specs.toString().replace(/^.*[\\\/]/, '');
logger.info(`Using LambdaTest selenium server at ${this.config_.seleniumAddress}`);
}
}