-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
70 lines (58 loc) · 1.72 KB
/
server.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
"use strict"
const express = require("express")
const blinkDiff = require("blink-diff")
const geckodriver = require("geckodriver")
const {Builder, By, Key, until} = require("selenium-webdriver")
const fs = require("fs")
// const pages = require("./testPages")
// deleted ^
const PORT = 8080
const HOST = "0.0.0.0"
const app = express()
app.get("/", (req, res) => {
res.send("Hello world\n")
})
app.get("/nightwatch", (req, res) => {
res.send("Hello nightwatch\n")
})
app.get("/run", (req, res) => {
new Builder()
.forBrowser("chrome")
.build()
.then(driver => {
driver.manage().window().maximize()
let page = pages["signin"]
return driver.get("https://" + page)
.then(_ => takeScreenshot(driver, "signin"))
.then(_ => runBlinkDiff("signin"))
.then(_ => driver.quit())
})
res.send("Builder has run")
})
app.listen(PORT, HOST)
console.log(`Running on http://${HOST}:${PORT}`)
function takeScreenshot(driver, page) {
return driver.takeScreenshot()
.then(function(data, err) {
fs.writeFile("./Screenshots/new/" + page + ".png", data, "base64", function(err) {
if (err) console.log(err)
})
})
}
function runBlinkDiff(page) {
let diff = new blinkDiff({
imageAPath: "./Screenshots/master/" + page + ".png",
imageBPath: "./Screenshots/new/" + page + ".png",
thresholdType: blinkDiff.THRESHOLD_PERCENT,
threshold: 0.01, // 1% threshold
imageOutputPath: "./Screenshots/result/" + page + "_result.png"
})
diff.run(function (error, result) {
if (error) {
throw error
} else {
console.log(diff.hasPassed(result.code) ? "Passed" : "Failed")
console.log("Found " + result.differences + " differences.")
}
})
}