Cucumber - Steps Without Definition Yet Fully Defined

I have recently started working on a Simple Selenium Cucumber project and have defined steps using the "Lambda Expressions Constructor" method in a feature file. However, when I tried to run the CucumberTest class, I encountered a failure exception.

The error message says: "There are undefined steps!"

Here is my StepDefinition:

https://i.stack.imgur.com/UgEqO.png

And this is my Feature file:

https://i.stack.imgur.com/p22o1.png

Below is the code for my CucumberRunner class:

https://i.stack.imgur.com/ugpoJ.png

Could you please suggest an alternative approach for calling the Step Definition File if I am using Lambda Expressions?

Answer №1

As mentioned in a previous comment, the glue option requires a list of package names, not directories. Changing it from

glue = {"src/test/java/my.project.automation.wolfram_alpha" }

to

glue = {"my.project.automation.wolfram_alpha" }

will resolve the problem.

Below are working code snippets for the given project structure:

src/test/java/my/project/automation/wolfram_alpha/StepDef.java
src/test/java/my/project/automation/wolfram_alpha/cucumberTest.java
src/test/resources/wolfram.feature
pom.xml

pom.xml (dependencies section)

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <version.cucumber>3.0.2</version.cucumber>
</properties>
<dependencies>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java8</artifactId>
        <version>${version.cucumber}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${version.cucumber}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>${version.cucumber}</version>
        <scope>test</scope>
    </dependency>
</dependencies>

cucumberTest.java

package my.project.automation.wolfram_alpha;

import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;

@CucumberOptions(
        features = { "src/test/resources/wolfram.feature" },
        glue = {"my.project.automation.wolfram_alpha" }
)
public class cucumberTest extends AbstractTestNGCucumberTests {
}

StepDef.java

package my.project.automation.wolfram_alpha;

import cucumber.api.java8.En;

public class StepDef implements En {
    public StepDef() {
        Given("URL of WolframAlpha", () -> {
            System.out.println("Given URL of WolframAlpha");
        });
        When("user logged in as {string} with {string}", (String user, String password) -> {
            System.out.printf("When user logged in as {%s} with {%s}%n", user, password);
        });
        And("login is successful", () -> {
            System.out.println("And login is successful");
        });
        And("user search for a {string}", (String topic) -> {
            System.out.printf("And user search for a {%s}%n", topic);
        });
        Then("results are displayed in a creative way", () -> {
            System.out.println("Then results are displayed in a creative way");
        });
    }
}

wolfram.feature as per the question

Running the test with mvn test will yield the following output.

Running my.project.automation.wolfram_alpha.cucumberTest
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@726f3b58
Given URL of WolframAlpha
When user logged in as {user} with {password}
And login is successful
And user search for a {IDOL}
Then results are displayed in a creative way

1 Scenarios (1 passed)
5 Steps (5 passed)

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

Encountering difficulties with submitting a drupal menu add form through Selenium

My quest to create a new menu in Drupal (8 URL: <site url>/admin/structure/menu/add) using the Python Selenium Chrome Webdriver has hit a roadblock - every time I attempt to submit the form, nothing seems to happen. I've explored various method ...

Using Python with Selenium, attempt to click on a button designated as type="button"

I've been trying to click on a button in this Airbnb listing but none of the codes I tried seem to work. Here is one example of the HTML code: <li data-id="page-2" class="_1eqazlr"> <button type="button" class="_1ip5u88" aria-label="Page 2 ...

Python Selenium is unable to locate the Password ID

I am fairly new to Python and Selenium, attempting to develop a program that can log in to a Microsence network outlet. The browser opens successfully and I use the built-in API to access Firefox, but Selenium is unable to locate the Password ID for loggin ...

How to Use Selenium to Locate the Innermost Elements that Contain a Particular Text

Is there a way to retrieve a list of elements from a webpage that contain a specific string without modifying the page's structure? I am currently using Selenium with XPath for evaluation, leveraging the browser-supported XPath engine. Here is a simp ...

Running two different wdio.config.js files consecutively

Is it possible to run two wdio.config.js files with different configurations, one after another? Here is how the first configuration file is defined in the code: const { join } = require('path'); require('@babel/register') exports.co ...

