Protractor failing to identify cucumber step definitions

After setting up my Angular6 project with Protractor and Cucumber for user acceptance tests, I encountered a recurring error when running test cases:

Undefined. Implement with the following snippet:

I've experimented with various combinations of cucumber versions (2,3,4), syntaxes, and import methods, but the error persists or changes to:

Unhandled rejection TypeError: this.registerHandler is not a function

Even after trying different versions of protractor-cucumber-framework and cucumber, I haven't been able to resolve the issue.

Regardless of whether I use plain strings, regular expressions, callbacks, async functions, etc., the step definitions are not being recognized.

Does anyone have any suggestions on how to tackle this problem?

Thank you in advance.

Below are details from my current configuration:

Repository:

https://github.com/stevensgarcia/uat-cucumber

Directory Structure:

e2e
├── src/
│   ├── features/
│   │   └── home.feature
│   ├── hooks/
│   ├── pages/
│   │   ├── basePage.ts
│   │   ├── courseDetails.ts
│   │   ├── homePage.ts
│   │   └── locator.interface.ts
│   ├── steps/
│   │   └── home.steps.ts
│   └── homePage.e2e-spec.ts
└── tsconfig.e2e.json

cucumber.conf.ts Configuration:

exports.config = {
  allScriptsTimeout: 60000,
  useAllAngular2AppRoots: true,
  capabilities: {
    browserName: 'chrome'
  },
  // SELENIUM_PROMISE_MANAGER: false,
  // required feature files
  specs: [
    './e2e/src/features/*.feature'
  ],
  directConnect: true,
  // seleniumAddress: 'http://localhost:4444/wd/hub',
  baseUrl: 'http://localhost:4200/',
  framework: 'custom',
  frameworkPath: require.resolve('protractor-cucumber-framework'),
  onPrepare() {
    require('ts-node').register({
      project: './e2e/tsconfig.e2e.json'
    });
  },

  cucumberOptions: {
    // required step definitions
    compiler: [],
    require : [ './e2e/src/**/*.steps.ts' ],
    strict  : true,
    format  : ['pretty'],
    dryRun  : false,
    tags    : []
  },
  disableChecks: true,
};

home.feature File:

Feature: To work with home page

  @smoke
  Scenario: Click course of application
    Given I navigate to application
    When I get all the heading
    When I click the 'Selenium framework development' course
    Then I should see 'Selenium framework development' course in coursedetails page

home.steps.ts Implementation:

import { defineSupportCode } from 'cucumber';
import { HomePage } from '../pages/homePage';
import { expect } from 'chai';
import { CourseDetailsPage } from '../pages/courseDetails';

defineSupportCode(({Given, When, Then}) => {

  const homePage = new HomePage();
  const coursedetails = new CourseDetailsPage();

  Given(/^I navigate to application$/, async() => {
    await homePage.OpenBrowser('http://localhost:4200');
  });

  When(/^I get all the heading$/, async() => {
    await homePage.GetAllHeadings();
  });

  When(/^I click the '([^\"]*)' course$/, async(headingText) => {
    await homePage.ClickFirstHeading(headingText.toString());
  });

  Then(/^I should see '([^\"]*)' course in coursedetails page$/, async(course) => {
    // tslint:disable-next-line:no-unused-expression
    expect(coursedetails.GetCourseHeading).to.be.not.null;
  });

});

Output:

>> uatPlayground  (develop *) !3008 $ ./node_modules/.bin/cucumber-js -r ./e2e/src/steps ./e2e/src/features
Feature: To work with home page

  @smoke
  Scenario: Click course of application
  ? Given I navigate to application
  ? When I get all the heading
  ? When I click the 'Selenium framework development' course
  ? Then I should see 'Selenium framework development' course in coursedetails page

Warnings:

1) Scenario: Click course of application - e2e/src/features/home.feature:4
   Step: Given I navigate to application - e2e/src/features/home.feature:5
   Message:
     Undefined. Implement with the following snippet:

       Given('I navigate to application', function (callback) {
         // Write code here that turns the phrase above into concrete actions
         callback(null, 'pending');
       });

