From b93bf18feaf3c44b406a41bf87d70c95e7a900e0 Mon Sep 17 00:00:00 2001 From: Leo Gallucci Date: Mon, 12 May 2014 19:46:41 -0300 Subject: [PATCH] feat(elementFinder): keep a reference to the original locator --- lib/protractor.js | 9 +++++++++ spec/basic/findelements_spec.js | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/lib/protractor.js b/lib/protractor.js index d9a28aee1..1e60a43e5 100644 --- a/lib/protractor.js +++ b/lib/protractor.js @@ -158,6 +158,15 @@ var buildElementHelper = function(ptor, opt_usingChain) { return using().isElementPresent(locator); }; + /** + * Returns the originally specified locator. + * + * @return {webdriver.Locator} The element locator. + */ + elementFinder.locator = function() { + return locator; + }; + /** * Calls to element may be chained to find elements within a parent. * diff --git a/spec/basic/findelements_spec.js b/spec/basic/findelements_spec.js index 6eb7d1851..fdf70288a 100644 --- a/spec/basic/findelements_spec.js +++ b/spec/basic/findelements_spec.js @@ -586,6 +586,13 @@ describe('global element function', function() { expect(element(by.binding('greet')).isPresent()).toBe(true); expect(element(by.binding('nopenopenope')).isPresent()).toBe(false); }); + + it('should keep a reference to the original locator', function() { + var byCss = by.css('body'); + var byBinding = by.binding('greet'); + expect(element(byCss).locator()).toEqual(byCss); + expect(element(byBinding).locator()).toEqual(byBinding); + }); }); describe('evaluating statements', function() {