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

Commit 207b231

Browse files
committed
Merge pull request #1 from jeffbcross/inherit-By
Inherited protractor.By from webdriver.By
2 parents fe69d19 + 90efe10 commit 207b231

File tree

2 files changed

+54
-47
lines changed

2 files changed

+54
-47
lines changed

httpspec.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ ptor.get('http://localhost:8000/app/index.html');
3737

3838
// Could still use driver.get to get a URL normally, without injecting modules.
3939

40-
ptor.findElement(webdriver.By.css('[app-version]')).getText().then(function(text) {
40+
ptor.findElement(protractor.By.css('[app-version]')).getText().then(function(text) {
4141
assert.equal('3', text);
4242
});
4343

44-
var sample1Button = driver.findElement(webdriver.By.id('sample1'));
45-
var sample2Button = driver.findElement(webdriver.By.id('sample2'));
44+
var sample1Button = driver.findElement(protractor.By.id('sample1'));
45+
var sample2Button = driver.findElement(protractor.By.id('sample2'));
4646
sample1Button.click();
4747

48-
var fetchButton = driver.findElement(webdriver.By.id('fetch'));
48+
var fetchButton = driver.findElement(protractor.By.id('fetch'));
4949
fetchButton.click();
5050

5151
// The quick RPC works fine.
@@ -61,10 +61,10 @@ ptor.findElement(protractor.By.binding(), "{{data}}").getText().then(function(te
6161
sample2Button.click();
6262
fetchButton.click();
6363
// Would normally need driver.sleep(2) or something.
64-
ptor.findElement(webdriver.By.id('statuscode')).getText().then(function(text) {
64+
ptor.findElement(protractor.By.id('statuscode')).getText().then(function(text) {
6565
assert.equal('200', text);
6666
});
67-
ptor.findElement(webdriver.By.id('data')).getText().then(function(text) {
67+
ptor.findElement(protractor.By.id('data')).getText().then(function(text) {
6868
assert.equal('finally done', text);
6969
});
7070

@@ -73,7 +73,7 @@ var urlBox = ptor.findElement(protractor.By.input('url'));
7373
urlBox.clear();
7474
urlBox.sendKeys('/3seccall');
7575
fetchButton.click();
76-
ptor.findElement(webdriver.By.id('data')).getText().then(function(text) {
76+
ptor.findElement(protractor.By.id('data')).getText().then(function(text) {
7777
assert.equal('done after 3 seconds', text);
7878
});
7979

@@ -86,12 +86,12 @@ ptor.addMockModule('moduleA', mockModuleA);
8686
ptor.get('http://localhost:8000/app/index.html#/bindings');
8787

8888
// Now, version should be 2, since only moduleA has been loaded.
89-
ptor.findElement(webdriver.By.css('[app-version]')).getText().then(function(text) {
89+
ptor.findElement(protractor.By.css('[app-version]')).getText().then(function(text) {
9090
assert.equal('2', text);
9191
});
9292

9393
ptor.findElement(protractor.By.select('planet')).
94-
findElements(webdriver.By.tagName("option")).then(function(planetOptions) {
94+
findElements(protractor.By.tagName("option")).then(function(planetOptions) {
9595
for (var i = 0; i < planetOptions.length; ++i) {
9696
planetOptions[i].getText().then(function(text) {
9797
util.puts(text);

protractor.js

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -64,43 +64,50 @@ exports.wrapDriver = function(webdriver) {
6464
};
6565
};
6666

67-
exports.By = {
68-
/** Usage:
69-
* driver.findElement(protractor.By.binding(), "{{myBinding}}");
70-
*/
71-
binding: function() {
72-
return {
73-
using: 'js',
74-
value: function() {
75-
var bindings = document.getElementsByClassName('ng-binding');
76-
var matches = [];
77-
var binding = arguments[0];
78-
for (var i = 0; i < bindings.length; ++i) {
79-
if (angular.element(bindings[i]).data().$binding[0].exp == binding) {
80-
matches.push(bindings[i]);
81-
}
82-
}
83-
return matches[0]; // We can only return one with webdriver.findElement.
67+
var ProtractorBy = function() {}
68+
var WebdriverBy = function() {};
69+
WebdriverBy.prototype = require('selenium-webdriver').By;
70+
71+
util.inherits(ProtractorBy, WebdriverBy);
72+
73+
ProtractorBy.prototype.binding = function() {
74+
return {
75+
using: 'js',
76+
value: function() {
77+
var bindings = document.getElementsByClassName('ng-binding');
78+
var matches = [];
79+
var binding = arguments[0];
80+
for (var i = 0; i < bindings.length; ++i) {
81+
if (angular.element(bindings[i]).data().$binding[0].exp == binding) {
82+
matches.push(bindings[i]);
83+
}
8484
}
85-
};
86-
},
87-
select: function(model) {
88-
return {
89-
using: 'css selector',
90-
value: 'select[ng-model=' + model + ']'
91-
};
92-
},
93-
selectedOption: function(model) {
94-
return {
95-
using: 'css selector',
96-
value: 'select[ng-model=' + model + '] option[selected]'
97-
};
98-
},
99-
repeater: null,
100-
input: function(model) {
101-
return {
102-
using: 'css selector',
103-
value: 'input[ng-model=' + model + ']'
104-
};
105-
}
85+
86+
return matches[0]; // We can only return one with webdriver.findElement.
87+
}
88+
};
89+
};
90+
91+
ProtractorBy.prototype.select = function(model) {
92+
return {
93+
using: 'css selector',
94+
value: 'select[ng-model=' + model + ']'
95+
};
10696
};
97+
98+
ProtractorBy.prototype.selectedOption = function(model) {
99+
return {
100+
using: 'css selector',
101+
value: 'select[ng-model=' + model + '] option[selected]'
102+
};
103+
};
104+
105+
ProtractorBy.prototype.input = function(model) {
106+
return {
107+
using: 'css selector',
108+
value: 'input[ng-model=' + model + ']'
109+
};
110+
}
111+
ProtractorBy.prototype.repeater = null;
112+
113+
exports.By = new ProtractorBy();

0 commit comments

Comments
 (0)