JavaScript: Extending a class with an invalid or null value is not permitted

Trying my hand at constructing a page object for login testing with WebdriverIO.

Encountering the error

ERROR: Class extends value #<Page> is not a function or null
on line 3 of login.page.js.

No clue what mistake I'm making... Is there a wrong path or filename somewhere?

/tests/specs/login.specs.js

var expect = require('chai').expect
var LoginPage = require('../pageobjects/login.page')

describe('login form', function () {
  it('should deny access with wrong creds', function () {
    LoginPage.open()
    LoginPage.username.setValue('foo')
    LoginPage.password.setValue('bar')
    LoginPage.submit()
    expect(LoginPage.flash.getText()).to.contain('Your username is invalid!')
  })
})

/tests/pageobjects/page

'use strict'
class Page {
  constructor() {
    this.title = 'My Page'
  }
  open(path) {
    browser.url('/' + path)
  }
}
module.exports = new Page()

/tests/pageobjects/login.page.js

'use strict'
var Page = require('./page')
class LoginPage extends Page {
  get username () { return browser.element('#username') }
  get password () { return browser.element('#password') }
  get form () { return browser.element('#login') }
  get flash () { return browser.element('#flash') }

  open () {
    super.open('login')
  }

  submit () {
    this.form.submitForm()
  }
}
module.exports = new LoginPage()

Answer №1

According to Gerardo's observation, you are exporting an instance of the class instead of the class itself. To resolve this issue, consider making the following changes:

/tests/pageobjects/page

module.exports = Page;

/tests/pageobjects/login.page.js

module.exports = LoginPage;

/tests/specs/login.specs.js

var LoginPage = new (require('../pageobjects/login.page'))();

or

var LoginPage = require('../pageobjects/login.page');
var instanceLoginPage = new LoginPage();

Answer №2

Give it a shot

module.exports.Page = Page

Next, in the login.page file

var Page = require('./page.js').Page

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The click function operates only once

Here are two simple JavaScript functions: CTCC.Transactions.PieceRecuClick = function (source) { $(".chk input[type='checkbox']").attr('checked', true); } CTCC.Transactions.PieceNonRecuClick = function (source) { $(".chk input ...

How can I troubleshoot the unresponsive remove div function on my website?

My code is running fine on CodePen (link provided below), but for some reason, it's not working properly in the web browser. I am executing the code from localhost and the button isn't responding as expected. CODE Here is my Visual Studio code ...

Apollo Client is not properly sending non-server-side rendered requests in conjunction with Next.js

I'm facing a challenge where only server-side requests are being transmitted by the Apollo Client. As far as I know, there should be a client created during initialization in the _app file for non-SSR requests, and another when an SSR request is requi ...

I'm curious about incorporating the datefunction or inserting Python date into the Selenium code below. Currently, I am manually inputting the dates '2021-05-01' and '2021-05-31'

Using Selenium in Python, locate the element with the ID "txtStarttime" and remove its type attribute. Then, find the same element again and set its value to '2021-05-01'. Next, locate the element with the ID "txtEndtime", remove its typ ...

retrieving particular information from within a Firebase array

My Firebase document contains a list with various properties such as name and imgUrl. Currently, I am facing an issue with extracting only the "name:" information from the list in Firebase Cloud Firestore so that I can determine how many times a specific n ...

Unable to locate the module '/workspace/mySQL/node_modules/faker/index.js'

Hi there, I'm currently facing an issue while trying to run the app.js file in my project through the terminal. It keeps showing me an error message that I am unable to resolve. To provide some context, I have already installed the faker package using ...

What is the best method for testing different versions of the same module simultaneously?

My goal is to distribute a module across various component manager systems like npmjs and bower. I also want to provide downloadable builds in different styles such as AMD for requirejs, commonJS, and a global namespace version for browsers - all minified. ...

"Facing rendering issues with handlebars.js when trying to display an

I have been diligently working on trying to display an array from my running express app, but despite the lack of errors, nothing is being rendered. Take a look at my handlebars template: <h3>Registered Users:</h3> <h5>{{users}}</h5& ...

Getting a ReferenceError while trying to use a MongoDB Collection variable in an external resolver file that had been imported through mergeResolvers

Here is a simplified example to illustrate the issue at hand. When using the resolver Query getAllUsers, the MongoDB Collection Users is not accessible in the external resolver file user.js. This results in the following error when executing the query: ...

HTML tends to disregard the dimensions specified in the JavaScript file

I'm currently working on replicating an Etch-a-Sketch style drawing board where hovering over a single pixel with the mouse changes its color. However, I've hit a roadblock when it comes to drawing the board. The flexbox container doesn't se ...

When you hover over HTML tables, they dynamically rearrange or shift positions

Issue: I am encountering a problem with multiple tables where, upon hovering over a row, the tables are floating rather than remaining fixed in place. Additionally, when hovering over rows in the first or second table, the other tables start rendering unex ...

Navigating the complexities of integrating Rollup, ES modules, TypeScript, and JSX can be a challenging endeavor due to

Lately, I've been learning about the tools mentioned in the title. However, I've encountered some bumps along the way, so I'm turning to StackOverflow for help. My Requirements I need something like Rollup to pack my stuff For bare module ...

Error message from sails.js: `req.target` is not defined

Experiencing a problem where req.target sometimes returns undefined, causing issues with other functionalities dependent on req.target. Seeking assistance to resolve this issue. Appreciate any help! ...

JavaScript Flash player for iPad

As many of us know, the iPad does not support Flash. However, I am curious if the iPad sends any specific error messages that can be captured using Javascript. I realize one method is to detect the iPad from the user agent string, but I am interested in w ...

"An issue arises where the bokeh plot fails to render when generating a

I have been working on embedding a bokeh plot within a webpage served by a simple Flask app. I am using the embed.autoload_server function that I found in the bokeh embed examples on github. While everything seems to be functioning correctly on the Python ...

Wrap the chosen text within tags in a particular element

Is there a way to wrap <span> tags around selected text within an element? For instance, if someone highlights the word "John", I would like to enclose it with span tags. Sample Code in HTML <p>My name is Jimmy John, and I hate sandwiches. M ...

What is the method for adjusting the time format?

Using the TIME data type, my data is currently displayed in the format hh:mm:ss (03:14:00). How can I change it to display in the format hh:mm (03:14)? The usual DATE type method does not seem to work: {{test.time | date: 'HH:mm'}} However, thi ...

"Learn the art of refreshing data in AngularJS following the use of $emit event handling

I am in need of assistance with AngularJS. How can I re-initialize a variable in scope after using emit? Here is an example code snippet: $scope.uiConfig = {title: "example"}; $scope.$emit('myCustomCalendar', 'Data to send'); $scop ...

The HTML table is not fully filled with data from the XML file

Trying to populate an HTML table using XML data retrieved from an AJAX call is proving to be a challenge for me. The main issue I am facing is the inability to fully populate the HTML table. Being new to AJAX, understanding how XML interpretation works an ...

Instructions for triggering the opening of a colorbox within an iframe directly on top of the parent window

I am encountering an issue on a page with an iframe. When clicking on a link inside the iframe, it opens a colorbox as expected. However, the colorbox opens within the iframe itself. Is there a way to have the iframe open over the parent window instead? ...