Cucumber experiencing issues in @before hook: NoClassDefFoundError

The automation framework is facing an issue where it does not proceed with executing steps in the .feature file after opening the Chrome browser, which then closes abruptly.

Code Snippet from GenericStepImplementation.java:

@Before
public void setUp() throws ConfigurationException, org.apache.commons.configuration.ConfigurationException
{
    System.setProperty("webdriver.chrome.ChromeDriver","C:\\Automation\\Webdrivers\\chromedriver.exe");
    driver = new ChromeDriver();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.manage().window().maximize();
    config = new XMLConfiguration("sample-object-config.xml");
}

Code Snippet from RunAutoTest.java:

package test_runner;

import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(
glue={"code_bindings"},
features="src/test/resources/features", 
plugin = {"pretty", "html:target/cucumber-html-report"})

public class RunAutoTest {

}

Content of Sample.feature file:

Feature: Automation Test

@Login-Successful
Scenario: Login (Successful)
Given I go to "www.yahoo.com" URL
    Then I enter "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9ff2dfe6fef7f0f0b1fcf0f2">[email protected]</a>" into "login.username" field and click tab
    Then I enter "1234567890" into "login.password" text field
    Then I clicked on "login.loginlink" login button
    Then I wait for "15" seconds
    And I will capture the page named "Login-Successful"

Upon running as a JUnit Test, the Chrome browser opens but fails to execute the steps in the Sample.feature file. The console displays the following error message:

