nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.79k stars 1.31k forks source link

There was an error while trying to load the file nightwatch/custom-commands/angular/getElementsInList.js #3699

Closed mikeumus closed 1 year ago

mikeumus commented 1 year ago

Description of the bug/issue

A fresh install of Nightwatch via npm init produces the following for me:

  1. > $ npm init nightwatch
    
    ...
    ? Select testing type to setup for your project End-to-End testing
    ? Select language + test runner variant JavaScript / default
    ? Select target browsers Chrome
    ? Enter source folder where test files are stored test
    ? Enter the base_url of the project http://localhost
    ? Select where to run Nightwatch tests On localhost
    ? Allow Nightwatch to collect completely anonymous usage metrics? No
    ? Setup testing on Mobile devices as well? No, skip for now

Installing the following packages:

2.> $ npx nightwatch ./nightwatch/examples/basic/ecosia.js

  1. Error
    unhandledRejection: There was an error while trying to load the file /Users/michaelmooring/Documents/Token/tenant-management/nightwatch/custom-commands/angular/getElementsInList.js:

Steps to reproduce

Fresh Nightwatch Setup

  1. npm init nightwatch
  2. npx nightwatch ./nightwatch/examples/basic/ecosia.js
  3. See error

Sample test

describe('Ecosia.org Demo', function() {
  before(browser => browser.navigateTo('https://www.ecosia.org/'));

  it('Demo test ecosia.org', function(browser) {
    browser
      .waitForElementVisible('body')
      .assert.titleContains('Ecosia')
      .assert.visible('input[type=search]')
      .setValue('input[type=search]', 'nightwatch')
      .assert.visible('button[type=submit]')
      .click('button[type=submit]')
      .assert.textContains('.layout__content', 'Nightwatch.js');
  });

  after(browser => browser.end());
});

Command to run

npx nightwatch ./nightwatch/examples/basic/ecosia.js

Verbose Output

Error
   unhandledRejection: There was an error while trying to load the file /Users/michaelmooring/Documents/Token/tenant-management/nightwatch/custom-commands/angular/getElementsInList.js:
Error: There was an error while trying to load the file /Users/michaelmooring/Documents/Token/tenant-management/nightwatch/custom-commands/angular/getElementsInList.js:
    at BaseLoader.handleModuleError (/Users/michaelmooring/Documents/Token/tenant-management/node_modules/nightwatch/lib/api/_loaders/_base-loader.js:12:19)
    at CommandLoader.requireModuleAsync (/Users/michaelmooring/Documents/Token/tenant-management/node_modules/nightwatch/lib/api/_loaders/_base-loader.js:234:18)
    at async CommandLoader.loadModuleAsync (/Users/michaelmooring/Documents/Token/tenant-management/node_modules/nightwatch/lib/api/_loaders/_base-loader.js:216:5)
    at async ApiLoader.addCommandDefinitionAsync (/Users/michaelmooring/Documents/Token/tenant-management/node_modules/nightwatch/lib/api/index.js:362:5)
    at async Promise.all (index 0)

───────────────────────────────────────────────────────────────────────────────────────────────────

  ️TEST FAILURE (232ms): 
   - 1 error during execution; 
   - 0 tests failed; 
   - 0/NA tests passed

Nightwatch Configuration

module.exports = {
test runner.
  src_folders: ['test','nightwatch/examples'],
  page_objects_path: ['nightwatch/page-objects'],
  custom_commands_path: ['nightwatch/custom-commands'],
  custom_assertions_path: ['nightwatch/custom-assertions'],
  plugins: [],  
  globals_path: '',  
  webdriver: {},
  test_workers: {
    enabled: true
  },
  test_settings: {
    default: {
      disable_error_log: false,
      launch_url: 'http://localhost',

      screenshots: {
        enabled: false,
        path: 'screens',
        on_failure: true
      },

      desiredCapabilities: {
        browserName: 'chrome'
      },

      webdriver: {
        start_process: true,
        server_path: ''
      },

    },

    chrome: {
      desiredCapabilities: {
        browserName: 'chrome',
        'goog:chromeOptions': {
          w3c: true,
          args: [
            //'--no-sandbox',
            //'--ignore-certificate-errors',
            //'--allow-insecure-localhost',
            //'--headless'
          ]
        }
      },

      webdriver: {
        start_process: true,
        server_path: '',
        cli_args: [
          // --verbose
        ]
      }
    },

  },

};

Nightwatch.js Version

zsh: command not found: nightwatch (using npx as per docs)

Node Version

18.12.1

Browser

Chrome 112.0.5615.121

Operating System

macOS Ventura 13.3.1

Additional Information

No response

AutomatedTester commented 1 year ago

We need to look at why the error is not being propagated properly.

gravityvi commented 1 year ago

@mikeumus I could not reproduce this error could you try using npm init nightwatch@latest in a fresh project and let us know if you still face an issue.

mikeumus commented 1 year ago

I tried it again and it's working now. No idea why. Same exact steps. But I'll take it. 😄👍