2) Scenario: Click course of application - e2e/src/features/home.feature:4
   Step: When I get all the heading - e2e/src/features/home.feature:6
   Message:
     Undefined. Implement with the following snippet:

       When('I get all the heading', function (callback) {
         // Write code here that turns the phrase above into concrete actions
         callback(null, 'pending');
       });

3) Scenario: Click course of application - e2e/src/features/home.feature:4
   Step: When I click the 'Selenium framework development' course - e2e/src/features/home.feature:7
   Message:
     Undefined. Implement with the following snippet:

       When('I click the \'Selenium framework development\' course', function (callback) {
         // Write code here that turns the phrase above into concrete actions
         callback(null, 'pending');
       });

4) Scenario: Click course of application - e2e/src/features/home.feature:4
   Step: Then I should see 'Selenium framework development' course in coursedetails page - e2e/src/features/home.feature:8
   Message:
     Undefined. Implement with the following snippet:

       Then('I should see \'Selenium framework development\' course in coursedetails page', function (callback) {
         // Write code here that turns the phrase above into concrete actions
         callback(null, 'pending');
       });

1 scenario (1 undefined)
4 steps (4 undefined)
0m00.000s

Answer №1

1) defineSupportCode is not compatible with Cucumber 4, instead use

import { Given, Then, When } from "cucumber";
in home.steps.ts.

import { Given, Then, When } from "cucumber";
import { HomePage } from '../pages/homePage';
import { expect } from 'chai';
import { CourseDetailsPage } from '../pages/courseDetails';

const homePage = new HomePage();
const courseDetails = new CourseDetailsPage();

Given(/^I navigate to the application$/, async() => {
  await homePage.OpenBrowser('http://localhost:4200');
});

When(/^I retrieve all the headings$/, async() => {
  await homePage.GetAllHeadings();
});

When(/^I select the '([^\"]*)' course$/, async(headingText) => {
  await homePage.ClickFirstHeading(headingText.toString());
});

Then(/^I should see the '([^\"]*)' course on the coursedetails page$/, async(course) => {
  // tslint:disable-next-line:no-unused-expression
  expect(coursedetails.GetCourseHeading).to.be.not.null;
});

2) In cucumber.conf.ts, it should be cucumberOpts instead of cucumberOptions, And the formatter: pretty has been removed in cucumber 4.

  cucumberOpts: {
    // necessary step definitions
    compiler: [],
    require : [ 'e2e/src/steps/*.steps.ts' ],
    strict  : true,
    dryRun  : false,
    tags    : []
  },

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

Angular2 faces a challenge with the selection issue

