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

feat(browser): auto-unwrap ElementFinder into WebElement for selenium… #3471

Merged
merged 1 commit into from
Aug 22, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions lib/browser.ts
Original file line number Diff line number Diff line change
@@ -51,16 +51,22 @@ export class Webdriver {

/**
* Mix a function from one object onto another. The function will still be
* called in the context of the original object.
* called in the context of the original object. Any arguments of type
* `ElementFinder` will be unwrapped to their underlying `WebElement` instance
*
* @private
* @param {Object} to
* @param {Object} from
* @param {string} fnName
* @param {function=} setupFn
*/
function mixin(to: any, from: any, fnName: string, setupFn?: Function) {
function ptorMixin(to: any, from: any, fnName: string, setupFn?: Function) {
to[fnName] = function() {
for (var i = 0; i < arguments.length; i++) {
if (arguments[i] instanceof ElementFinder) {
arguments[i] = arguments[i].getWebElement();
}
}
if (setupFn) {
setupFn();
}
@@ -265,11 +271,11 @@ export class ProtractorBrowser extends Webdriver {
.forEach((method: string) => {
if (!this[method] && typeof webdriverInstance[method] == 'function') {
if (methodsToSync.indexOf(method) !== -1) {
mixin(
ptorMixin(
this, webdriverInstance, method,
this.waitForAngular.bind(this));
} else {
mixin(this, webdriverInstance, method);
ptorMixin(this, webdriverInstance, method);
}
}
});
@@ -863,7 +869,7 @@ export class ProtractorBrowser extends Webdriver {
*/
navigate() {
let nav = this.driver.navigate();
mixin(nav, this, 'refresh');
ptorMixin(nav, this, 'refresh');
return nav;
}

6 changes: 6 additions & 0 deletions spec/basic/lib_spec.js
Original file line number Diff line number Diff line change
@@ -44,6 +44,12 @@ describe('protractor library', function() {
expect(browser.driver.getCurrentUrl()).toMatch('#/form');
});

it('should unwrap WebElements', function() {
browser.get('index.html');
var ptorEl = element(by.binding('greet'));
browser.executeScript('', ptorEl); // Will crash if element isn't unwrapped
});

it('should have access to the processed config block', function() {
function containsMatching(arr, string) {
var contains = false;