Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit ff3d5eb

Browse files
elgalujuliemr
authored andcommitted
feat(locators): add toString() wrapper for this.message
1 parent f9082d0 commit ff3d5eb

File tree

2 files changed

+45
-20
lines changed

2 files changed

+45
-20
lines changed

lib/locators.js

+44-19
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ ProtractorBy.prototype.addLocator = function(name, script) {
6565
return driver.findElements(
6666
webdriver.By.js.apply(webdriver.By, findElementArguments));
6767
},
68-
message: 'by.' + name + '("' + Array.prototype.join.call(locatorArguments, '", "') + '")'
68+
toString: function toString() {
69+
return 'by.' + name + '("' + Array.prototype.
70+
join.call(locatorArguments, '", "') + '")';
71+
}
6972
};
7073
};
7174
};
@@ -86,7 +89,7 @@ ProtractorBy.prototype.addLocator = function(name, script) {
8689
* expect(span2.getText()).toBe('[email protected]');
8790
*
8891
* @param {string} bindingDescriptor
89-
* @return {{findElementsOverride: findElementsOverride, message: string}}
92+
* @return {{findElementsOverride: findElementsOverride, toString: Function|string}}
9093
*/
9194
ProtractorBy.prototype.binding = function(bindingDescriptor) {
9295
return {
@@ -95,7 +98,9 @@ ProtractorBy.prototype.binding = function(bindingDescriptor) {
9598
webdriver.By.js(clientSideScripts.findBindings,
9699
bindingDescriptor, false, using));
97100
},
98-
message: 'by.binding("' + bindingDescriptor + '")'
101+
toString: function toString() {
102+
return 'by.binding("' + bindingDescriptor + '")';
103+
}
99104
};
100105
};
101106

@@ -117,7 +122,7 @@ ProtractorBy.prototype.binding = function(bindingDescriptor) {
117122
* expect(element(by.exactBinding('phone')).isPresent()).toBe(false);
118123
*
119124
* @param {string} bindingDescriptor
120-
* @return {{findElementsOverride: findElementsOverride, message: string}}
125+
* @return {{findElementsOverride: findElementsOverride, toString: Function|string}}
121126
*/
122127
ProtractorBy.prototype.exactBinding = function(bindingDescriptor) {
123128
return {
@@ -126,7 +131,9 @@ ProtractorBy.prototype.exactBinding = function(bindingDescriptor) {
126131
webdriver.By.js(clientSideScripts.findBindings,
127132
bindingDescriptor, true, using));
128133
},
129-
message: 'by.exactBinding("' + bindingDescriptor + '")'
134+
toString: function toString() {
135+
return 'by.exactBinding("' + bindingDescriptor + '")';
136+
}
130137
};
131138
};
132139

@@ -150,7 +157,9 @@ ProtractorBy.prototype.model = function(model) {
150157
return driver.findElements(
151158
webdriver.By.js(clientSideScripts.findByModel, model, using));
152159
},
153-
message: 'by.model("' + model + '")'
160+
toString: function toString() {
161+
return 'by.model("' + model + '")';
162+
}
154163
};
155164
};
156165

@@ -164,7 +173,7 @@ ProtractorBy.prototype.model = function(model) {
164173
* element(by.buttonText('Save'));
165174
*
166175
* @param {string} searchText
167-
* @return {{findElementsOverride: findElementsOverride, message: string}}
176+
* @return {{findElementsOverride: findElementsOverride, toString: Function|string}}
168177
*/
169178
ProtractorBy.prototype.buttonText = function(searchText) {
170179
return {
@@ -173,7 +182,9 @@ ProtractorBy.prototype.buttonText = function(searchText) {
173182
webdriver.By.js(clientSideScripts.findByButtonText,
174183
searchText, using));
175184
},
176-
message: 'by.buttonText("' + searchText + '")'
185+
toString: function toString() {
186+
return 'by.buttonText("' + searchText + '")';
187+
}
177188
};
178189
};
179190

