forked from admc/se-builder
-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathscript.js
More file actions
177 lines (166 loc) · 5.03 KB
/
script.js
File metadata and controls
177 lines (166 loc) · 5.03 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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
builder.breakpointsEnabled = true;
/**
* Defines a Script object that encapsulates a single test script.
*/
builder.Script = function(seleniumVersion) {
this.id = builder.__idCounter;
builder.__idCounter++;
this.steps = [];
this.seleniumVersion = seleniumVersion;
this.path = null;
this.saveRequired = false;
this.data = {'configs':{}, 'source': 'none'};
this.inputs = [];
this.timeoutSeconds = 60;
};
builder.Script.prototype = {
getStepIndexForID: function(id) {
for (var i = 0; i < this.steps.length; i++) {
if (this.steps[i].id == id) { return i; }
}
return -1;
},
getStepWithID: function(id) {
var index = this.getStepIndexForID(id);
return index == -1 ? null : this.steps[index];
},
getLastStep: function() {
return this.steps.length == 0 ? null : this.steps[this.steps.length - 1];
},
getStepBefore: function(step) {
var index = this.getStepIndexForID(step.id);
if (index > 0) {
return this.steps[index - 1];
} else {
return null;
}
},
getStepAfter: function(step) {
var index = this.getStepIndexForID(step.id);
if (index < this.steps.length - 1) {
return this.steps[index + 1];
} else {
return null;
}
},
removeStepWithID: function(id) {
var index = this.getStepIndexForID(id);
if (index !== -1) {
var step = this.steps[index];
this.steps.splice(index, 1);
return step;
}
return null;
},
addStep: function(step, afterID) {
if (afterID) {
var index = this.getStepIndexForID(afterID);
if (index !== -1) {
this.steps.splice(index, 0, step);
}
}
this.steps.push(step);
},
insertStep: function(step, beforeIndex) {
if (beforeIndex < this.steps.length) {
this.steps.splice(beforeIndex, 0, step);
} else {
this.steps.push(step);
}
},
moveStepToBefore: function(stepID, beforeStepID) {
var step = this.removeStepWithID(stepID);
this.steps.splice(this.getStepIndexForID(beforeStepID), 0, step);
},
moveStepToAfter: function(stepID, afterStepID) {
var step = this.removeStepWithID(stepID);
if (this.getLastStep().id == afterStepID) {
this.steps.push(step);
} else {
this.steps.splice(this.getStepIndexForID(afterStepID) + 1, 0, step);
}
},
reorderSteps: function(reorderedIDs) {
var newSteps = [];
for (var i = 0; i < reorderedIDs.length; i++) {
newSteps.push(this.getStepWithID(reorderedIDs[i]));
}
this.steps = newSteps;
}
};
/** Global counter for generating unique IDs for steps. */
builder.__idCounter = 1; // Start at 1 so the ID is always true.
/**
* @param type The type of step (from builder.selenium1.stepTypes or builder.selenium2.stepTypes)
* Further arguments used as step parameters.
*/
builder.Step = function(type) {
this.type = type;
this.id = builder.__idCounter;
this.negated = false;
this.step_name = null; // Can be null for default numbering.
builder.__idCounter++;
var pNames = this.type.getParamNames();
if (pNames) {
for (var i = 0; i < pNames.length; i++) {
if (i + 1 < arguments.length) {
this[pNames[i]] = arguments[i + 1];
} else {
this[pNames[i]] = this.type.getParamType(pNames[i]) == "locator" ? builder.locator.empty() : "";
}
}
}
this.changeType(this.type);
};
builder.stepFromJSON = function(parsedJSON, seleniumVersion) {
if (!seleniumVersion.stepTypes[parsedJSON.type]) {
throw new Error(_t("sel1_no_command_found") + ": " + parsedJSON.type);
}
var step = new builder.Step(seleniumVersion.stepTypes[parsedJSON.type]);
step.negated = parsedJSON.negated || false;
step.step_name = parsedJSON.step_name || null;
var pNames = step.getParamNames();
for (var j = 0; j < pNames.length; j++) {
if (parsedJSON[pNames[j]]) {
if (step.type.getParamType(pNames[j]) == "locator") {
step[pNames[j]] = builder.selenium2.io.jsonToLoc(parsedJSON[pNames[j]]);
} else {
step[pNames[j]] = "" + parsedJSON[pNames[j]];
}
}
}
return step;
};
builder.Step.prototype = {
getParamNames: function() {
return this.type.getParamNames();
},
changeType: function(newType) {
this.type = newType;
var pNames = this.type.getParamNames();
for (var i = 0; i < pNames.length; i++) {
if (!this[pNames[i]]) {
this[pNames[i]] = this.type.getParamType(pNames[i]) == "locator" ? builder.locator.empty() : "";
}
}
},
toJSON: function() {
var cleanStep = { type: this.type.name };
if (this.negated) {
cleanStep.negated = true;
}
if (this.step_name) {
cleanStep.step_name = this.step_name;
}
var pNames = this.getParamNames();
for (var j = 0; j < pNames.length; j++) {
if (this.type.getParamType(pNames[j]) == "locator") {
cleanStep[pNames[j]] = builder.selenium2.io.locToJSON(this[pNames[j]]);
} else {
cleanStep[pNames[j]] = this[pNames[j]];
}
}
return cleanStep;
}
};
if (builder && builder.loader && builder.loader.loadNextMainScript) { builder.loader.loadNextMainScript(); }