Having difficulty running my selenium test on the virtual machine

My goal is to execute my Selenium test using selenium grid. To achieve this, I have set up the hub on my local Ubuntu machine and a node on a Centos VM. I ran the following commands:

  1. java -jar selenium-server-standalone-3.141.59.jar -role hub (on local machine )
  2. java -Dwebdriver.chrome.driver="/usr/bin/chromedriver" -jar selenium-server-standalone-3.141.59.jar -role node -hub http://hubipaddress:4444/grid/register

Both commands executed successfully and the node was also set up without any issues as verified from the console.

Here is a snippet of the code used:

          DesiredCapabilities cap1=new DesiredCapabilities();
          String hubURL = "http://10.242.2.6:4444/wd/hub";
          cap1.setBrowserName(browser);
          ChromeOptions option=new ChromeOptions();
          option.addArguments("--headless","--no-sandbox");
          option.merge(cap1);
          driver=new RemoteWebDriver(new URL(hubURL),option);
          driver.get("http://practice.automationtesting.in/my-account/");
          driver.findElement(By.id("username")).sendKeys("pavanoltraining");
          driver.findElement(By.id("password")).sendKeys("Test@selenium123");
          driver.findElement(By.name("login")).click();

However, when running the test script from my local machine, I encounter the following error after a few seconds:

