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

Commit b131309

Browse files
Mike Stickeljuliemr
Mike Stickel
authored andcommitted
feat(locators): add textarea locator
Add locator to findElement by textarea
1 parent f56357a commit b131309

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed

Diff for: lib/clientsidescripts.js

+21
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,27 @@ clientSideScripts.findSelectedOption = function() {
278278
}
279279
};
280280

281+
/**
282+
* Find a textarea element by model name.
283+
*
284+
* arguments[0] {Element} The scope of the search.
285+
* arguments[1] {String} The model name.
286+
*
287+
* @return {Element} The first matching textarea element.
288+
*/
289+
clientSideScripts.findTextarea = function() {
290+
var using = arguments[0] || document;
291+
var model = arguments[1];
292+
var prefixes = ['ng-', 'ng_', 'data-ng-', 'x-ng-', 'ng\\:'];
293+
for (var p = 0; p < prefixes.length; ++p) {
294+
var selector = 'textarea[' + prefixes[p] + 'model="' + model + '"]';
295+
var textareas = using.querySelectorAll(selector);
296+
if (textareas.length) {
297+
return textareas[0];
298+
}
299+
}
300+
};
301+
281302
/**
282303
* Tests whether the angular global variable is present on a page. Retries
283304
* in case the page is just loading slowly.

Diff for: lib/locators.js

+9
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ ProtractorBy.prototype.input = function(model) {
7777
};
7878
};
7979

80+
ProtractorBy.prototype.textarea = function(model) {
81+
return {
82+
findOverride: function(driver, using) {
83+
return driver.findElement(
84+
webdriver.By.js(clientSideScripts.findTextarea), using, model);
85+
}
86+
};
87+
};
88+
8089
/**
8190
* Usage:
8291
* <div ng-repeat = "cat in pets">

Diff for: spec/findelements_spec.js

+11
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ describe('finding elements', function() {
4848
toBe(false);
4949
});
5050

51+
it('should find an element by textarea model', function() {
52+
var about = ptor.findElement(protractor.By.textarea('aboutbox'));
53+
expect(about.getAttribute('value')).toEqual('This is a text box');
54+
55+
about.clear();
56+
about.sendKeys('Something else to write about');
57+
58+
expect(about.getAttribute('value')).
59+
toEqual('Something else to write about');
60+
});
61+
5162
it('should find inputs with alternate attribute forms', function() {
5263
var letterList = ptor.findElement(protractor.By.id('letterlist'));
5364
expect(letterList.getText()).toBe('');

Diff for: testapp/app/js/controllers.js

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ BindingsCtrl.$inject = ['$scope'];
101101
function FormCtrl($scope) {
102102
$scope.greeting = "Hiya";
103103
$scope.username = "Anon";
104+
$scope.aboutbox = "This is a text box";
104105
$scope.color = "blue";
105106
$scope.show = true;
106107
$scope.days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'];

Diff for: testapp/app/partials/form.html

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
<div>Username
33
<input ng-model="username" type="text"/>
44
</div>
5+
<div>Textarea
6+
<textarea ng-model="aboutbox"></textarea>
7+
</div>
58
<div ng-style="{'color': color}">Color <br/>
69
<input ng-model="color" value="blue" type="radio"/> blue <br/>
710
<input ng-model="color" value="green" type="radio"/> green <br/>

0 commit comments

Comments
 (0)