-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.js
96 lines (86 loc) · 2.53 KB
/
example.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
96
/*
* Reboot Technicolor modem.
*
* Puppeteer container for rebooting an Technicolor modem.
* since the specific navigation for your modem will vary, this
* is more of an example and isn't guaranteed to work for your particular
* modem.
* Many thanks to https://gist.github.com/mbierman/5b3e671fa4e848eec899ff486d0cdc26
and https://stackoverflow.com/users/6870228/keith
*
*/
const puppeteer = require('puppeteer');
const date = require('date-and-time');
const isDocker = require('is-docker');
const USER = process.env.USER || "custadmin";
const PASS = process.env.PASS || "cga4233";
const URL = process.env.URL || "URL";
var browser;
const delay = (ms) =>
new Promise((resolve) => setTimeout(resolve, ms));
async function timeMe(num, txt) {
let now = new Date();
let time = date.format(now, 'dddd MM/DD/YYYY HH:mm:ss, ');
console.log(time, txt);
}
process.on("unhandledRejection", (reason, p) => {
console.error("Unhandled Rejection at: Promise (new page)", p, "reason:", reason);
browser.close();
});
(async() => {
if (isDocker()) {
console.log('Running inside a Docker container');
browser =await puppeteer.launch({
executablePath: '/usr/bin/chromium-browser',
args: ['--no-sandbox', '--headless', '--disable-gpu']
});
}
else{
browser = await puppeteer.launch({
headless: false
});
}
timeMe(1, 'Login...');
const page = await browser.newPage();
await page.setViewport({
width: 1366,
height: 768
});
await delay(1000);
await page.goto(URL+'/#/login', {
waitUntil: 'load',
timeout: 0
});;
await delay(10000);
await page.type('input#username', USER, {
delay: 30
});
await page.type('input[type="password"]', PASS, {
delay: 10
});
const form = await page.$('#login-button');
await form.evaluate( form => form.click() );
await delay(10000);
timeMe(1, 'Go to reboots...');
await page.screenshot({path: 'screenshot_before.png'});
await page.goto(URL+'/#/administration/reset', {
waitUntil: 'load',
timeout: 20000
});
await page.screenshot({path: 'screenshot_after.png'});
await delay(4000);
page.click( "#reset_content_container > div.table_only_data > div:nth-child(1) > div:nth-child(4) > div:nth-child(2) > button" )
timeMe(1, 'Waiting for dialog');
await page.on("dialog", (dialog) => {
timeMe(1, 'Dialog is up');
delay(4000);
dialog.accept();
timeMe(1, "Accepted...");
delay(4000);
});
timeMe(1, 'Pause...');
await delay(10000);
timeMe(1, 'Exiting...');
await browser.close();
process.exit(1);
})()