Unable to locate module - relative file path

I'm currently running a test with the following code and encountering an error message:

Failed: cannot find module '../page/home_page.js

The main page consists of:

describe("login to website",function(){
     var employeeId;
     var employeeBday;
     
    beforeEach(function(){
        browser.get("https://pre-www5.main.co.il/#/");
    });
   
    it("should successfully login",function(){
        employeeId = "54729108";
        employeeBday = "25/03/1957";
        var home_page = require('../page/home_page.js')
        
        home_page.enterUsernameField(employeeId);
        home_page.enterBirthdateField(employeeBday);
        var pick_present_page = home_page.clickContinue();
        
        element(by.xpath("//*[@id='planAndDev']/div/div/div/div/matanot/form/div[2]/h4")).getText().then(function(text)
        {
            expect(text).toContain("foo")
        });
                      
    });

});

Also, utilizing the home_page class:

require ('../page/pick_present_page.js')
var home_page = function(){

    this.enterUsernameField=function(employeeId){
        element(by.xpath("//*[@id='planAndDev']/div/div/div/div/form/fieldset/div[1]/input")).sendKeys(employeeId);
    };
    this.enterBirthdateField=function(EmployeebDay){
         element(by.xpath("//*[@id='planAndDev']/div/div/div/div/form/fieldset/div[2]/my-date-picker/div/div/input")).sendKeys(EmployeebDay);
    };
    this.clickContinue=function(){
        element(by.xpath("//*[@id='planAndDev']/div/div/div/div/form/nav/div/button")).click();
        return require('./pick_present_page');
    };
module.exports = new home_page();
};

The project directory is located in C:\JS_Project and the pages can be found in C:\JS_Project\page. It seems like I might have made an error in how I'm using the relative path.

Answer №1

Make sure to establish the correct relative path to the SpecFile, not starting from the config file.

For example, if your project structure is as follows:

Project

  • page
    • home_page.js
    • pick_present_page.js
  • conf.js
  • specs
    • main

You should reference the home page like this: "../page/home_page.js"

Main

'use strict;'
let HomePage = require('../page/home_page.js');

describe("login to website",function(){
    let employeeId;
    let employeeBday;
    let home = new HomePage();

    beforeEach(function(){
        browser.get("https://pre-www5.main.co.il/#/");
    });

    it("should login successfully",function(){
        employeeId = "54729108";
        employeeBday = "25/03/1957";

        home.enterUsernameField(employeeId);
        home.enterBirthdateField(employeeBday);
        var pick_present_page = home.clickContinue();

        element(by.xpath("//*[@id='planAndDev']/div/div/div/div/matanot/form/div[2]/h4")).getText().then(function(text)
        {
            expect(text).toContain("foo")
        });

    });
});

Home_Page

'use strict;'
require ('../page/pick_present_page.js');

var HomePage = function(){
    let employeeField = element(by.xpath("//*[@id='planAndDev']/div/div/div/div/form/fieldset/div[1]/input"));
    let employeeBDayField = element(by.xpath("//*[@id='planAndDev']/div/div/div/div/form/fieldset/div[2]/my-date-picker/div/div/input"));
    let continueButton = element(by.xpath("//*[@id='planAndDev']/div/div/div/div/form/nav/div/button"));

    this.enterUsernameField=function(employeeId){
        employeeField.sendKeys(employeeId);
    };

    this.enterBirthdateField=function(EmployeebDay){
        employeeBDayField.sendKeys(EmployeebDay);
    };

    this.clickContinue=function(){
        continueButton.click();
        return require('./pick_present_page');
    };
};
module.exports = HomePage;

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

Get the download link from the given URL

I've been attempting to retrieve the URL of a video, but for some reason it doesn't appear in my output. I've tried using request, urllib, and even selenium, but it seems like part of the code is missing in my result - almost as if it's ...

exploring the depths of nested objects and utilizing the 'for in

