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

Is there a way I can incorporate v-for with a computed variable?

I am trying to display navigation items based on my authority and other conditions. Below is the code I am using: <template v-for="(subItem, index2) in item.children"> <v-list-item sub-group link :to="subItem.link" exact ...

Trouble with Add To Cart feature in React app due to issues with Context API

I have been following a tutorial located here. I followed the steps exactly and even checked the code on the related github repository, which matches. However, when I try to add a product to the cart by clicking the button, the state does not update. In Re ...

Crafting personalized objects from an array

In the process of creating an object from an array, I am faced with a dilemma. The elements in the array are as follows: var arr = [ 'find({ qty: { $lt: 20 } } )', 'limit(5)', 'skip(0)' ] Despite my efforts, my code is ...

Utilizing AngularJS within a Captive Network Assistant (WISPr) on iOS and MacOS devices

In my past experiences with projects, it has been observed that Apple's Captive Network Assistant (also known as WISPr client) operates with a restricted browser. For further information, you can refer to How can I debug the browser in Captive Portal? ...

How to properly set up geckodriver for selenium-webdriver on Ubuntu 18.04?

Currently, I am working on a specific web scraping task using Selenium in Node.js. The code is running smoothly on my local Mac machine. However, when I attempt to execute the same code on a demo Google Compute virtual machine instance, I am facing challen ...

Using React: implementing a spinner upon clicking a button and transitioning to a new screen when the animation finishes

I have noticed that there are existing answers on incorporating spinners during fetch requests completion. However, my query pertains to stopping the animation once it reaches completion after a timeout. Additionally, I am seeking advice on best practices ...

LeafletJS and ReactJS integration causing misalignment in tile ordering

In my ReactJS single page application, I am utilizing the LeafletJS plugin to showcase a full-page map. Even after following the guidelines mentioned here, I am facing an issue where the map tiles are not displayed in the correct order and appear to be shu ...

Loop through an array of arrays in JavaScript. If a match is found, add it to an existing inner array. If not, create a new

I am currently extracting data from a database, and here is a simplified representation of the information: var example = [ {'start': 1966, 'end': 1970}, {'start': 1969, 'end': 1971}, {'start&ap ...

Discovering the Windows Identifier of the Opener Window in Chrome via JavaScript

I recently opened a link in a new window and realized that the current window's ID is now the ID of the newer window. I'm curious if there is any method to determine the window ID of the original window (the opener) from the perspective of the ne ...

Error: The variable "Set" cannot be found in the react.js code, specifically in Safari browser

An issue has been identified in Safari where a ReferenceError is thrown: "Can't find variable: Set" when using react.js. This error occurs only in Safari, while all other browsers work perfectly fine. The error message points to the main.js file which ...

Using parseFloat in JavaScript for German number formatting

Currently, I am working on incorporating a Vue.js component that is inspired by the example provided in this link: https://jsfiddle.net/mani04/bgzhw68m/. This is the structure of my source code: computed: { displayValue: { get ...

Typescript Angular2 filtering tutorial

In Angular 2 using TypeScript, the goal is to search for matching values from an array within an object array. The intention is to filter out any objects where the 'extraService' property contains any of the values from the 'array_values&apo ...

How to execute a system command or external command in Node.js

I am encountering an issue with Node.js. When using Python, I would typically perform an external command execution like this: import subprocess subprocess.call("bower init", shell=True) Although I have explored child_process.exec and spawn in Node.js, I ...

No testing detected, ending with code zero - NPM and YARN

After installing node js and yarn, I attempted to run an application/script developed by someone else. However, when running the test, I encountered the following message: No tests found, exiting with code 0 Watch Usage › Press f to run only failed tes ...

Creating a sticky header for a MatTable in Angular with horizontal scrolling

Having an issue with merging Sticky Column and horizontal scrolling. Check out this example (it's in Angular 8 but I'm using Angular 10). Link to Example The base example has sticky headers, so when you scroll the entire page, the headers stay ...

Fetching selenium logs and screenshots from the Intern grid backend

My question pertains to the Intern workflow in case of exceptions, with two specific parts: 1- According to Selenium's Desired Capabilities specifications, RemoteWebDriver automatically captures screenshots on exceptions unless disabled by setting we ...

Tips for waiting on an Ajax request while populating a dropdown menu with Selenium

So, I am working with two drop down lists. The second list (List B), populates based on the selection made in the first list (List A) using Ajax technology. The issue I'm facing is that after selecting an option from List A, List B does not populate ...

Having trouble loading environment variables in NextJS on Heroku?

I am currently utilizing NextJS and deploying my application on Heroku. When the page initially loads, I am able to retrieve data through getInitialProps without any issues. However, when trying to access this data in a regular function, I encounter an er ...

Unexpected JSON data submission

I am encountering an issue with JSON. Since I am not proficient in JSON, identifying the problem is challenging. Here is the JSP code snippet. $(document).ready( function(){ window.onload = dept_select; $("#sales_dept_id").change ...

How can I incorporate a standalone Vuetify component into my Nuxt.js project?

Using Vuetify with nuxt.js specifically for the dashboard layout - how can I achieve this in my nuxt.config.js file? modules: [ //['nuxt-leaflet', { /* module options */}], 'bootstrap-vue/nuxt', '@nuxtjs/ax ...