alecxe alecxe - 4 months ago 27
Javascript Question

Cannot read property 'prototype' of undefined after upgrading to Protractor 4

Recently, we've upgraded to Protractor 4.0.0 and our tests started to fail immediately with:


Error: TypeError: Cannot read property 'prototype' of undefined


Failing in
onPrepare()
on the following line:

protractor.ElementArrayFinder.prototype.takewhile = function(whileFn) {
// ...
};


Here we are extending
ElementArrayFinder
to support
takewhile
function
.

Looks like
protractor.ElementArrayFinder
is now undefined.
How should we be extending
ElementArrayFinder
in Protractor 4?

I don't see anything related in the breaking changes in the changelog.





Issue tracker link: Cannot read property 'prototype' of undefined (Protractor 4 upgrade problem).

Answer

It seems that ElementFinder and ElementArrayFinder are no longer exposed in the protractor namespace. You could simply import them with require:

var ElementFinder = require('protractor/built/element').ElementFinder;
var ElementArrayFinder = require('protractor/built/element').ElementArrayFinder;

ElementArrayFinder.prototype.takewhile = function(whileFn) {
    ...
};