My issue involves receiving a json response from an API that includes objects within objects. It looks something like this: {Object}->{results}->{manyObjects} When I execute the following code: var list = data.results.list; for(val in list){ ...

Setting the focus on an input when updating a property in the Pinia store using Vue

When a component I have is clicked, it triggers a function in the store: <button @click="this.store.foo()"></button> Within the store, I am updating a specific property: state: () => ({ focusIn: false, }), actions: { foo() { ...

Can you provide me with the sequelize query that is equivalent to this raw query?

Retrieve the ID from the offers table where the user ID is not equal to '2' and the ID is not present in the list of notified offers for user '2'. ...

Issue with Date generation in TypeScript class causing incorrect date output

I have a simple code snippet where I am creating a new Date object: var currentDate = new Date(); After running this code, the output value is: Sat May 11 2019 13:52:10 GMT-0400 (Eastern Daylight Time) {} ...

Using the JavaScript selectionchange event to target a specific element exclusively

I am looking for a way to incorporate a JavaScript selectionchange event on a specific div element. The goal is to display a highlighter box when the user selects text from the DOM. I was able to achieve this functionality for web using an onmouseup event, ...

Send the component template and functions when triggering an expanded view in a material dialog

While striving to adhere to DRY coding principles, I've encountered a dilemma involving a particular use case. The task at hand is to display an expanded view of a component within a dialog box. This component presents JSON records in a paginated list ...

Tips for saving data after reading lines in Node.js

I am working on a project where I need to read data from an external text file into my function. How can I efficiently store each line of the file as a separate variable? const fs = require("fs"); const readline = require("readline"); const firstVariable ...

The document.write function in JavaScript is malfunctioning

I've been attempting to utilize the javascript function document.write to incorporate an external css file in my template. However, I am aiming to achieve this using Twig, like so: document.write('<link href="{{ asset('bundles/activos/cs ...

Could you advise on the best placement for my upcoming JQuery animation?

Here is the code I am currently working with: $(function() { $("button").click(function() { $("#box1").animate({ left: $(window).width() - 800 }, { complete: function() { $("#box1").hide(); } }); $("#box2").a ...

Best practice for organizing sort icons in a table with React and MaterialUI

I am currently implementing the following code in a tsx component. I am still learning about the various layout options available. You can view my code on this sandbox link. import React from "react"; import { ArrowDropUp, ArrowDropDown } from "@materia ...

Different Option for Ajax/Json Data Instead of Using Multiple Jquery Append Operations

I am working on a complex data-driven application that heavily relies on Ajax and Javascript. As the amount of data returned for certain value selections increases, the application is starting to struggle. This is more of a brainstorming session than a q ...

Using Selenium to interact with a hidden button under a span element

I am seeking to automate the process of selecting an environment on a screen where there are multiple individual buttons hidden within spans, displayed as tiles. While I have been able to successfully navigate to a specific tile and reveal the button, I a ...

The Nodejs function exits before the internal function finishes executing

Currently, I am facing an issue where despite MongoDB returning the correct number of users (more than 0) when running console.log within collection.find(), the function userExists always returns false (0). I'm seeking guidance on how to ensure that ...

Sending data with the request body using Express and Passport

I've created a login application using Express and Passport, but I'm having trouble directing the user to their specific user profile page. The goal is for users to fill out an HTML form and then be redirected to their own profile page (which dif ...

Is there a way to have dynamic content from angularJS show up in an iframe?

When working with tabular content generated using ng-repeat in AngularJS, it is important to find a way to display this content within an iframe. The goal is to allow users to drag and resize the content as needed. However, using the iframe src attribute ...

My backend axios post request is not returning any data to my external API. What could be the issue?

I've encountered an issue where I'm attempting to transmit data from my client-side using an ajax call to my backend axios post request, which is responsible for posting data to an external API URL. Despite receiving a 200 status code, none of th ...

Combine two arrays in MongoDB where neither element is null

Issue I am looking to generate two arrays of equal length without any null elements. Solution I have managed to create two arrays, but they contain some null values. When I remove the null values, the arrays are no longer of equal length. aggregate([ ...

Processing JSON in PHP after an AJAX POST request

In the scenario where JavaScript is used to make an ajax request: index.js- var dataFeedback = $("#feedback_popup_message_body").val(); var jsonObj = JSON.stringify({dataFeedback: dataFeedback}); $.ajax({ url: "index.php", type: 'POST' ...

Styling images and text in CSS within a jQuery UI autocomplete widget

I am currently using an autocomplete widget that displays text along with images. The results I have right now are not meeting my requirements. I want to customize the appearance of my results so that the words 'test' and either 'Federico&a ...