forked from jamesshore/lets_code_javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_phantomjs.js
More file actions
51 lines (42 loc) · 1.2 KB
/
_phantomjs.js
File metadata and controls
51 lines (42 loc) · 1.2 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
// Copyright (c) 2013 Titanium I.T. LLC. All rights reserved. See LICENSE.TXT for details.
/*global phantom, document */
(function() {
"use strict";
var page = require("webpage").create();
page.onConsoleMessage = function(message) {
console.log("CONSOLE: " + message);
};
page.open("http://localhost:5000", function(success) {
try {
var error = page.evaluate(inBrowser);
if (error) {
console.log(error);
phantom.exit(1);
}
else {
phantom.exit(0);
}
}
catch(err) {
console.log("Exception in PhantomJS code");
phantom.exit(1);
}
});
function inBrowser() {
try {
var client = require("./client.js");
var HtmlElement = require("./html_element.js");
var drawingArea = new HtmlElement(document.getElementById("drawingArea"));
drawingArea.doMouseDown(10, 20);
drawingArea.doMouseMove(50, 60);
drawingArea.doMouseUp(50, 60);
var actual = JSON.stringify(client.drawingAreaCanvas.lineSegments());
var expected = JSON.stringify([[ "10", "20", "50", "60" ]]);
if (actual !== expected) return "lines drawn expected " + expected + " but was " + actual;
else return null;
}
catch(err) {
return "Exception in PhantomJS browser code";
}
}
}());