Nightwatch encounters issues during the initialization of the page object

I am currently in the process of testing a Vue application. I have developed 2 simple page objects and created 2 simple spec files to run the end-to-end test. The first test (login) passes without any issues, however, the second test fails with the following error message:

Error: No selector property for element "client" Instead found properties: capabilities,globals,sessionId,options,launchUrl,launch_url,screenshotsPath,Keys,session,sessions,timeouts,timeoutsAsyncScript,timeoutsImplicitWait,elemen t,elementIdElement,elements,elementIdElements,elementActive,elementIdAttribute,elementIdClick,elementIdCssProperty,elementIdDisplayed,elementIdLocationInView,elementIdLocation,elementIdName,elementIdClear,elementIdSelected,elemen tIdEnabled,elementIdEquals,elementIdSize,elementIdText,elementIdValue,submit,source,contexts,currentContext,setContext,getOrientation,setOrientation,moveTo,doubleClick,mouseButtonClick,mouseButtonDown,mouseButtonUp,execute,execut eAsync,execute_async,frame,frameParent,window,windowHandle,windowMaximize,window_handle,windowHandles,window_handles,windowSize,windowPosition,refresh,back,forward,screenshot,url,status,title,keys,cookie,acceptAlert,accept_alert, dismissAlert,setAlertText,getAlertText,dismiss_alert,sessionLog,sessionLogTypes,click,clearValue,getAttribute,getCssProperty,getElementSize,getLocation,getLocationInView,getTagName,getText,getValue,isVisible,moveToElement,setValu e,submitForm,sendKeys,switchWindow,resizeWindow,setWindowPosition,maximizeWindow,saveScreenshot,getTitle,closeWindow,init,urlHash,getCookies,getCookie,setCookie,deleteCookie,deleteCookies,injectScript,getLogTypes,getLog,isLogAvai lable,waitForElementNotPresent,waitForElementNotVisible,waitForElementPresent,waitForElementVisible,end,pause,perform,useCss,useRecursion,useXpath,page,expect,assert,verify,currentTest,parent,name at new Element (C:\aquaprojects\src\bitbucket.org\scalock\tenantmanager\client\node_modules\nightwatch\lib\page-object\element.js:11:11) at C:\aquaprojects\src\bitbucket.org\scalock\tenantmanager\client\node_modules\nightwatch\lib\page-object\page-utils.js:39:35 at Array.forEach (native) at C:\aquaprojects\src\bitbucket.org\scalock\tenantmanager\client\node_modules\nightwatch\lib\page-object\page-utils.js:35:24 at Array.forEach (native) at module.exports.createElements (C:\aquaprojects\src\bitbucket.org\scalock\tenantmanager\client\node_modules\nightwatch\lib\page-object\page-utils.js:34:14) at Object.Page (C:\aquaprojects\src\bitbucket.org\scalock\tenantmanager\client\node_modules\nightwatch\lib\page-object\page.js:19:6) at Object.parent.(anonymous function) [as tenant] (C:\aquaprojects\src\bitbucket.org\scalock\tenantmanager\client\node_modules\nightwatch\lib\core\api.js:469:16) at Object.before (C:/aquaprojects/src/bitbucket.org/scalock/tenantmanager/client/test/e2e/specs/tenants.spec.js:7:26) at Object. (C:\aquaprojects\src\bitbucket.org\scalock\tenantmanager\client\node_modules\nightwatch\lib\util\utils.js:35:8)

login.js:

module.exports = {
  url: 'http://localhost:8080/#/login',
  elements: {
    app: '#app',
    loginSection: '.login-page',
    title: 'h3',
    submitButton: '.btn-primary',
    username: '#username',
    password: '#password'
  }
}

login.spec.js:

let login = null
module.exports = {
  before: function (client) {
    console.log('*********** Init login page *******************')
    login = client.page.login()
  },
  'open login page': function () {
    login
      .navigate()
      .waitForElementVisible('@app', 5000)
      .assert.elementPresent('@loginSection')
      .assert.containsText('@title', 'Tenant Manager Login')
  },
  'try to login': function () {
    login.setValue('@username', 'administrator')
    login.setValue('@password', '1234')

    login.click('@submitButton')
    login.waitForElementNotPresent('@submitButton')
  },
  after: function (client) {
    client.end()
  }
}

The first test passes successfully, while the second one - which is essentially a copy/paste with a few modifications - fails on this line:

