diff --git a/httpspec.js b/httpspec.js index e2d8b2552..6057abad4 100644 --- a/httpspec.js +++ b/httpspec.js @@ -37,15 +37,15 @@ ptor.get('http://localhost:8000/app/index.html'); // Could still use driver.get to get a URL normally, without injecting modules. -ptor.findElement(webdriver.By.css('[app-version]')).getText().then(function(text) { +ptor.findElement(protractor.By.css('[app-version]')).getText().then(function(text) { assert.equal('3', text); }); -var sample1Button = driver.findElement(webdriver.By.id('sample1')); -var sample2Button = driver.findElement(webdriver.By.id('sample2')); +var sample1Button = driver.findElement(protractor.By.id('sample1')); +var sample2Button = driver.findElement(protractor.By.id('sample2')); sample1Button.click(); -var fetchButton = driver.findElement(webdriver.By.id('fetch')); +var fetchButton = driver.findElement(protractor.By.id('fetch')); fetchButton.click(); // The quick RPC works fine. @@ -61,10 +61,10 @@ ptor.findElement(protractor.By.binding(), "{{data}}").getText().then(function(te sample2Button.click(); fetchButton.click(); // Would normally need driver.sleep(2) or something. -ptor.findElement(webdriver.By.id('statuscode')).getText().then(function(text) { +ptor.findElement(protractor.By.id('statuscode')).getText().then(function(text) { assert.equal('200', text); }); -ptor.findElement(webdriver.By.id('data')).getText().then(function(text) { +ptor.findElement(protractor.By.id('data')).getText().then(function(text) { assert.equal('finally done', text); }); @@ -73,7 +73,7 @@ var urlBox = ptor.findElement(protractor.By.input('url')); urlBox.clear(); urlBox.sendKeys('/3seccall'); fetchButton.click(); -ptor.findElement(webdriver.By.id('data')).getText().then(function(text) { +ptor.findElement(protractor.By.id('data')).getText().then(function(text) { assert.equal('done after 3 seconds', text); }); @@ -86,12 +86,12 @@ ptor.addMockModule('moduleA', mockModuleA); ptor.get('http://localhost:8000/app/index.html#/bindings'); // Now, version should be 2, since only moduleA has been loaded. -ptor.findElement(webdriver.By.css('[app-version]')).getText().then(function(text) { +ptor.findElement(protractor.By.css('[app-version]')).getText().then(function(text) { assert.equal('2', text); }); ptor.findElement(protractor.By.select('planet')). - findElements(webdriver.By.tagName("option")).then(function(planetOptions) { + findElements(protractor.By.tagName("option")).then(function(planetOptions) { for (var i = 0; i < planetOptions.length; ++i) { planetOptions[i].getText().then(function(text) { util.puts(text); diff --git a/protractor.js b/protractor.js index 78816de18..e42268ae4 100644 --- a/protractor.js +++ b/protractor.js @@ -64,43 +64,50 @@ exports.wrapDriver = function(webdriver) { }; }; -exports.By = { - /** Usage: - * driver.findElement(protractor.By.binding(), "{{myBinding}}"); - */ - binding: function() { - return { - using: 'js', - value: function() { - var bindings = document.getElementsByClassName('ng-binding'); - var matches = []; - var binding = arguments[0]; - for (var i = 0; i < bindings.length; ++i) { - if (angular.element(bindings[i]).data().$binding[0].exp == binding) { - matches.push(bindings[i]); - } - } - return matches[0]; // We can only return one with webdriver.findElement. +var ProtractorBy = function() {} +var WebdriverBy = function() {}; +WebdriverBy.prototype = require('selenium-webdriver').By; + +util.inherits(ProtractorBy, WebdriverBy); + +ProtractorBy.prototype.binding = function() { + return { + using: 'js', + value: function() { + var bindings = document.getElementsByClassName('ng-binding'); + var matches = []; + var binding = arguments[0]; + for (var i = 0; i < bindings.length; ++i) { + if (angular.element(bindings[i]).data().$binding[0].exp == binding) { + matches.push(bindings[i]); + } } - }; - }, - select: function(model) { - return { - using: 'css selector', - value: 'select[ng-model=' + model + ']' - }; - }, - selectedOption: function(model) { - return { - using: 'css selector', - value: 'select[ng-model=' + model + '] option[selected]' - }; - }, - repeater: null, - input: function(model) { - return { - using: 'css selector', - value: 'input[ng-model=' + model + ']' - }; - } + + return matches[0]; // We can only return one with webdriver.findElement. + } + }; +}; + +ProtractorBy.prototype.select = function(model) { + return { + using: 'css selector', + value: 'select[ng-model=' + model + ']' + }; }; + +ProtractorBy.prototype.selectedOption = function(model) { + return { + using: 'css selector', + value: 'select[ng-model=' + model + '] option[selected]' + }; +}; + +ProtractorBy.prototype.input = function(model) { + return { + using: 'css selector', + value: 'input[ng-model=' + model + ']' + }; +} +ProtractorBy.prototype.repeater = null; + +exports.By = new ProtractorBy(); \ No newline at end of file