Nightwatch.js feature not functioning properly in a 'closing' manner

I'm facing an issue where I need to execute a function at the beginning of my test before proceeding with the rest of the test steps.

Here is the custom command I am using, named internalAdviceLinksHtml:

const solr = require('solr-client')

exports.command = function() {
  this
  const client = solr.createClient('solr.dev.bauerhosting.com', 8080, 'cms', '/www.parkers.co.uk');
  const globalSettingsQuery = client.createQuery()
      .q({TypeName:'Bauer.Parkers.GlobalSettings'})
      .start(0)
      .rows(10);  

  client.search(globalSettingsQuery,function(err,obj) {
    if (err) {
      console.log(err);
    } else {      
      const myresult = (obj.response.docs[0].s_InternalAdviceLinksHtml);

      console.log(myresult.length);
      if (myresult.length === 0) {
        console.log('content block not configured');
      } else {    
        console.log('content block configured');
      }
    }
  });        
  return this;
};

Below is the content of the test file:

module.exports = {
  'set up the solr query': function (browser) {
    browser
      .solr_query.global_settings.internalAdviceLinksHtml();
  },

  'links above footer on advice landing page displayed': function (browser) {
    browser
      .url(browser.launch_url + browser.globals.carAdvice)
      .assert.elementPresent('section.seo-internal-links')
  },

  'closing the browser': function (browser)  {
    browser
      .browserEnd();
  },  
}; 

The custom command functions correctly, but it seems like the subsequent test ('links above footer on advice landing page displayed') is not being triggered. It appears that the execution halts after the custom command section. I believe there must be something obvious causing this issue, but I haven't been able to identify it yet.

Your assistance in resolving this matter would be greatly appreciated.

Answer №1

After reviewing your custom command internalAdviceLinksHtml, I believe everything is in order (I assume the lone this was a mistake).

It appears that the Nightwatch test-runner is encountering an issue moving on to the next test, possibly due to a promise not being resolved upstream (specifically in the client.search function within internalAdviceLinksHtml).

To address this problem, I suggest adding a return this statement right after logging to the console (content block not configured or content block configured) and see if that resolves the issue:

  client.search(globalSettingsQuery,function(err,obj) {
    if (err) {
      console.log(err);
    } else {      
      var myresult = (obj.response.docs[0].s_InternalAdviceLinksHtml);

      console.log(myresult.length);
      if (myresult.length === 0) {
        console.log('content block not configured');
      } else {    
        console.log('content block configured');
      }
    }
    return this
  });

Additionally, here are some extra tips:

  • Utilize Nightwatch test-hooks to enhance the readability and maintenance of your tests and establish a clear separation of concerns (setup => before/beforeEach hooks | teardown (e.g: browser.end()) => after/afterEach hooks);
  • You do not need to explicitly call browser.end() at the end of each test case. Refer to this answer for more insights.

Your updated test file should look like this:

module.exports = {
  // > perform setup actions here <
  before(browser) {
    browser
      .solr_query.global_settings.internalAdviceLinksHtml();
  },

  'Verify display of links above footer on advice landing page': function (browser) {
    browser
      .url(browser.launch_url + browser.globals.carAdvice)
      .assert.elementPresent('section.seo-internal-links');
  },
  // > perform cleanup actions here <
  after(browser)  {
    browser
      .browserEnd();
  },  
}; 

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 and show the response from a jQuery GET call

I'm currently working on fetching and displaying data using the ESV API available at Interestingly, the code seems to be functioning properly within the codecademy.com domain but is encountering issues on the esvapi.org domain. Here's a lin ...

Displaying a JQuery notification when hovering over a link

I am having trouble getting an alert to pop up when I hover over a hyperlink using JQuery and Javascript. The hyperlink is inside an anchor within the main section of the HTML. Any assistance would be much appreciated. Here is my current code snippet: &l ...

SimpleBrowser.WebDriver is unable to extract information from a Frame using Selenium

Having trouble retrieving data from a Frame. After checking the Page Source on VS, it seems that the frame I need content from is not visible. Selenium doesn't have access to the contents of the frame, so my final xpath query isn't working as exp ...

React component's state is not being correctly refreshed on key events

Currently facing an issue that's puzzling me. While creating a Wordle replica, I've noticed that the state updates correctly on some occasions but not on others. I'm struggling to pinpoint the exact reason behind this discrepancy. Included ...

Determine the position of an element in relation to a specific ancestor using JavaScript