tenant = client.page.tenant()

tenant.js:

module.exports = {
  url: 'http://localhost:8080/#/tenants',
  elements: {
    tab: '#tenants',
    tenantsFilter: '.tenants-filter input',
    statusFilter: '.status-filter input',
    add: '.add-tenant'
  }
}

tenants.spec.js:

let tenant = null
module.exports = {
  before: function (client) {
    console.log('*********** Init tenant page *******************')
    tenant = client.page.tenant()
  },
  'open tenant page': function () {
    console.log('*********** Navigating to tenant page *******************')
    tenant
      .navigate()
      .waitForElementVisible('@tab', 5000)
      //.assert.elementPresent('@tenantsFilter') <-- commented out assertion causing failure
  },
  after: function (client) {
    client.end()
  }
}

nightwatch.conf.js:

require('babel-register')
var config = require('../../config')

// http://nightwatchjs.org/gettingstarted#settings-file
module.exports = {
  src_folders: ['test/e2e/specs'],
  output_folder: 'test/e2e/reports',
  custom_assertions_path: ['test/e2e/custom-assertions'],
  "page_objects_path" : "test/e2e/pages",
  selenium: {
    start_process: true,
    server_path: require('selenium-server').path,
    host: '127.0.0.1',
    port: 4444,
    cli_args: {
      'webdriver.chrome.driver': require('chromedriver').path
    }
  },

  test_settings: {
    default: {
      selenium_port: 4444,
      selenium_host: 'localhost',
      silent: true,
      globals: {
        devServerURL: 'http://localhost:' + (process.env.PORT || config.dev.port)
      }
    },

    chrome: {
      desiredCapabilities: {
        browserName: 'chrome',
        javascriptEnabled: true,
        acceptSslCerts: true
      }
    },

    firefox: {
      desiredCapabilities: {
        browserName: 'firefox',
        javascriptEnabled: true,
        acceptSslCerts: true
      }
    }
  }
}

Answer №1

Please specify the page-object path

    require('babel-register')
var config = require('../../config')

// http://nightwatchjs.org/gettingstarted#settings-file
module.exports = {
  src_folders: ['test/e2e/specs'],
  output_folder: 'test/e2e/reports',
  custom_assertions_path: ['test/e2e/custom-assertions'],
  "page_objects_path" : "test/e2e/pages", //path to page objects
  selenium: {
    start_process: true,
    server_path: require('selenium-server').path,
    host: '127.0.0.1',
    port: 4444,
    cli_args: {
      'webdriver.chrome.driver': require('chromedriver').path
    }
  },

  test_settings: {
    default: {
      selenium_port: 4444,
      selenium_host: 'localhost',
      silent: true,
      globals: {
        devServerURL: 'http://localhost:' + (process.env.PORT || config.dev.port)
      }
    },

    chrome: {
      desiredCapabilities: {
        browserName: 'chrome',
        javascriptEnabled: true,
        acceptSslCerts: true
      }
    },

    firefox: {
      desiredCapabilities: {
        browserName: 'firefox',
        javascriptEnabled: true,
        acceptSslCerts: true
      }
    }
  }
}

Create a folder named "pages" and place the page objects in it.

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

Add a new value to an object and ensure that only the unique value is appended to the first

