forked from trywildcard/resurrectio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.js
119 lines (101 loc) · 3.06 KB
/
doc.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
// ---------------------------------------------------------------------------
// DocumentRenderer -- a class to render recorded tests to a DocumentJS
// test format.
// ---------------------------------------------------------------------------
if (typeof(EventTypes) == "undefined") {
EventTypes = {};
}
EventTypes.OpenUrl = 0;
EventTypes.Click = 1;
EventTypes.Change = 2;
EventTypes.Comment = 3;
EventTypes.Submit = 4;
EventTypes.CheckPageTitle = 5;
EventTypes.CheckPageLocation = 6;
EventTypes.CheckTextPresent = 7;
EventTypes.CheckValue = 8;
EventTypes.CheckValueContains = 9;
EventTypes.CheckText = 10;
EventTypes.CheckHref = 11;
EventTypes.CheckEnabled = 12;
EventTypes.CheckDisabled = 13;
EventTypes.CheckSelectValue = 14;
EventTypes.CheckSelectOptions = 15;
EventTypes.CheckImageSrc = 16;
EventTypes.PageLoad = 17;
EventTypes.ScreenShot = 18;
function DocumentRenderer(document) {
this.document = document;
this.title = "Testcase";
this.items = null;
this.history = new Array();
this.screen_id = 1;
}
DocumentRenderer.prototype.text = function(txt) {
// todo: long lines
this.document.writeln(txt);
}
DocumentRenderer.prototype.stmt = function(text) {
this.document.writeln(text);
}
DocumentRenderer.prototype.cont = function(text) {
this.document.writeln(" ... " + text);
}
DocumentRenderer.prototype.pyout = function(text) {
this.document.writeln(" " + text);
}
DocumentRenderer.prototype.pyrepr = function(text) {
// todo: handle non--strings & quoting
return "'" + text + "'";
}
DocumentRenderer.prototype.space = function() {
this.document.write("\n");
}
var d = {};
d[EventTypes.Comment] = "comment";
d[EventTypes.ScreenShot] = "screenShot";
DocumentRenderer.prototype.dispatch = d;
var cc = EventTypes;
DocumentRenderer.prototype.render = function() {
var etypes = EventTypes;
this.document.open();
this.document.write("<" + "pre" + ">");
this.writeHeader();
for (var i=0; i < this.items.length; i++) {
var item = this.items[i];
if (this.dispatch[item.type]) {
this[this.dispatch[item.type]](item);
}
}
this.writeFooter();
this.document.write("<" + "/" + "pre" + ">");
this.document.close();
}
DocumentRenderer.prototype.writeHeader = function() {
var date = new Date();
this.text("Document generated " + date);
this.text("==============================================================================");
this.space();
}
DocumentRenderer.prototype.writeFooter = function() {
this.space();
}
DocumentRenderer.prototype.normalizeWhitespace = function(s) {
return s.replace(/^\s*/, '').replace(/\s*$/, '').replace(/\s+/g, ' ');
}
DocumentRenderer.prototype.screenShot = function(item) {
this.stmt('.. image:: screenshot'+this.screen_id+'.png');
this.space();
this.screen_id = this.screen_id + 1;
}
DocumentRenderer.prototype.comment = function(item) {
this.text(item.text);
this.space();
}
var dt = new DocumentRenderer(document);
window.onload = function onpageload() {
chrome.extension.sendRequest({action: "get_items"}, function(response) {
dt.items = response.items;
dt.render();
});
};