-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathhooks.js
73 lines (64 loc) · 1.85 KB
/
hooks.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
"use strict";
const webdriver = require("selenium-webdriver");
const lambdaTunnel = require("@lambdatest/node-tunnel");
const config_file =
"../../conf/" + (process.env.CONFIG_FILE || "single") + ".conf.js";
const config = require(config_file).config;
const tunnelArguments = { user: config.user, key: config.key };
const myTunnel = new lambdaTunnel();
var createLambdaTestSession = function(config, caps) {
console.log(
"https://" +
config.user +
":" +
config.key +
"@" +
config.server +
"/wd/hub"
);
return new webdriver.Builder()
.usingServer(
"https://" +
config.user +
":" +
config.key +
"@" +
config.server +
"/wd/hub"
)
.withCapabilities(caps)
.build();
};
var myHooks = function() {
this.Before(function(scenario, callback) {
var world = this;
var task_id = parseInt(process.env.TASK_ID || 0);
var caps = config.capabilities[task_id];
if (caps["tunnel"]) {
// Code to start LambdaTest Tunnel before start of test and stop LambdaTest Tunnel after end of test
myTunnel.start(tunnelArguments, function(e, status) {
if (e) return console.log(e);
console.log("Started Tunnel " + status);
console.log(
"TUNNELLLLL" + caps["tunnel"] + caps["browserName"] + caps["build"]
);
world.driver = createLambdaTestSession(config, caps);
callback();
});
} else {
world.driver = createLambdaTestSession(config, caps);
callback();
}
});
console.log("TUNNEL STATUS" + myTunnel.isRunning());
this.After(function(scenario, callback) {
console.log("Started Tunnel AFTER " + myTunnel.isRunning());
this.driver.quit().then(function() {
if (myTunnel) {
myTunnel.stop(callback);
}
callback();
});
});
};
module.exports = myHooks;