I have a scenario where I have 2 objects, and I need to add a new key value pair to only the first matching object of its kind. Obj1 [{ buyDate: "yesterday", productId: "0001", consumerId: "John", price: 10 // add new key valu ...

The program suddenly halts during the second loop without displaying any error messages

I've encountered an issue with my Node.js program on Windows that records microphone sound. The problem arises when I try to record multiple .wav files within a loop while taking user options from a menu. Initially, everything works fine and the prog ...

Having trouble uploading a file to a Spring Boot REST endpoint with Axios and FormData

I've been struggling to upload a file from a webpage using axios and I can't seem to retrieve it on my controller. I'm using Vue.js with axios on the front-end and a Spring MVC Controller on the back-end. It appears that my controller is hav ...

I am experiencing difficulties in running tests for the Vue3/TS/Jest/testing library

After using vue cli to create a project with vue3, TS, JEST, and adding @testing-library/vue, my package.json is structured as follows: { "name": "todo-app", "version": "0.1.0", "private": true, "scripts": { "serve": "vue-cli-service serve", ...

Ensuring the robust typing of Vue component props through the powerful combination of the Composition API and TypeScript's typing system

I'm currently working in Vue with the composition API and Typescript. Does anyone have tips on how to effectively use Typescript for strongly typing component props? ...

Guide to Inputting Numbers in a Form Field using a Pop-up Keypad (with Javascript/AJAX)

I am working on a small project that involves creating a keypad with buttons for all the digits, backspace, and decimal. When these buttons are clicked, they should populate a form field like a text box. The keypad will be located next to the form field as ...

Clicking to reveal a v-date-picker v-menu and automatically focusing on a v-text-field within it?

I implemented a date-picker component in my app following the instructions from Vuetify. To enhance usability for desktop users, I removed the readonly attribute to allow manual input. Now, desktop users can easily navigate through form fields using th ...

An error notification received from the command "jspm install jquery"

As I follow the tutorial on the jspm.io site, everything goes smoothly until I reach step 3. When I try to execute jspm install jquery, an error message pops up. The error reads: warn Error on getOverride for jspm:github, retrying (2). ReferenceError: ui ...

Switching from Dom to Jquery

Seeking assistance to convert DOM values into Jquery equivalent. For instance, how can I translate the DOM code: var x = document.querySelector('#x'); into Jquery format? Any suggestions? Additionally, looking for guidance on transforming even ...

The limitation of only being able to include up to 2 adsterra ad banners on a Next.js 14 application

I'm encountering an issue when trying to include more than 2 Adsterra ad banners on my Next.js 14 app. Whenever I attempt to display two Adsterra ad banners on the same page, the first one fails to render properly. I have also experimented with next/s ...

Troublesome GSP: JavaScript not functioning properly in Gr

I am experiencing an issue with the JavaScript code I have. Here's my code: <script type="text/javascript"><!-- ​$(function () { $('#add').click(function() { $(this).before($('select:eq(0)').clone()); ...

What is the best way to choose all checkboxes identified by a two-dimensional array?

I need help with a question div setup that looks like this: <div class="Q"> <div id="Q1"><span>1. </span>Which of the following have the same meaning?</div> <div class="A"><input type="checkbox" id="Q1A1Correct" /& ...

Rocket Calculations Made Easy

Recently, I acquired a cutting-edge 3D system along with a set of coordinates: Initial coordinates (x, y, z) for a rocket (located on the ground) Target coordinates (x, y, z) for the rocket's destination (also on the ground) Here are some essential ...

What is the best way to use JavaScript to disable all duplicate textboxes with identical IDs?

I am faced with a situation where I have multiple TextBoxes with the same Id. Due to certain restrictions, I am unable to use Class for differentiation. My goal is to only enable the first TextBox and disable the others. Below is an example of my code wit ...

Unable to successfully download zip files using Ajax in the MVC framework

I need to trigger the download of a zip file that contains .pdf files using an ajax call. The issue I'm encountering is that everything seems to be working fine except for the actual downloading of the zip file. public FileResult DownloadZip(string[] ...

Using Three.js to control the camera's position and direction

Despite hours of searching, I have been unable to find a solution to a fundamental issue in Three.js. I know the position of the camera (my eyes), the direction the camera is facing (my eyes), and the direction my head is pointing. I need to create the cam ...

Having trouble finding a module in React.js

As a newcomer to React, I am struggling with a recurring error that I can't seem to resolve. I have researched the issue multiple times but cannot pinpoint what is wrong with my import statement (https://i.sstatic.net/GPtZ78TQ.png)] (https://i.sstati ...

Add Vue data as a suffix to the class using v-bind

Within my Vue Multiselect component, I am using the following template. <template slot="option" scope="props"> <div class="option__desc"> <span class="flag-icon flag-icon-{{ props.option.code }}">{{ props.option.code }}</span> ...

Tips for getting a plugin to function properly when the page is refreshed in Nuxt app

I am currently incorporating the vue GAPI plugin into my project. While it functions smoothly when navigating between pages, I encounter an error upon refreshing: vue-gapi.common.js?15fd:241 Uncaught (in promise) Error: gapi not initialized at GoogleAuth ...

The issue in AngularJS 1.4 where the select element value is not binding due to a type mismatch

My ng-model has a value assigned to it, but it is not binding with the selected element. <select data-ng-model="myval"> <option value="? number:2 ?"></option> <option value="2" class="ng-binding">Value 1</option> <op ...