*Feature: Automation Test
Starting ChromeDriver 2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387) on port 11795
Only local connections are allowed.
Jan 07, 2019 6:00:53 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
[31mFailure in before hook:[0m[31mGenericStepImplementation.setUp()[0m
[31mMessage: [0m[31mjava.lang.NoClassDefFoundError: org/apache/commons/collections/CollectionUtils
    at org.apache.commons.configuration.XMLConfiguration.constructHierarchy(XMLConfiguration.java:640)
    at org.apache.commons.configuration.XMLConfiguration.constructHierarchy(XMLConfiguration.java:635)
    at org.apache.commons.configuration.XMLConfiguration.initProperties(XMLConfiguration.java:596)
    at org.apache.commons.configuration.XMLConfiguration.load(XMLConfiguration.java:1009)
    at org.apache.commons.configuration.XMLConfiguration.load(XMLConfiguration.java:972)

Answer №1

In order to modify the code within the System.setProperty line, it is necessary to replace the keyword from ChromeDriver to driver. Therefore, make sure to alter the following:

System.setProperty("webdriver.chrome.ChromeDriver","C:\\Automation\\Webdrivers\\chromedriver.exe");

With:

System.setProperty("webdriver.chrome.driver","C:\\Automation\\Webdrivers\\chromedriver.exe");
                             only ^^^driver^^^

Answer №2

Click here for more information on NoClassDefFoundError

This error occurs when a class was present during compilation, but is missing at runtime.

Make sure that your classpath includes the

org/apache/commons/collections/CollectionUtils
. It's possible that the commons-collections library is not in the classpath.

Answer №3

Update the following code snippet with the correct file path for the ChromeDriver:

System.setProperty("webdriver.chrome.ChromeDriver","C:\\Automation\\Webdrivers\\chromedriver.exe");

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

How can I use Python Selenium webdriver to input text into a text field using send

Below is the HTML code snippet for the text field: <div tabindex="-1" class="_2bXVy"><div tabindex="-1" class="_3F6QL _2WovP"> <div class="_39LWd" style="visibility: visible;">Type a message</div> <div class="_2S1VP copy ...

Ways to identify JSON data within an InputStream?

Is it possible to determine if the data in a java.io.InputStream (from File, URL, etc.) is JSON without loading the entire stream? The ideal method would involve validating the whole stream as JSON by checking for JSON-specific indicators such as a closin ...

Iterating through the last pages always results in a false return

I am encountering an issue where the methods in my test are functioning correctly, but I am getting a false return when the pages end. How can I ensure that after the method runs, it returns true? I understand that I need to address the logic in the initN ...

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 ...

Effortless Ways to Automatically Accept SSL Certificates in Chrome

It has been quite some time that I have been attempting to find a way to automatically accept SSL certificates. Unfortunately, I haven't had any success yet. The scenario is this: I am working on selenium tests and every time I run the test on Chrome, ...

Iterate through and append to a list

My current goal is to create a list of URLs named visit_urls that I need to visit. To begin with, I manually provide the first URL to be visited using self.br.get(url). By determining the number of pages on the website, let's say it has 40 pages, I ca ...

Trying my best to use Selenium to fetch data by executing JavaScript...I guess

I've been attempting to retrieve information from this particular URL. My current code does not manage to extract any of the data as expected. import urllib.request from bs4 import BeautifulSoup url = "https://www.nissanusa.com/dealer-locator.html" ...

Tips for interfacing with Angular ColorPicker elements using Selenium WebDriver

Is there a way to automate interactions with Angular ColorPicker components using Selenium WebDriver? Since there is no text field input for hex codes, it relies solely on mouse clicks. For reference, you can check out this example: https://www.primeface ...

Unable to retrieve docx files with selenium in headless chrome

Currently, I am in the process of automating an end-to-end (E2E) task that involves downloading files from a drop-down menu. The functionality works flawlessly using chromedriver without the headless mode activated. However, when I enable Chrome options fo ...

Is it possible to transmit messages from a Chrome extension to a Java server?

My question is, if I want to create a Chrome extension that sends messages to a Java server, should I use the XmlHttpRequest API in the extension and have the Java server as an HTTP server? ...

Interact with webpage dropdown menus using Python

I'm currently working on a Python script that interacts with a webpage, specifically , to retrieve a (DNA sequence in fasta format) file. The file is automatically downloaded when a user clicks on a dropdown menu. Here's the dropdown menu: Dow ...

Updating Element Attribute with Selenium in Python

Currently, I am utilizing python selenium to streamline data input on a specific website. The challenge lies in the fact that one of the fields restricts characters to a maximum length of "30". <input data-qa="input-LogId" data-testid="input-LogId" ...

When the Protractor configuration is executed, it displays the message "The requested webpage cannot be accessed."

Testing protractor on a vanilla.js app and encountering an error when running protractor basicConf.js The following error is occurring: This webpage is not available ERR_CONNECTION_REFUSED Here is the test script in use: describe('foo', fun ...

I was taken aback when my reliable tests on WebDriver started failing due to the error message "Other Element Would Receive Click"

After returning from vacation, I encountered an issue with a dozen automated UI end-to-end tests in WebDriver using C# on Chrome. Most of the tests were failing with similar errors related to clickable elements and coordinates: Result Message: System.Inva ...

Internet Explorer node connected to a Selenium hub

Can Selenium Hub be utilized with an Internet Explorer node? I have successfully used Selenium Hub with Firefox and Chrome nodes using Docker and Kubernetes with the images available at . However, I cannot find an Internet Explorer image on Selenium' ...

Update the content within every <td> element using AJAX/JQUERY on a table created from JSP

I have a database filled with descriptions and corresponding ID numbers. The table displays them like this: index.jsp <table> <tr> <td>Name:</td> <td>Id:</td> </tr> <c:forEach items ...

Is there a way to verify if a file was successfully downloaded after clicking a button using Selenium Webdriver

I'm attempting to trigger a button click with the following code: public void clickDownloadButton() { WebDriverWait wait = new WebDriverWait(driver, 15); wait.until(ExpectedConditions.elementToBeClickable(downloadTransactionsButton)). ...

Picking an option from a dropdown menu by hovering over the main menu item with the assistance of Selenium

I need assistance with selecting the "Application Processing" menu item after hovering over the "Asmt Admin" parent menu item option. The HTML code is provided below: <div id="topmenu"> <div id="ctl00_topMenu1" class="RadMenu RadMenu_GovernBl ...

Guide: Interacting with the Sign up button on Spotify's registration page with Python Selenium

Having trouble clicking the "sign up" button on the Spotify registration page. I have located the xpath and css for the button but still can't click it. I even attempted to use "click text" but encountered the same issue. WebDriverWait(driver,10).unti ...

clicking on a download link to retrieve a CSV file from a webpage

I am currently experiencing an issue with downloading a csv file from a website that requires login. Using Selenium, I have managed to successfully log in. However, I am unsure of how to proceed with downloading the csv file by clicking on a button. Despit ...