python-selenium clicking on specific coordinates: "error when adding different types"

I'm having an issue with my automated tests on Robot Framework where I need to click on specific coordinates on a map. Here is the code snippet that I wrote: def click_at_coordinates(pos_x, pos_y): actions = ActionChains(get_driver()) my_map ...

"Python Selenium's TimeoutError Raised When Web Page Doesn

Is there a way to customize the TimeoutException in Selenium? I am facing issues with my script crashing when page loads take longer than 300 seconds. The script triggers a php script on the backend, and if the php script runs for less than 300 seconds, e ...

Having trouble launching Firefox with Selenium test in Java using Netbeans?

I recently installed Selenium IDE on Firefox, ran a simple test, and exported the test cases to Netbeans using Java/JUNIT4/WebDriver. However, when I tried to run the code in Netbeans, Firefox did not launch as expected. Interestingly, another program of m ...

Transforming C# code into Python programming language

Hello, I have created a web scraper using Selenium in C#, but now I need to convert it into Python for my project. I am having trouble displaying the element in the console window. Here is the C# code: var elements = ghostDriver.FindElements(By.XPath("/h ...

Utilizing C# Windows Forms to Engage With a Web Browser

Currently, I have created a Windows Form application using C# that is able to communicate with a phone system. My next goal is to incorporate click-to-dial capabilities into the application. The idea is that when a telephone number is clicked on in a web ...

Why do some classes need to be instantiated while others do not?

When working with Java, certain classes need to be instantiated using the new keyword. If these classes are instantiated using new, then only eclipse will display their methods as suggestions after the object. However, for some classes, you just need to t ...

The error message "Unable to establish a connection to security.ubuntu.com:80" keeps popping up while attempting to execute a shell command in Databricks

I have been trying to implement Selenium on an AWS Databricks platform following the guidelines in a recent post. However, every time I execute the code provided, I encounter the same error: Partial Error: Could not connect to security.ubuntu.com:80 Code ...

Accessing input fields within an HTML form using Selenium.Note: Please provide

I am struggling to select input fields from this specific form in Selenium. Despite trying multiple methods, my test consistently fails. Here is the HTML form in question: `<form class="login" action="/Index/trylogin/?ru=L015RmlueWE=" novalidate> ...

Steps for accessing the search input box in Office365 Hotmail:1. Open your web

I'm having trouble with automating the process of opening an email through searching for the email address. Despite trying various XPaths and Actions, I can't seem to click on the search box. Can anyone provide assistance? This is being done in ...

The issue of JMeter WebDriver failing to recognize variable values

I'm currently facing some confusion while using JMeter with Selenium. My scenario involves having two Webdriver Samplers for different pages and a JSR223 Sampler to set up data, such as vars.put("loanAmount", "50000"); and other variables. Interesti ...

Evade the pop-up warning in IE 10 when downloading, or utilize the save button with Selenium Webdriver in C#

How can we use Selenium - WebDriver (C#) to click on the save button of an IE 10 warning message that appears when trying to download a file? If clicking is not an option, how can we disable this warning without needing to alter the system registry so tha ...

Allow SSL certificate using Marionette with Python's Splinter library in Firefox WebDriver

While utilizing Python Splinter with Firefox 47 and the new Marionette webdriver, I encounter a certificate error when trying to access a specific website. I attempted to resolve this issue by accepting SSL certificates using the following code: browser = ...

Selenium is struggling to identify the XPath displayed on the developer tools

https://i.stack.imgur.com/enl7F.jpg https://i.stack.imgur.com/LNQW9.jpg I am currently facing an issue with validating the visibility of a comment I posted on my profile. The comment appears on my wall and profile feeds, but Selenium is unable to recogni ...

The Selenium webdriver fails to close the Chrome driver

I'm having an issue with the Selenium webdriver not properly quitting chrome and chrome driver. Some processes are remaining active after closing. Here is the code I am using to quit chrome: driver.quit(); And here is the code I use to start chrome ...

Are there any tools available to facilitate sending commands to Selenium through an interpreter?

As a Perl programmer, I am currently engaged in web application testing with Selenium. However, I am in search of an interactive interpreter that would allow me to enter Selenium commands directly at a prompt and have them executed by Selenium. My current ...