@@ -187,7 +198,7 @@ ProtractorBy.prototype.buttonText = function(searchText) {
187198
* element(by.partialButtonText('Save'));
188199
*
189200
* @param {string} searchText
190-
* @return {{findElementsOverride: findElementsOverride, message: string}}
201+
* @return {{findElementsOverride: findElementsOverride, toString: Function|string}}
191202
*/
192203
ProtractorBy.prototype.partialButtonText = function(searchText) {
193204
return {
@@ -196,7 +207,9 @@ ProtractorBy.prototype.partialButtonText = function(searchText) {
196207
webdriver.By.js(clientSideScripts.findByPartialButtonText,
197208
searchText, using));
198209
},
199-
message: 'by.partialButtonText("' + searchText + '")'
210+
toString: function toString() {
211+
return 'by.partialButtonText("' + searchText + '")';
212+
}
200213
};
201214
};
202215

@@ -259,24 +272,30 @@ ProtractorBy.prototype.repeater = function(repeatDescriptor) {
259272
webdriver.By.js(clientSideScripts.findAllRepeaterRows,
260273
repeatDescriptor, using));
261274
},
262-
message: 'by.repeater("' + repeatDescriptor + '")',
275+
toString: function toString() {
276+
return 'by.repeater("' + repeatDescriptor + '")';
277+
},
263278
row: function(index) {
264279
return {
265280
findElementsOverride: function(driver, using) {
266281
return driver.findElements(
267282
webdriver.By.js(clientSideScripts.findRepeaterRows,
268283
repeatDescriptor, index, using));
269284
},
270-
message: 'by.repeater(' + repeatDescriptor + '").row("' + index + '")"',
285+
toString: function toString() {
286+
return 'by.repeater(' + repeatDescriptor + '").row("' + index + '")"';
287+
},
271288
column: function(binding) {
272289
return {
273290
findElementsOverride: function(driver, using) {
274291
return driver.findElements(
275292
webdriver.By.js(clientSideScripts.findRepeaterElement,
276293
repeatDescriptor, index, binding, using));
277294
},
278-
message: 'by.repeater("' + repeatDescriptor + '").row("' + index +
279-
'").column("' + binding + '")'
295+
toString: function toString() {
296+
return 'by.repeater("' + repeatDescriptor + '").row("' + index +
297+
'").column("' + binding + '")';
298+
}
280299
};
281300
}
282301
};
@@ -288,17 +307,21 @@ ProtractorBy.prototype.repeater = function(repeatDescriptor) {
288307
webdriver.By.js(clientSideScripts.findRepeaterColumn,
289308
repeatDescriptor, binding, using));
290309
},
291-
message: 'by.repeater("' + repeatDescriptor + '").column("' + binding +
292-
'")',
310+
toString: function toString() {
311+
return 'by.repeater("' + repeatDescriptor + '").column("' +
312+
binding + '")';
313+
},
293314
row: function(index) {
294315
return {
295316
findElementsOverride: function(driver, using) {
296317
return driver.findElements(
297318
webdriver.By.js(clientSideScripts.findRepeaterElement,
298319
repeatDescriptor, index, binding, using));
299320
},
300-
message: 'by.repeater("' + repeatDescriptor + '").column("' +
301-
binding + '").row("' + index + '")'
321+
toString: function toString() {
322+
return 'by.repeater("' + repeatDescriptor + '").column("' +
323+
binding + '").row("' + index + '")';
324+
}
302325
};
303326
}
304327
};
@@ -326,7 +349,9 @@ ProtractorBy.prototype.cssContainingText = function(cssSelector, searchText) {
326349
webdriver.By.js(clientSideScripts.findByCssContainingText,
327350
cssSelector, searchText, using));
328351
},
329-
message: 'by.cssContainingText("' + cssSelector + '", "' + searchText + '")'
352+
toString: function toString() {
353+
return 'by.cssContainingText("' + cssSelector + '", "' + searchText + '")';
354+
}
330355
};
331356
};
332357

lib/protractor.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ var buildElementHelper = function(ptor) {
568568
this.locator_, this.parentElementFinder_).getWebElements();
569569

570570
var id = webElementsPromise.then(function(arr) {
571-
var locatorMessage = (self.locator_.message || self.locator_.toString());
571+
var locatorMessage = self.locator_.toString();
572572
if (!arr.length) {
573573
throw new Error('No element found using locator: ' + locatorMessage);
574574
}

0 commit comments

Comments
 (0)