Error: The property 'constructor' of undefined cannot be accessed

vegan@vegan:~/hb-x/gateway$ gulp protractor [14:44:36] Using gulpfile ~/hb-x/gateway/gulpfile.js [14:44:36] Starting 'protractor'... Using ChromeDriver directly... [launcher] Running 1 instances of WebDriver Started - User not logged in, so trying to log in x- User not logged in, so trying to log in xy- User not logged in, so trying to log in

/home/vegan/hb-x/gateway/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2965 return fn.constructor.name === 'GeneratorFunction'; ^ TypeError: Cannot read property 'constructor' of undefined at Object.promise.ControlFlow.goog.defineClass.goog.defineClass.promise.isGenerator (/home/vegan/hb-x/gateway/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2965:12)

This is the section where the error occurs

'use strict';

var CommonPageObject = function() {

    this.baseUrl = "http://localhost:8080";

    this.product = element.all(by.css('[data-tab-item="product"]')).first();



    this.loginTextLocator = element(by.css('button.layout-align-xs-start-start'));
    this.loginPageHeader = element(by.css('header'));

    this.loginUsername = element(by.model('vm.model.username'));
    this.loginPassword = element(by.model('vm.model.password'));
    this.loginButton = element(by.css('[aria-label="login.button"]));

    this.isLoggedIn = function () {
        this.get();

        var self = this;

        this.loginTextLocator.isPresent().then(function(isElementDisplayed){
            if(isElementDisplayed){
                console.log('- User not logged in, so trying to log in');

                self.ctaLogin('cta', 'M0ha44bOw-36SMm');
            }
            else{
                console.log('- User already logged in');
            }
        })
    };

    this.get = function() {
        browser.get(this.baseUrl);
    };

    this.ctaLogin = function(name,password) {

        this.get();//necessary?
        browser.driver.wait(protractor.until
            .loginPageHeader);

        this.setName(name);
        this.setPassword(password);

        this.loginButton.click();
    };

    this.setName = function(name) {browser.sleep(5000);console.log('x- User not logged in, so trying to log in');
        this.loginUsername.clear().sendKeys(name);

    };

    this.setPassword = function(password) {browser.sleep(5000);console.log('xy- User not logged in, so trying to log in');
        this.loginPassword.clear().sendKeys(password);

    };

};

module.exports = CommonPageObject;

this part calls it

'use strict';


var LogoutPageObject = require('./logoutControllerPageObject');

describe(
    'Logout module', function () {

        var logoutPageObject = new LogoutPageObject();

        beforeEach(
            function(){
                console.log('Logout Test starting');
                logoutPageObject.isLoggedIn();

this code snippet is from promise.js which causes the error on line 2965

promise.isGenerator = function(fn) {
  return fn.constructor.name === 'GeneratorFunction';
};

I tried adding a return statement but the issue persists

this.isLoggedIn = function () {
        this.get();

        var self = this;

        this.loginTextLocator.isPresent().then(function(isElementDisplayed){
            if(isElementDisplayed){
                console.log('- User not logged in, so trying to log in');

                self.ctaLogin('cta', 'M0ha44bOw-36SMm');
            }
            else{
                console.log('- User already logged in');
            }
        });
        return null;
    };

The problem may be related to this line of code

this.isLoggedIn = commonPageObject.isLoggedIn();

What steps can I take to resolve this?

Answer №1

After making a switch, I utilized the caller function as follows:

this.isLoggedIn = function(){
            commonPageObject.isLoggedIn();
       };

The change proved successful, as previously I attempted to call it like a variable.

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

Issues arising with VueJS array props when integrating Bootstrap

I am attempting to display two divs next to each other while iterating through props (which are essentially an array) in VueJS. When I have just a single element, everything functions properly. However, as soon as I include the v-for directive, the element ...

employing express.json() post raw-body

Within my Express application, I am aiming to validate the length of the request body and restrict it irrespective of the content type. Additionally, I wish to parse the body only if the content type is JSON. How can I go about accomplishing this? Curren ...

Using the v-for directive in Vue.js to loop through an array and display

Looking at the image provided, I am trying to access the content. I attempted to do so using element.comments.content, but it did not seem to work as expected. Here is the snippet of code: <div class="fil-actualites-container"> <div cl ...

Steps to generate a fresh array from a given array of objects in JavaScript

Looking to transform an existing array into a new array of objects in Vue.js. Here's the initial array : import { ref } from 'vue'; const base_array = ref([ {id: 1, name: Pill, timing: [morning, noon, evening, night]}, {id: 2, name: Ta ...

Parsing nested JSON objects using BodyParser in a node.js environment

My node.js server is receiving a JSON object through a put request: { stats = { abdominal=0, bicep=0, deltoids=0, erector_spinae=0, gastro_soleus=0, gluteus=0, hamstrings=0, ...

React error: "Unable to locate property 'bind' within the undefined"

After reviewing several solutions, I'm still struggling to understand. Below is my code snippet: // userInputActions.js ... export function dummy() { console.log('dummy function called'); } ... // *userInputPage.js* import * as use ...

Confirm that the content on the page is accurate and free of any additional elements

I'm currently working on automation coding and I've been tasked with creating a test case to confirm that the page contents are accurate. The requirement is that if there are any additional elements (text) on the page, the test must fail. I' ...

Attempted to fetch information using Ajax in Grails

I am attempting to utilize jQuery and ajax with the Grails framework to load the content registration page. However, upon loading the page, I am encountering an issue where the menu and registration fields are duplicated within the page. <script src ...

Encountering an error when trying to use this.setState

I'm currently working on developing a simple react application that consists of a component. In this component, I am attempting to adjust the state when a link is clicked. However, I'm encountering an issue where the setState function is not bein ...

Show or hide the sibling element of the current element without using a specific identifier in jQuery

I am looking to make div.edit-button toggle its corresponding sibling div.additionalFieldForm. There are multiple instances of both on the page, so I want to target only the pair that are related within the same group. If a div.edit-button is clicked, the ...

Obtaining data from a webpage element using Python Selenium

Is there a method to obtain all the information about a specific web element? When I attempt to print a web element retrieved using find_element_by_css_selector(), I only receive the internal ID and another reference number, but not all of the properties. ...

Encountering difficulties when attempting to run initial React Native app

Struggling with my journey of learning react-native, I encountered a roadblock while trying to run the application. Here is the error log. I'm hopeful for some assistance from anyone who can lend a hand. The development server returned response erro ...

Just starting out with json/ajax and I received an error in the Console that says: Uncaught TypeError: Cannot read property 'length' of undefined

I’m encountering an issue with my code. I must emphasize that I’m brand new to this, so please bear with me if the solution is simple. I did attempt to solve it myself before reaching out for help and searched through various posts with similar errors, ...

Setting the default option in an Autocomplete component using Material UI in React JS

I am currently working with autocomplete input using react material ui component. One specific challenge I am facing is setting a default selected value when a user enters edit mode for this input field. Although I can select the option using getOptionSe ...

Using JavaScript to insert array elements at various positions

I am facing a scenario where I have an array structured as follows: [ { "Fare":10, "TotalFare":30 }, { "Fare":20, "TotalFare":50 }, { "Fare":30, "TotalFare":100 } ] My objective is to accumulate all the fare values into a single variable at i ...

Error message: The import from './components/headerComponent/header' failed because it does not have a default export. Make sure to export it as default to be able to import it

I've been trying to bring a header from one file into another, but it's not cooperating. import React from 'react'; import { Typography, Card, CardContent } from '@material-ui/core'; import Header from './components/head ...

Having trouble loading the JSON data for display

My select dropdown is supposed to display the names of states. The data is being fetched from PHP and is also available in the controller JS file. However, the data is showing up as blank in the HTML. When I use console.log(), the fetched result from PHP s ...

NodeJS API Language Configuration

I'm currently working on integrating the DuckDuckGo Instant Answer Api into my NodeJS application. To do so, I am making a data request from the API using Node Request. var request = require('request'); request('http://api.duckduckgo.c ...

Passing data between child components using Vuejs 3.2 for seamless communication within the application

In my chess application, I have a total of 3 components: 1 parent component and 2 child components. The first child component, called Board, is responsible for updating the move and FEN (chess notation). const emit = defineEmits(['fen', 'm ...

Application of Criteria for Zod Depending on Data Stored in Array Field

I am currently working on an Express route that requires validation of the request body using Zod. The challenge arises when I need to conditionally require certain fields based on the values in the "channels" field, which is an array of enums. While my cu ...