11:43:08.894 INFO [RequestHandler.process] - Error forwarding the new session Error forwarding the request Failed to connect to /**nodeIpAddress**:22956
org.openqa.grid.internal.exception.NewSessionException: Error forwarding the request Failed to connect to /**nodeIpAddress**:22956
    ....(more detailed error message)

I have tried various solutions but have not been able to identify the root cause of the problem.

Answer №1

Give this a try:

            private WebDriver driver;
            private ChromeOptions chromeOptions;
            private DesiredCapabilities caps;
            // Virtual Machine Test
            private final String URL = "http://10.242.2.6:4444/wd/hub";
            ChromeOptions options = new ChromeOptions();
            options.addArguments("--headless");
            options.setCapability(CapabilityType.BROWSER_NAME, "chrome");
            options.setCapability(CapabilityType.PLATFORM_NAME, Platform.LINUX);
            options.addArguments("Proxy", "null");
            options.setExperimentalOption("useAutomationExtension", false);
            options.addArguments("--disable-dev-shm-usage");
            options.addArguments("--no-sandbox");
            options.addArguments("window-size=1920,1080");
            options.addArguments("--disable-gpu");
            options.addArguments("start-maximized");
            options.addArguments("--allow-insecure-localhost");
            options.addArguments("--ignore-certificate-errors");
            System.out.println(options);
            driver = new RemoteWebDriver(new URL(URL), options);
            driver.manage().window().fullscreen();

I have tested this and it worked for me. If the node is connected to the Hub and you can see that in the console, then this solution should work.

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

Utilizing Selenium JavaScript to insert a cookie into a request

Trying to add a cookie to the request in Selenium using JavaScript. I followed the documentation at this link, but my code snippet doesn't seem to pass any cookies to the PHP script below on the server. Here is the client-side JavaScript code: var w ...

The compilation of debug Java with Javac in CordovaLib is not being done incrementally

I am currently in the process of setting up Ionic on my new computer, but I have encountered an issue while trying to build a Cordova Android project that I can't seem to resolve. The software and versions I am using include: NodeJS v6.9.1 npm ...

Having difficulty incorporating custom JavaScript files into a testing framework

I am facing a unique challenge while integrating the Page Object design pattern into my test suite using selenium-webdriver and node.js. The first page object, pageObject/admin/login/index.js, works seamlessly. It contains selectors and methods to fill ou ...

How would you execute a simple protractor test with the provided file hierarchy?

I have attempted to follow a tutorial located HERE for running protractor tests. Despite my efforts, I am facing an issue where the tests do not seem to run when I attempt to start them. While my webdriver-manager is functioning correctly, nothing seems to ...

Is it possible to run nightwatch.js tests on a Linux machine?

Struggling to kick off the nightwatch automated UI tests on a Linux machine running CentOS OS? Starting is proving to be quite challenging. This is the test_settings configuration in my nightwatch.json: "test_settings": { "default": { ...

Facing difficulties in initiating Selenium with PhantomJS/GhostDriver as child processes

I am currently working on a Node script that involves using the child_process module in order to run a Selenium server with PhantomJS's GhostDriver. I have imported the module: Child = require "child_process" This is how I am attempting to start the ...

Tips for interacting with a custom web component using Selenium WebDriver

As a newcomer to writing selenium tests, I am attempting to create an automated test for a carousel feature on our homepage. The objective is to click on one of the carousel navigation buttons and then confirm that a specific inline style has been applied ...

Having trouble locating the web element within a div popup while utilizing Node.js and WebdriverIO

I need assistance with a seemingly simple task. I am currently learning webdriverjs and attempted to write a short code to register for an account on the FitBit website at URL: www.fitbit.com/signup. After entering my email and password, a popup appears as ...

Steps to effortlessly retrieve a CSV file using Selenium without dealing with the bothersome file dialog

I've been attempting to access a URL with a CSV file for download in a specific directory by using the Selenium Webdriver for Firefox (geckodriver) in a NodeJS environment on Linux-Mint. Here's the code I'm working with: const {Builder} = r ...

Transform a protractor screenshot into a PDF file

I'm currently working on a small Protractor code that captures screenshots, but my goal is to save these screenshots as PDF files. Below you can find the code snippet I have written. await browser.get(url); const img = await browser.takeScreenshot(); ...

Issue with installing chromedriver and selenium-driver on Windows 7 using NPM arise

I have a relatively basic package.json file with some development dependencies included. Here is what it looks like: "devDependencies": { "cssnano": "3.3.2", "cucumber": "0.9.2", "diff": "2.2.0", "grunt": "0.4.5", "jit-grunt": "0.9.1", " ...

Combining multiple storageStates in a playwright context for efficient loading

I am trying to load multiple storageStates into a single context in playwright, but I am facing some issues. When using the following code: const context = await browser.newContext({ storageState: "telegram.json",storageState: "google. ...

Ubuntu compatibility with chrome-driver 83

Currently using Ubuntu 18.04.1 LTS with Google Chrome version 83 and corresponding chrome-driver version 83 successfully for a while, I recently encountered an issue after updating to the latest stable versions: google-chrome-stable v83.0.4103.61 and chrom ...

Executing Selenium tests: utilizing the webdriver.wait function to repeatedly call a promise

Currently, I am using Selenium ChromeDriver, Node.js, and Mocha for testing purposes... I am facing a dilemma at the moment: The driver.wait function seamlessly integrates with until. I have a promise, which we'll refer to as promiseA. This pro ...

The situation arose when Webpack unexpectedly terminated before completion

Currently, I'm facing an issue with my project that I've been developing using Vaadin 14.4.10 and Node.js 14.16.1 without any hassle until now. The only recent change I made was updating the Vaadin version to 23.3.6 while working in a local branc ...

Error Alert: Fatal issue encountered while utilizing a Java npm package

Currently in my Meteor application, I am utilizing the 'node-excel-api' npm package which has a dependency on the 'java' npm package. Upon starting up the Meteor server, I encountered the following error message: A critical error has b ...

Converting hexadecimal string to a double value in Java

Currently, I am working on decoding the value of the "Well-known Binary" format using Java. The Node script below accomplishes this task: Buffer.from('A4C0A7DEBFC657C0', 'hex').readDoubleLE() // returns -95.1054608 I am struggling to f ...

"Exploring the dynamic capabilities of Node.JS and Java Publisher/Subscriber

I am working on developing an application where communication will be facilitated through a node.js server. This node server is responsible for receiving messages from other peers. Here is the code snippet for my node.js: var zmq = require('zmq&apos ...

Developing single-page application frontends without utilizing node or npm

As a backend java developer with experience in spring boot, I am now exploring the world of single page applications. One aspect that appeals to me about SPA frameworks, particularly Vue, is things like model-binding and the use of components and template ...

Single Linked List - retrieve and insert functions

Today I'm tackling the challenge of implementing an SLList class by completing operations such as: get(i), set(i, x), add(i, x), and remove(i), all designed to run in O(1 + i) time. The areas where I'm encountering issues in my program are part ...