alecxe alecxe - 1 year ago 203
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
on the following line:

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

Here we are extending
to support

Looks like
is now undefined.
How should we be extending
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 Source

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) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download