Encountering a java.lang.ExceptionInInitializerError when attempting to execute the Tests class due to an issue with cucumber.deps.com.thoughtworks.xstream.XStream.setup

Check out this dropbox link for further investigation. Encountered an issue while trying to run a test scenario in IntelliJ, resulting in java.lang.ExceptionInInitializerError at the first step. The StepDefinition class is provided below:

package automation.glue;

import automation.config.AutomationFrameworkConfiguration;
import automation.drivers.DriverSingleton;
import automation.pages.CheckoutPage;
import automation.pages.HomePage;
import automation.pages.SignInPage;
import automation.utils.ConfigurationProperties;
import automation.utils.Constants;
import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import org.junit.Before;
import org.openqa.selenium.WebDriver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;

import static org.junit.Assert.assertEquals;

@ContextConfiguration(classes = AutomationFrameworkConfiguration.class)
public class StepDefinition {
    private WebDriver driver;
    private HomePage homePage;
    private SignInPage signInPage;
    private CheckoutPage checkoutPage;

    @Autowired
    ConfigurationProperties configurationProperties;

    @Before
    public void initializeObjects(){
        DriverSingleton.getInstance(configurationProperties.getBrowser());
        homePage = new HomePage();
        signInPage = new SignInPage();
        checkoutPage = new CheckoutPage();
    }

    @Given("^I go to the Website")
    public void i_go_to_the_Website(){
        driver = DriverSingleton.getDriver();
        driver.get(Constants.URL);
    }

    @When("^I click on Sign in button")
    public void i_click_on_sign_in_button(){
        homePage.clickSignIn();
    }

    @And("^I specify my credentials and click login")
    public void i_specify_my_credentials_and_click_login(){
        signInPage.logIn(configurationProperties.getEmail(), configurationProperties.getPassword());
    }

    @Then("^I can log into the website")
    public void i_can_log_into_the_website(){
        assertEquals(configurationProperties.getUsername(), homePage.getUserName());
    }
}

The issue seems to be that @Autowired is not injecting an instance of ConfigurationProperties in the step definition, but the reason is unclear. Here's the code for the ConfigurationProperties class:

package automation.utils;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

@Component
@PropertySource("framework.properties")
public class ConfigurationProperties {

    @Value("${browser}")
    private String browser;

    @Value("${email}")
    private String email;

    @Value("${password}")
    private String password;

    @Value("${username}")
    private String username;

    public String getBrowser() {
        return browser;
    }

    public void setBrowser(String browser) {
        this.browser = browser;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }
}

The @ComponentScan searches the folder "automation" for @Component which is used in the AutomationFrameworkProperties class:

package automation.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan("automation")
public class AutomationFrameworkConfiguration {
    public AutomationFrameworkConfiguration(){}
}

To execute all of this, I am using RunTests:

package automation;

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

@RunWith(Cucumber.class)
@CucumberOptions(
        plugin = {"pretty", "html:target/cucumber-reports"},
        features = "src/main/resources/features"
)
public class RunTests {
    @Test
    public void test(){}
}

However, after setting up everything, the following error is occurring:

C:\Users\dkreminskyi\.jdks\openjdk-17.0.1\bin\java.exe -ea -DnodeNamesHandler=org.jetbrains.plugins.cucumber.java.run.CucumberTestTreeNodeManager -Didea.test.cyclic.buffer.size=1048576 .... (full error message here).

I am seeking suggestions or solutions as I have seen others face similar errors in tutorials without resolution. Any insights would be greatly appreciated. Thank you.

Answer №1

We've come up with a solution to address your issue.

I'm currently enrolled in a course that focuses on developing an automation project for the automationpractice.com website.

However, there have been some challenges encountered in the course, particularly due to outdated dependencies. The first step involves upgrading these dependencies within the pom.xml

In the RunTests class, it's important to specify the path where the report will be stored. Make sure to add the file name at the end of the route, such as index.html or report.html.

@RunWith(Cucumber.class)
@CucumberOptions(
        plugin = {"pretty", "html:target/cucumber-reports/report.html"},
        features = "src/main/resources/features"
)
public class RunTests {
    @Test
    public void test(){}
}

If you're encountering issues with Dependency Injection not functioning properly, a workaround to resolve this is by directly working with the constants in the StepDefinition class:

//@Autowired
//ConfigurationProperties configurationProperties;

@Before
public void initializeObjects(){
    DriverSingleton.getInstance("Chrome");
    homePage = new HomePage();
    signInPage = new SignInPage();
    checkoutPage = new CheckoutPage();
}

@And("^I specify my credentials and click login")
public void i_specify_my_credentials_and_click_login(){
    signInPage.logIn("encodedEmail", "encodedExample");
}

By implementing these changes, the project should be able to run smoothly and generate the necessary report. I will continue investigating ways to address the @Autowired problem.

Feel free to visit my project's repository link below if you'd like to review my code while I work on resolving the Dependency Injection issue. https://github.com/svascot/automation-practice

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

Is there a dependable resource for mastering Protractor along with the Jasmine Framework in Eclipse using JavaScript?

Starting a new role at my organization where I will be testing Angular JS applications. Can anyone recommend a good website for learning PROTRACTOR with JAVASCRIPT using the JASMINE Framework? (Would prefer if it includes guidance on Eclipse IDE) Thank yo ...

utilizing the process builder in order to retrieve the stream from this particular process