Let's consider the following example of HTML code: <div id="site_header_container" class="site_bar_container"> <div id="site_header"> <div id="header_logo_container"> <a class="sliced" id="header_ ...

"Error: imports are undefined" in the template for HTML5 boilerplate

After setting up an HTML5 Boilerplate project in WebStorm, I navigate to the localhost:8080/myproject/src URL to run it. Within the src folder, there is a js directory structured like this: libraries models place.model.ts place.model.js addr ...

Error: 'chromedriver' executable is missing from the PATH. Please advise on how to resolve this issue

from selenium import webdriver #from webdriver_manager.chrome import ChromeDriverManager import time browser=webdriver.Chrome(ChromeDriverManager().install()) #browser=webdriver.Chrome() url="exampleurl.com" browser.get(url) time.sleep(10) browser.cl ...

By employing the actions class for scrolling to the bottom of the page, inadvertently clicking on another element triggers an unintended right-click context menu to appear

Currently, I am implementing Actions to automatically scroll down to the bottom of the page: public void scrollToBottomPage(){ Actions actions = new Actions(driver); actions.keyDown(Keys.CONTROL).sendKeys(Keys.END).perform(); } However, in the fo ...

Sorting tables in Jquery with advanced filter options and seamless integration with an ajax pager

I've implemented a tablesorter library for sorting and filtering data in a table along with a plugin that allows me to paginate the table across multiple pages. Due to the increasing number of records in my table causing slow loading times (>60 secon ...

Issue with FontAwesome icon selection in Vue2 (nuxt) not displaying icons

If you're looking for the icon picker, you can find it here: https://github.com/laistomazz/font-awesome-picker I've tried running it, but unfortunately, the icons are not showing up. When I inspect the elements, the code is there but the icon is ...

JavaScript has received an event on Server XHR

Situation: There is a scenario where the target API is external and cannot be altered. A JS client initiates sending data to the API upon clicking a button. The code snippet resembles something like this: $.ajax({ type: "POST", url: &quo ...

React hook form submit not being triggered

import React, { useState } from "react"; import FileBase64 from "react-file-base64"; import { useDispatch } from "react-redux"; import { makeStyles } from "@material-ui/core/styles"; import { TextField, Select, Input ...

What steps should I follow to bring in an animated SVG file into Next.js 13 without losing transparency and animation effects?

How to Include an Animated SVG File in Next.js 13 import Image from "next/image"; export default function Home() { return ( <main className="flex h-screen flex-col items-center"> <div className="container mt-1 ...

Unable to locate phonepe.intentsdk.android.release:IntentSDK:2.4.1 while integrating React Native

android build gradle : // Configuration options for all sub-projects/modules are defined in the top-level build file. buildscript { ext { buildToolsVersion = "33.0.0" minSdkVersion = 21 compileSdkVersion = 33 targetSdkVersion = ...

Determine whether I am verified or if the XMLHttpRequest has been directed

When making an XMLHttpRequest to an API secured with OAuth authentication, I encountered a situation where calling the API from a browser without being logged in automatically redirected me to the provider's login page. However, when attempting to ca ...

Encountering this issue: Unable to access the property 'length' of an undefined variable

I'm currently developing an app using nuxt, vuetify 2, and typescript. Within the app, I have radio buttons (referred to as b1 and b2) and text fields (referred to as t1, t2, t3). When a user clicks on b1, it displays t1 and t3. On the other hand, w ...

jQuery automatic slider for seamless transitions

I am in need of assistance with the coding for a website I'm currently constructing at www.diveintodesign.co.uk/ChrisMcCrone/index.html The coding being used is sourced from http://jquery.malsup.com/cycle/ The central large image functions as a slid ...

Implementing precise search functionality in a table with jquery datatables

Hey there, I'm attempting to implement an exact search feature in jQuery datatables. In my table, I have a column called "status" with values of either "paid" or "unpaid". Currently, when I type "unpaid", it correctly displays only the unpaid record ...

Challenge encountered in posting a variable generated through ajax

Embarking on my first attempt at utilizing ajax has been quite challenging. Essentially, when an option is selected from the initial field, javascript and xml trigger a php script that generates the next dropdown menu based on information fetched from an S ...

I have the latitude and longitude for both the shop and user, and I am looking to display a list of shops in order based

Currently, I have the latitude and longitude for both my shop and the user. My objective is to display a list of shops that fall within the geographic area between the user's location and the shop's coordinates using Sequelize ORM. Can you provid ...