This repository has been archived by the owner on Mar 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
95 lines (81 loc) · 2.58 KB
/
index.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* Script replicates the manual way of refreshing a
* ServiceNow developer instance. I know, I'm lazy.
*/
(async () => {
// load dependencies
require("dotenv").config();
const { Builder, By, Key, until } = require("selenium-webdriver");
const chrome = require("selenium-webdriver/chrome");
const firefox = require("selenium-webdriver/firefox");
// Set default screen resolution (for headless instance)
const screenResolution = {
width: 1280,
height: 720
};
// Set config variables
let webdriver = process.env.WEBDRIVER || "chrome";
let args = ["--headless ", "--disable-web-security"];
let driver = await new Builder()
.forBrowser(webdriver)
.setChromeOptions(
new chrome.Options()
.headless()
.addArguments(args)
.windowSize(screenResolution)
)
.setFirefoxOptions(
new firefox.Options()
.headless()
.addArguments(args)
.windowSize(screenResolution)
)
.build();
// Refreshing of instance starts here.
try {
// Go to servicenow
console.log('Redirecting to https://developer.servicenow.com/');
await driver.get("https://developer.servicenow.com/");
// click login link
console.log('Logging in..');
await driver.findElement(By.id("dp-hdr-login-link")).click();
// enter username
await driver
.findElement(By.id("username"))
.sendKeys(`${process.env.EMAIL}`);
// click next
await driver.findElement(By.id("usernameSubmitButton")).click();
// enter password
let pwd = driver.wait(until.elementLocated(By.id("password")), 5000);
await driver
.wait(until.elementIsVisible(pwd), 5000)
.sendKeys(`${process.env.PASSWORD}`);
// click sign in
let signInBtn = driver.wait(
until.elementLocated(By.id("submitButton")),
5000
);
await driver.wait(until.elementIsVisible(signInBtn), 5000).click();
// wait for 30 secs to ensure sign in is done
await driver.wait(
until.titleIs("Dashboard | ServiceNow Developers"),
30000
);
// go to instances
console.log('Checking your instance...');
await driver.get("https://developer.servicenow.com/app.do#!/instance");
// wake up instance
let wakeInstanceBtn = driver.wait(
until.elementLocated(By.id("instanceWakeUpBtn")),
5000
);
console.log('Waking your instance up!');
await driver.wait(until.elementIsVisible(wakeInstanceBtn), 5000).click();
} catch (e) {
} finally {
// Wait 5 minutes before terminating Selenium
setTimeout(async () => {
await driver.quit();
}, 300000);
}
})();