"Implementing NightwatchJS with parallel mode using Selenium Hub and Docker Compose

I have been experimenting with running tests in parallel using nightwatchjs within Docker using Selenium Hub. Initially, I managed to run the tests in parallel in Docker without Selenium Hub, but encountered issues with child processes timing out and requiring multiple retries. This inconsistency in results led me to consider using Selenium Hub or a similar solution to eliminate timeouts and retries, ensuring more stable and consistent test results.

However, when I attempt to execute

docker-compose run --rm nightwatch
, as shown in the code snippet below, the selenium server starts in parallel mode and initiates multiple child processes. Strangely, only the first child process executes successfully. Subsequently, the other child processes encounter an error message stating
Error retrieving a new session from the selenium server. Connection refused! Is selenium server started?
. I am puzzled about what may be missing or causing this issue in order to run nightwatchjs tests in parallel seamlessly without any timeouts.

nightwatch.conf.js

module.exports = {
  src_folders: ['tests'],
  output_folder: 'reports',
  custom_commands_path: '',
  custom_assertions_path: '',
  page_objects_path: 'page_objects',
  test_workers: true,
  live_output: true,
  detailed_output: true,

  selenium: {
    start_process: true,
    server_path: './bin/selenium-server-standalone-3.0.1.jar',
    log_path: '',
    host: '127.0.0.1',
    port: 4444,
    cli_args: {
      'webdriver.chrome.driver' : './node_modules/chromedriver/bin/chromedriver'
    }
  },

  test_settings: {
    default: {
    launch_url: 'https://example.com',
    selenium_port: 4444,
    selenium_host: 'hub',
    silent: true,
    screenshots: {
      'enabled': false,
      'path': ''
    },
    desiredCapabilities: {
      browserName: 'chrome',
      javascriptEnabled: true,
      acceptSslCerts: true,
      chromeOptions: {
        args: [
          '--window-size=1024,768',
          '--no-sandbox'
        ]
      }
    },
    globals: {
      waitForConditionTimeout: 20000,
      asyncHookTimeout: 70000
    }
  }
};

docker-compose.yml

version: '2'

services:
  nightwatch:
    build:
      context: .
    command: /bin/sh -c "node ./node_modules/nightwatch/bin/nightwatch"
    links:
      - chrome
      - hub
    volumes:
      - .:/opt/nightwatch
  chrome:
    environment:
      VIRTUAL_HOST: node.chrome.docker
      HUB_PORT_4444_TCP_ADDR: hub
      HUB_PORT_4444_TCP_PORT: 4444
    image: selenium/node-chrome:3.1.0-astatine
    links:
      - hub
  hub:
    ports:
      - 4444:4444
    image: selenium/hub:3.1.0-astatine

Dockerfile

FROM java:8-jre

## Node.js setup
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get install -y nodejs

RUN npm config set spin false

WORKDIR /app

COPY . ./

RUN npm install

Answer №1

The docker node images are set up to operate with just a single browser instance. However, if you need to modify this configuration, you can do so by overriding certain environment variables. Take a look at the example below:

  firefox:
    environment:
      VIRTUAL_HOST: node.firefox.docker
      HUB_PORT_4444_TCP_ADDR: hub
      HUB_PORT_4444_TCP_PORT: 4444
      NODE_MAX_INSTANCES: 8
      NODE_MAX_SESSION: 8
    image: selenium/node-firefox:3.2.0-bismuth
    links:
      - hub

If you're curious about how I came across this information, I found it while examining the source Dockerfile.

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

What is the best way to target and select all spans within a specific div using JavaScript?

I'm struggling with selecting all spans in the card using code that currently only selects the first span when I use getElementsByTagName. Can anyone offer assistance as I have multiple cards containing spans? TypeError: Failed to execute 'inse ...

Unexpected behavior: Angular post request does not include the expected request body

Embarking on my initial solo Angular project... I am endeavoring to make a post request to my freshly created web service and have implemented the following code: headers = new HttpHeaders( {'Content-Type':'text/plain'} ); l ...

One way to send image data from the front end to the back end using AJAX

Client-Side JavaScript: var userInfo = { 'username': $('#addUser fieldset input#inputUserName').val(), 'email': $('#addUser fieldset input#inputUserEmail').val(), 'fullname': $('#addUser f ...

Uh oh! You haven't set a QueryClient yet. Make sure to use QueryClientProvider to set

My first experience with React Query didn't go as planned when I encountered this error at the beginning of my React app: Even though I added QueryClientProvider to the top of my component tree, I kept getting: Error: No QueryClient set, use QueryCli ...

Improper structure of a JSON for creating a JSON object using JSON.parse

I have a website that generates a tree structure. The file inicio_pru.php creates a JSON representation of the tree, which is then passed to a JavaScript file for rendering the tree. inicio_pru.php is called in two different scenarios. Firstly, when the p ...

Guide for extracting the button click text using selenium and node js, illustrated in the image

Attempting to extract the text displayed upon button click, as seen in the image. Below is the code I have used after accessing the website, however it failed to retrieve the text. //*[@class='']//*[text()=''] ...

Is it possible to monitor Angular events such as routechangestart from external sources like the browser console or an extension?

Is there a method to monitor the routechangestart event of my application directly from the browser console or within a browser extension? I am not very familiar with Angular and have not attempted anything yet. I would like for the user to receive notific ...

Interpolating UV is not allowed: 'flat': Using a reserved word in an illegal manner

As a beginner, I recently learned that UV coordinates are not interpolated in WebGL, allowing for exact pixel values to be retrieved. However, when attempting to use the 'flat' keyword, I encountered an error. By adding 'flat' before t ...

Having Trouble Deploying NextJS Site on Gh-Pages Despite Using basePath and assetPrefix

I recently built a website using next.js that is functioning well locally. The code for this site can be found at: https://github.com/xpress-smoke-shop/website. Now, I am attempting to deploy a static HTML version of the site to the domain: To do this, I ...

Are you patiently anticipating the definition of variables?

As a newcomer to JavaScript, I am experimenting with creating an API that can send requests to other websites and then display the data in an EJS template. I have written some functions to handle the requests, but I am encountering issues when trying to a ...

Creating a React Component in TypeScript that utilizes Promise Objects for data handling

After receiving a Promise type Object as a response, an error has been encountered: Error: Objects are not valid as a React child (found: object with keys { key1, key2, key3 ...}... How can this issue be resolved? // Component.tsx import React, { us ...

Troubles encountered when attempting to click a button (element not accessible) while working with Selenium in Python

Whenever I try to click the second button, an error message pops up saying: selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable This is the HTML code for the buttons: <button class="btn btn-primary btn-fab ...

Accessing the downloaded file from the browser footer using Capybara and Selenium

Can you advise me on how to open a downloaded file from the footer bar? I am working on creating tests for downloading a PDF in Chrome. I would like to be able to open the file and verify its contents as well. Thank you! ...

The live search feature using AJAX is exceptionally sluggish

Update: I am utilizing XAMPP with the built-in Apache server and vscode. I have created a live search input functionality (HTML -> JavaScript -> PHP -> JavaScript -> HTML) that runs smoothly upon initial input. However, I have noticed that it ...

Identifying the completion of loading a HTML page using an object tag

I am trying to load an HTML page using an object tag, and once the page is fully downloaded, I want to display something. I have attempted the following approach, but it is not working: document.querySelector(".obj_excel").addEventListener("load", funct ...

Displaying local PDF files with Vue.js - A comprehensive guide

I've been experimenting with different PDF viewers like pdf.js and vue-pdf, but I'm encountering some issues. With vue-pdf, I am able to make it work, but I can't seem to render local files. And when trying out pdf.js, I attempted to downlo ...

Is it possible to incorporate button classes from the <a> tag into a JQuery fade in/fade out function?

My jQuery image thumb Slider features thumb buttons that link to different div elements. When a user clicks on a thumb button, I want the associated div to smoothly fade in, replacing the previous one. The goal is to have a seamless transition between the ...

There was an issue encountered when trying to call a PHP file within an HTML table using Ajax and data.html

For a small project, I have various news items that need to be included from the "news_all.php" file into table data within the "dashboard.php" file. Due to the predefined root structure restrictions, using include('news.php') is not an option. I ...

Is it possible to remove Sprites from a three.js scene?

Currently facing an issue where I am trying to update axis labels on a 3D plot by removing the old labels (implemented as sprites) before adding new ones. Unfortunately, I am experiencing difficulties. The previous labels seem to persist in the scene even ...

Accessing nested keys within an object and comparing them to keys within another object, with the distinction that the second object contains an array of objects

I encountered a challenge while trying to compare and access data within nested objects and match them with an array of non-nested objects. To illustrate, the scenario looks something like this: const members = [ { name: 'Angelica&apos ...