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

Struggling to implement JQuery code in a Next.js application

I'm having trouble getting my tracking code to work in Next.js. <Script> window.dataLayer = window.dataLayer || []; function gtag(){ dataLayer.push(arguments) } gtag('js', new Date()) ...

Refresh the page using a promise in Angular after a delay of 3 seconds

Currently, I am working on enhancing the functionality of the login page. In case a user enters an incorrect login and password combination, my goal is to have the page automatically reload after 3 seconds. Despite my best efforts, I have encountered chall ...

Failure to achieve success with jQuery Ajax

success in my AJAX call is not triggering at all, leaving me puzzled as to why. None of the alerts specified in the AJAX file are appearing. The form: <form onsubmit="check_reg();return false;" method="post" name="reg_form" id="reg"> <label ...

Storing executable scripts in HTML5 LocalStorage allows for the dynamic creation

As I work on a hybrid app with its own local HTML and JS files, there are times when I need to load additional small executable JS scripts and CSS from the server. Currently, I achieve this by using $.getScript, which has been working well. In order to ma ...

Having difficulty initiating Selenium Grid

Having some issues with getting Selenium Grid Hub to start. I've been using the command below: java -jar selenium-server-standalone-2.25.0.jar -role hub After running this command, I receive the following message: Jul 25, 2012 1:26:26 PM org.openqa. ...

Selenium's repeated attempt to retrieve articles results in a NoSuchElementException

I am working on a project where I need to scrape a list of 100 articles from a simple webpage. The page has javascript running in the background that retrieves the articles when it loads. The URL of the webpage is: For extracting the top 30 articles, I ha ...

Adding a picture to the webpage and saving it temporarily on the site

After exploring all options on the site, testing it rigorously and closely following the instructions provided, I am still unable to determine where exactly I went wrong. Website Link: The main goal is to upload an image and temporarily store it within t ...

Enhancing Couchdb documents with unique id and author information through an update handler

Is there a way to include additional fields using the update handler in Couchdb? I'm trying to insert the author (with a validation function to verify that the user is logged in) and the id when creating a new document via an update handler. The auth ...

Encountered a connection error while attempting to establish a connection in Node.js

Every time I try to execute the code, I encounter this error message: throw new Error('Most middleware (like ' + name + ') is no longer bundled with express and must be installed separately ^ Error: Most middleware(like BodyParser) is ...

What is the best way to verify if a text input has a valid email format in ReactJS?

When working with ReactJS, how can I properly check if text entered in a <TextField/> component is in email format (i.e. contains @)? Since my application is connected to MongoDB, should I perform the email format validation on the client-side or se ...

What methods does Javascript callback employ to access an external variable that has not yet been defined?

Hi all, I am a beginner in nodejs and recently stumbled upon this function within express var server = app.listen(()=>{ console.log(server.address()) }) I'm curious about how the callback utilizes the object that is returned by the listen func ...

Ways to create distance between repeated cards in a loop. My method involves utilizing ajax, jquery, and bootstrap

view image description here What is the best way to create some space between these closely aligned cards? .done((todos) => { todos.forEach(el => { console.log(el) $("#todo-list").append(` <d ...

What strategies can I implement to reduce the execution time of my code?

Is there a way to optimize this code for faster performance? It currently takes over 10 hours to scrape all 50,000 profiles. I would appreciate any suggestions on how to reduce the runtime. Thank you! from selenium import webdriver from selenium.webdriv ...

Can one integrate various angular components constructed using distinct versions of Angular?

Is it feasible to utilize various angular components (custom elements) created with different versions of Angular? I've heard concerns about zone.js causing global scope pollution. Appreciate your response! ...

Putting Jenkins, selenium-grid, and protractor to the test with end-to-end testing

Currently, I am in the process of setting up my testing environment using Jenkins, Selenium, and Protractor. To efficiently distribute tests across remote machines (nodes), I have opted to utilize the selenium-plugin (selenium grid). The initial progress i ...

Error: 'require is not defined' pops up while trying to import into App.js for a React App built with CDN links

My latest project involves a React App that showcases an h1 tag saying "Hello World" on the browser. Rather than utilizing npm, I have opted for CDN links to set up the application. The structure of the App consists of three key files: An index.html file ...

`In HTML, trigger blocks based on the number chosen by the user`

I am working on creating a web page where users can select the number of friends they have, and based on that input, a corresponding number of invisible boxes will be triggered. For example, if a user selects 3 friends, 3 boxes will appear for them to ente ...

When executing through Jenkins, the screenshot does not get included in the final report

While using the remote-webdriver instance of BrowserStack, I encountered an issue where the failed screenshot is not being attached to the report when running in Jenkins. The folder structure is ExtentReport\Screenshots. https://i.sstatic.net/mZSQJ.p ...

Switch out the words within the input box

My code has the ability to convert words to numbers, however, when I try to paste a text like: three four one one four five six one, the output I receive is: 3411456one If I click on the text input again, the word 'one' changes to '1', ...

Having difficulty adjusting the width of a div element

I've been struggling to adjust the width of the div assigned with the colors class, whether in percentage or pixels. var colors = ["RED", "GREEN", "BLUE", "YELLOW", "PURPLE"]; for (var h = 0; h <= 4; h++) { for (var i = 0; i <= colors.lengt ...