When attempting to use the BufferedReader class to fetch input stream, I encountered an issue. Even though the command console opens with the application running, the variables remain empty and the program gets stuck at the readline() step. This is probabl ...

Guide to selecting a specific year on a calendar using Selenium with JavaScript

While attempting to create a Selenium test using JavaScript, I encountered an issue with filling in calendar data through a dropdown menu: const {Builder, By, Key} = require('selenium-webdriver') const test2 = async () => { let driver = awa ...

ways to parse a JSON array within another JSON array in Java

My task involved extracting the type value and networkUsage download value from a dynamically generated list. Here is an example of the JSON Response I received: { "count": 2, "devices": [ { "name": "xyz ...

Installing selenium, chrome driver, and wdio alongside vagrant or docker integration

When I first tried to learn how to write automated tests for a small project, I faced some difficulties as things weren't working smoothly right from the start. After spending a couple of hours searching and experimenting, I finally found the correct ...

Experiencing issues while setting up and using Selenium and Pycharm, encountering errors during

Upon installing Selenium, I ran a pip check for Selenium and encountered the following issues: qdarkstyle 2.8.1 requires helpdev which is not installed. Spyder 4.1.4 requires pyqt5<5.13 with python version >= "3", but you have pyqt5 ve ...

Parsing CSV rows into a map using Gson

I have a JSON API response that follows a structure resembling a CSV file { "headers": ["x", "y", "z"], "row1": [10, 20, 30], "row2": [40, 50, 60] } My goal is to extract a Plain Old Java Object (POJO) for each row in this JSON object Ideall ...

When using a Map<k,v> to store key-value pairs, what is the best way to retrieve a result when the parameters are uncertain

Within my project, there exists a JSON file structured like so: { "table1": [], "table2": [{ "field1": "value1", "field2": "value2", "field3": "value3" }], "table3": [] } I proceeded to convert this into a JSONObject using JSON-Lib. I have al ...

The session does not support the 'css selector' Locator Strategy Exception error occurred when attempting to locate an instance of EditText using Appium in C#

Successfully opened my app using Appium in C#. Now, on the loginPage, I am trying to retrieve the EditText element in order to input the userName. I have attempted various methods, but they all seem to be causing issues. Here is a snippet of my code: pub ...

Having a tough time getting Selenium to successfully complete the automated checkout process

After experimenting with Selenium and attempting to automate the checkout process, I've encountered a stumbling block in the final part of my code. Despite numerous configurations of 'sleeps' and 'implicit_waits', I keep receiving ...

Error encountered while trying to utilize the modal input box in the Robot Framework Python script

I developed a Robot Framework code to interact with an input box inside a Modal that opens when a button is clicked. However, upon opening the modal, it displays a message stating that the "input box" is not interactable. It's worth noting that there ...

When trying to iterate over a CSV file using Selenium and Pandas in Python, I encountered the error message: "TypeError 'io.BufferedWriter' object is not subscriptable."

Hi there! I'm currently exploring how to integrate data from a csv file into my selenium script. Here's what I have so far: f = pd.read_csv("Data.csv") f.head() for index in range(len(f.index)): Bestellnummer = f["Bestellnumme ...

Is there a way to toast the values of an array retrieved from a getter within my object?

My data in the format of a JSON Array looks like this and I am attempting to display the user_review_ids values - 63,59,62 using a toast message. However, instead of getting the actual values, I keep receiving what seems to be a reference to them, such as ...

I have been assigned the responsibility of loading my default chrome profile, accessing the website, and clicking on the extension. However, I am encountering some

After running the code for the first time, I encounter an issue where the website does not load despite opening with extensions. Clicking on Terminate and running it a second time resolves the problem. How can I ensure the code runs successfully on the f ...

Pressing the button only seems to be effective if a time.sleep function is included in the

click() method in python(selenium) seems to require the use of time.sleep() in order to work properly. The main script already includes an implicit wait at the beginning, so it's puzzling why this additional wait is needed. Can anyone offer insight in ...

Finding a specific element within a table using xpath in selenium proved to be a challenge

I am trying to click on a specific button inside a table where each row has an update button. Here is what my table looks like: <table _ngcontent-vhp-c82="" datatable="" id="dtOptionsComments" class="display table tabl ...

Utilize VBA-Selenium to export table data into separate Excel sheets

My current task involves extracting information from a website in tabular format based on specific keywords. Below are the keywords and the sample website: apple LG Samsung Nokia Website = www.wikipedia.com I have organized the keywords in Sheet 1 and th ...

Having difficulty downloading the Maven Resources Plugin during a Jenkins build

I have created and tested Selenium IDE test cases in Eclipse as part of a Maven Java project. The tests run fine in Eclipse but encounter an error and result in build failure when I add the project to Jenkins. The encountered error: Started by user anony ...

Tips for Troubleshooting Selenium Using Python

I'm encountering a problem where Selenium is not performing as intended. In my Python script, I locate an element by its id. If the node is visible, I proceed to click on it and capture a screenshot. However, the current behavior is unexpected. Selen ...

"What are the necessary components to include in UserDTO and what is the reasoning behind their

Presenting the User entity: package com.yogesh.juvenilebackend.Model; import jakarta.annotation.Generated; import jakarta.persistence.*; import lombok.*; @Entity @Getter @Setter @NoArgsConstructor @AllArgsConstructor @RequiredArgsConstructor public class ...