-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrowser.js
More file actions
69 lines (52 loc) · 1.41 KB
/
Copy pathbrowser.js
File metadata and controls
69 lines (52 loc) · 1.41 KB
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
/*
Wrapper for headless browser.
Niels Groot Obbink
*/
'use strict';
var phantomjs = require('phantomjs-prebuilt-that-works')
var selenium = require('selenium-webdriver')
module.exports = function()
{
this.driver = null;
this.min_required_time = 5000;
this.start = function()
{
// Change the binary path from the default selenium phantomjs settings.
let phantomjs_capabilities = selenium.Capabilities.phantomjs();
phantomjs_capabilities.set("phantomjs.binary.path", phantomjs.path);
// Build a custom phantomJS driver.
this.driver = new selenium.Builder().withCapabilities(phantomjs_capabilities).build();
};
this.load = function(url, timeout, success)
{
let me = this;
// Load the page.
this.driver.get(url);
// The function to run.
let runner = function()
{
let logs = [];
// Retrieve console.log results.
me.driver.manage().logs().get('browser').then(function(entries)
{
entries.forEach(function(entry)
{
logs.push(entry.message);
});
success(logs);
});
};
// After the timeout, collect the console.log entries and call the success callback function.
if(timeout)
{
// Wait at least min_required_time (browser startup time) seconds, more if we have a longer timeout.
setTimeout(runner, Math.max(timeout, me.min_required_time));
}else{
setTimeout(runner, me.min_required_time);
}
};
this.stop = function()
{
this.driver.quit();
}
};