forked from Schibsted-Tech-Polska/stp.pediff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pediff.sh
executable file
·86 lines (81 loc) · 2.69 KB
/
pediff.sh
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
#!/bin/bash
start=`date +%s`
mkdir -p candidate current diff
rm -rf candidate/*
rm -rf current/*
rm -rf diff/*
mkdir -p candidate/hq current/hq diff/hq candidate/html current/html candidate/html/failed current/html/failed
rm -f report.json
touch report.json
rm -f paths.json
touch paths.json
# Start new phantomjs process for each task in /tasks directory. Run up to $1 processes at once if $1 is set
tasksRunning=0
echo "Taking screenshots..."
for file in `ls tasks/*.js | xargs -n 1 basename`;
do
casperjs run.js --web-security=no ${file} &
tasksRunning=$(($tasksRunning+1))
if [[ $1 && $tasksRunning -ge $1 ]]; then
wait
tasksRunning=0
fi
done
wait
# Use ImageMagick compare tool to render perceptual diffs between candidate and current pages
echo "Calculating differences..."
cd candidate/
for file in *.png;
do
candidate=${file};
current=../current/${file};
if [ ! -f ${candidate} -o ! -f ${current} ]
then
continue
fi
canH=$(identify -format %h ${candidate});
currH=$(identify -format %h ${current});
# Compare files dimensions and extend them if necessary
if [ "$canH" -gt "$currH" ]; then
convert ${current} -gravity north -extent $(identify -format %w ${current})x${canH} ${current}
fi
if [ "$currH" -gt "$canH" ]; then
convert ${candidate} -gravity north -extent $(identify -format %w ${candidate})x${currH} ${candidate}
fi
# Assign absolute number of pixels that are different to a variable
ae=$(compare -dissimilarity-threshold 1 -metric AE ${candidate} ${current} ../diff/${file} 2>&1)
# Handle different implementations of grep
if [[ `uname` == 'Darwin' ]]; then
fsize=$(echo ${file} | grep -Eo --color=never '\d+x\d+' | tr 'x' '*' | bc)
else
fsize=$(echo ${file} | grep -Po '\d+x\d+' | tr 'x' '*' | bc)
fi
# Add relative error factor to the name of the files for sorting
factor=$(echo "$ae/$fsize" | sed -e 's/[eE]+*/\*10\^/' | bc -l | cut -c -9 | tr -d '.')
newfname=${factor}_${file}
mv ../diff/${file} ../diff/${newfname}
mv ../candidate/${file} ../candidate/${newfname}
mv ../current/${file} ../current/${newfname}
done
echo "Generating previews..."
for env in diff candidate current
do
cd ../${env}
for file in *.png;
do
if [ ! -f ${file} ]
then
continue
fi
convert ${file} -strip -interlace Plane -quality 75% ${file%.png}.jpg
mv ${file} hq/${file}
done
done
end=`date +%s`
runtime=$((end-start))
filecount=$(ls -1 *.jpg | wc -l | tr -d ' ')
cd ../
echo "Generating report..."
casperjs report.js
casperjs coverage.js
echo "Pediff has taken and compared ${filecount} screenshots in ${runtime} seconds."