-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
123 lines (107 loc) · 3.17 KB
/
test.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*global mw, ve, $ */
var casper, articleName, url;
function msg(text) {
casper.echo('[ve-dirtydiffbot] ' + text);
}
casper = require('casper').create({
viewportSize: {
width: 1280,
height: 1024
},
stepTimeout: 45000,
timeout: 45000,
waitTimeout: 45000,
onTimeout: function () {
casper.echo('timeout!');
casper.exit();
},
onError: function () {
casper.echo('error!');
casper.exit();
},
verbose: true,
logLevel: 'debug',
onPageInitialized: function () {
casper.evaluate(function () {
/* Placeholder to execute code early on when the DOM is ready */
});
}
});
articleName = casper.cli.args.length === 0 ? 'Special:Random' : casper.cli.args[0];
url = 'http://en.wikipedia.org/wiki/' + encodeURIComponent(articleName);
msg('Loading page "' + articleName + '"...');
casper.userAgent(phantom.defaultPageSettings.userAgent + ' CasperJS/' + phantom.casperVersion + ' ve-dirtydiffbot');
casper.start(url, function () {
articleName = this.evaluate(function () {
return mw.config.get('wgPageName');
});
msg('Loaded "' + articleName + '"');
msg('VisualEditor initializing...');
this.evaluate(function () {
mw.loader.using(['ext.visualEditor.viewPageTarget.init', 'jquery.cookie'], function () {
if (mw.libs.ve.isAvailable && !$('html').hasClass('ve-available')) {
$('html')
.removeClass('ve-not-available')
.addClass('ve-available');
mw.libs.ve.setupSkin();
}
// Override welcome dialog
$.cookie('ve-beta-welcome-dialog', '1', { path: '/' });
mw.libs.ve.onEditTabClick(new $.Event('click'));
});
});
this.waitFor(function () {
return this.evaluate(function () {
return ve.init.target && ve.init.target.active === true;
});
});
});
casper.then(function () {
msg('VisualEditor initialized');
msg('VisualEditor generating diff...');
this.evaluate(function () {
ve.init.target.edited = true;
ve.init.target.toolbarSaveButton.setDisabled(false);
ve.init.target.onToolbarSaveButtonClick();
setTimeout(function () {
ve.init.target.onSaveDialogReview();
}, 2000);
});
this.wait(500, function () {
this.waitFor(function () {
return this.evaluate(function () {
return ve.init.target.saveDialog.isPending() === false;
});
});
});
});
casper.then(function () {
var clipRect, diffLength;
diffLength = this.evaluate(function () {
var saveDialog = ve.init.target.saveDialog;
return saveDialog.$body.find('.diff tr').length;
});
if (diffLength > 1) {
msg('VisualEditor got dirty diff');
msg('Capturing diff and writing to disk for analysis');
clipRect = this.evaluate(function () {
var saveDialog = ve.init.target.saveDialog,
$frame = $('.oo-ui-window-frame').css('height', '');
return {
top: $frame.offset().top,
left: $frame.offset().left,
width: $frame.outerWidth(),
// Can't use outerHeight of frame because it is too fluid,
// it expanded to the max 10000px available instantly
height: saveDialog.$reviewViewer.outerHeight() + 150
};
});
this.capture(articleName.replace(/ /g, '_').replace(/[^a-zA-Z0-9_\-]/g, '-') + '.png', clipRect);
} else {
msg('VisualEditor got clean diff');
}
});
casper.run(function () {
msg('Closing "' + articleName + '"...');
this.exit();
});