I have created a Plunker code for you to review. If you click the "toggle show" button twice, the selected item should be displayed. import {Component} from '@angular/core'; @Component({ selector: 'my-app', template: `<div *ngI ...

Tips for triggering a function each time a view is shown

I am currently developing an inappbrowser application that involves communication between the webview and the app. Below is a snippet of my code : import { Component } from '@angular/core'; import { NavController, Platform } from 'ionic-an ...

Modifying ngModel will result in the corresponding ngModel in another Angular2 browser being updated

I'm a novice when it comes to Angular 2 and I'm currently working on a project using npm to run the application. At the moment, I have it hosted on localhost with port 3000. The issue I'm facing in my project is that when I open the same ...

Leveraging parameters within a sequence of object properties

Within the realm of Angular, I am dealing with interfaces that take on a structure similar to this (please note that this code is not my own): export interface Vehicles { id: number; cars: Car; trucks: Truck; } Export interface Car { make: ...

The installation of Clarity through the command 'ng add @clr/angular' does not succeed

Following the guidance in 'Chapter 3: Building an Issue Tracking System using Reactive Forms' from Angular Projects: Discover Angular 12 with 10 innovative projects and cutting-edge technologies, 2nd Ed. by Aristeidis Bampakos. This chapter&apos ...

Troubleshooting an Angular application

Just diving into Angular and following along with the tutorial on https://angular.io/tutorial. However, I seem to be facing an issue in Chrome where the const HEROES is not available in my watch list. It keeps showing as "not available". What could be ca ...

Tips on utilizing the *ngIf directive to check for a condition other than equality

Can the != operator be used in the ngIf directive? I attempted to use it but it was unsuccessful: <div class="tranDetails tenPadding" *ngIf="transDtlsObj?.txnHistory!='null'"> ...

Sending an HTTP POST request from Angular 4 to Java SpringMVC results in the issue of POST parameters not

Currently, I am developing a REST API using Java Maven Spring Boot and Spring MVC. I have encountered an issue where Angular POST request parameters are not being recognized by SpringMVC's @RequestParam. Below is the Angular code snippet; saveAsSit ...

Troubleshooting the Hide/Show feature in React Native

As a newcomer to React Native development, I am attempting something simple. Within a React Class extending Component, I have 4 components <TouchableOpacity>. In the render function, my goal is to hide three of these components while pressing on one ...

What types should be used when passing a NgRx Action as a parameter to a function?

Within my Effects function, I have implemented the following code structure. I have included a few lines of code for the catchError block to ensure that: Any errors are handled by the state/store The errors are forwarded to the global error handler / Int ...

Sample: "Exploring the world of Realm with embedded objects in React

Can anyone share specific instances of utilizing realm with React Native and TypeScript while incorporating embedded objects? Typically, you can supply a partial object containing properties to be sent to realm for CRUD operations: realm.write(() => { ...

Jasmine reported that there were no specifications found in the Angular project written in TypeScript

I'm facing a frustrating issue with Karma and Jasmine in my Angular 9 project. Despite setting up the configuration files correctly, I keep getting a "No specs found" message when running ng test. I have tried various adjustments, including creating d ...

Including .d.ts files in TypeScript files

I am facing an issue with importing types from a .d.ts file that I created. The TypeScript compiler is giving an error related to the file path, displaying this message: File '.../lib/types/generated.d.ts' is not a module.ts(2306) The error occu ...

I am looking to transfer 'beforeEach' and 'afterEach' from the spec file to the global configuration file in WDIO [mocha, hook, wdio]

My E2E testing setup involves using the WebdriverIO library along with the mocha framework. During test execution, I want Mocha to automatically skip all subsequent checks in a test after encountering the first error, and proceed to the next test file. T ...

The object parameter is not being bound properly in the integration of Spring Boot and Angular

I am attempting to make an HTTP POST request to an API created in Spring Boot from an Angular app. The API expects an object as a parameter. When I execute the URL with Postman using form-data or urlencoded parameters, the request finishes successfully. Ho ...

"Troubleshooting the absence of exception messages between Angular and .NET Core integration

Is there a way to retrieve a JSON array with a message in the console that says "Your direct manager has no account for your area"? Currently, I am only receiving the message "Http failure response for https://localhost:44385/api/Option/Post: 500 Internal ...

Unlock the power of asynchronous dependencies on a global scale with Inversify

I'm looking to resolve an asynchronous dependency at the top level without relying on top-level awaits. Currently, I've implemented a temporary solution by defining an asynchronous function getService() in the controller file. However, this appr ...

Uncaught ReferenceError: jQuery is undefined" - Navigating the Angular and JavaScript Realm with

There is an Angular project that I am working on, and it utilizes the AvayaClientSDK consisting of three JavaScript files. While trying to import the AvayaClientSDK JS file into my component, an error message stating "jQuery is not defined" appeared. ...

Error encountered: The property 'localStorage' is not found on the 'Global' type

Calling all Typescript enthusiasts! I need help with this code snippet: import * as appSettings from 'application-settings'; try { // shim the 'localStorage' API with application settings module global.localStorage = { ...

What causes the behavior discrepancy in Typescript Union + Mapped Types when used with and without Generics?

I am a novice in the realm of generics. Although the code snippets for "w0" and "w1" appear to be identical, they actually have different purposes and types. Could someone shed light on why they are distinct from each other, and also provide guidance on a ...