-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselenium.js
59 lines (48 loc) · 1.7 KB
/
selenium.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
//https://github.com/SeleniumHQ/selenium/tree/master/javascript/node/selenium-webdriver
const {Builder, By, Key, until, logging} = require('selenium-webdriver');
const fs = require('fs');
(async function example() {
let theScript = fs.readFileSync('speed_test_scraper.js', 'utf8');
let caps = {
"browserName": 'chrome', // chrome, firefox
"loggingPrefs": {
'driver': 'DEBUG',
'browser': 'INFO'
}
};
// let driver = await new Builder().forBrowser('chrome').withCapabilities(caps).build();
let driver = await new Builder()
.usingServer()
.withCapabilities(caps).build();
try {
await driver.get('http://plumewifi.speedtestcustom.com/').then(()=> {
// console.log('[%s] %s', entry.level.name, entry.message);
console.log('page loaded');
});
driver.executeScript(theScript + "ooklaTest.init('selenium');").then(() => {
console.log('script loaded');
},() =>{
console.log('failure!!!!!!!!!!!!!!!!!');
});
let testOver = false;
let logs = function(){
driver.manage().logs().get(logging.Type.BROWSER)
.then((logs) => {
// console.log('logs?');
logs.forEach(log => {
if (log.message.includes("completed") || log.message.includes("failed")){
console.log("RESULT: " + log.message + " " + log.timestamp);
testOver = true;
}
// console.log(log.message + " " + log.timestamp);
})
})
}
// await driver.wait(until(function(){return testOver}), 121000).then((logstring) => {console.log("test ended")});
driver.sleep(121000);
} catch(err) {
console.log("!!!!" + err);
} finally {
// await driver.quit();
}
})();