What is the recommended approach for utilizing the value from a Given step in Cucumber Js?

After considering various possibilities, I came up with the following solution:

Given(
  `Step1`,
  async function() {
    const ObjectToUse = {
      A: 'a',
      B: 'b'
    }

    this.ObjectToUse = ObjectToUse
  }
)

Then(`Step2`, async function() {
  ObjectToUse = this.ObjectToUse
})

Despite my efforts, I am uncertain whether this is the most efficient practice as it might become redundant when used multiple times.

Do you have any suggestions for a more streamlined approach? My goal is to simply utilize the values obtained from the Given step.

Answer №1

Optimally, saving information in a top-tier database for future use is recommended when using cucumber

Answer №2

The most effective method for transferring data between steps in a scenario is by utilizing the scenario context or "world" object known as this. See below for an example:

Feature File

Feature: Transferring data between steps

  Scenario: Data transfer
    Given I input the value as "example"
    Then the output should be "example"

Step Definitions

const { Given, Then } = require('cucumber');
const assert = require('assert');

Given('I input the value as {string}', function (value) {
    this.value = value;
});

Then('the output should be {string}', function (value) {
    assert.ok(this.value === value);
});

Sample Online Demonstration:

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

Button Click Tracking Using Google Analytics for In-Page Searches

Is there a way to track Google Analytics In-Page search using the search code "KEYWORDS site:MYDOMAIN.com" without users immediately jumping to Google upon hitting Enter? I have heard about using Google Analytics hitCallback but I'm not sure how to i ...

Need help triggering an alert once your AJAX post is successful? Here's how!

Within my Node application, I have implemented both get and post requests. The get request is responsible for rendering the page, while the post request inserts data into a MySQL database. Although the data is inserted correctly, the alert message fades aw ...

Guide to utilizing the (page-source) function with clj-webdriver

I read through the description of the (page-source) function, but I'm still struggling to grasp it. Would someone be able to provide me with an example to help clarify things? Many thanks ...

Mobile Size Setting

Could someone please explain to me why when I test this code on Google Chrome using the mobile emulator for Galaxy S3, it displays the correct size (640x360), but when I try to load it on my actual Galaxy S5 or any other device, the size is different from ...

utilize jQuery to load webpage with an HTML dropdown element

Querying the Campaigns: // Getting the campaigns $campaigns = $wpdb->get_results( "SELECT * FROM tbl_campaigns ORDER BY campaignID DESC", OBJECT_K ); // Displaying the Cam ...

Using a function as a parameter in Typescript: Anticipated no arguments, received 1.ts

I'm encountering an issue when trying to pass the doSomething function into performAction. The error message I'm receiving is Expected 0 arguments, but got 1 interface SomeInterface { name: string, id: string } function doSomethingFunction( ...

Is it possible to utilize AngularJS' ng-view and routing alongside jade?

Currently, I am diving into the world of the MEAN stack. I noticed that Express utilizes jade by default, but I decided to experiment with it even though I can easily use html instead. When attempting to route with Angular, like so: ... body div(ng-view ...

Disabling the shadow when setting the face color in Three.js

When creating geometric objects in my project, I am randomly setting colors on the faces: // Material used to create the mesh var material = new THREE.MeshLambertMaterial({ color: 0xffffff, ambient: 0xffffff, vertexColors: THREE.FaceColors}) function ad ...

Struggling to retrieve a date using a Firebase cloud function?

My goal is to retrieve a date from a firebase function: import * as functions from 'firebase-functions'; const date = functions.https.onCall(() => { return { date: new Date(), iso: new Date().toISOString() }; }); export default d ...

Merge two separate Vue applications into one cohesive application

I have developed two separate Vue apps independently from each other. User Interface Admin Interface Each app has its own routes, store, configs, etc. I came across this helpful comment here which discusses treating each app as a component within a mai ...

Encountered issue while jasmine mocking angular $http - Error: describe function does not support a done parameter

I am currently working with an angular factory that looks like this: .factory('widgetFactory', ['$http', function($http){ function getWidgets(){ return $http.get('http://example.com/api/widgets/') .then(function(re ...

Deleting object properties in JavaScript is not possible

obj = {a: []} I need to remove the element obj.a. The following code does the job: if(!obj.a.length) delete obj.a // it works However, the below code does not achieve the desired result: function _delete(o) { if(!o.length) delete o } _d ...

Disabling a specific dropdown within ng-repeat in AngularJS

I've encountered a problem with the ng-repeat in my HTML code: <div ng-repeat="a in items"> <div> <span>{{a.name}}</span> </div> <div> <select ng-model="a.c_id" ng-options="d.c_id as d.description ...

The error message "TypeError: Cannot read properties of undefined (reading 'prototype')" is encountered in Next.js 13 when trying to access the prototype of an

I tried to integrate the downshift library into my project. However, when I attempted to use a basic example from the GitHub repository here, I encountered an error. Current versions: Next.js: 13.2.4 React: 18.2.0 Upon further investigation, it seems lik ...

Simple steps to activate and monitor global events using EaselJS

Can EventDispatcher be used to create a global event that any object in the hierarchy can listen and respond to? What is the best approach to implement this in EaselJS, and is it advisable from a general perspective? ...

Transforming timestamps to month day, year format and back again without the use of any NPM packages

I have developed a microservice that converts Unix timestamps to a format like Dec 01, 2017 and vice versa. The microservice is deployed at this link: timestamp I am wondering if there is a better way to achieve this without using third-party NPM modules. ...

Can you please explain the differences between "resolved" and "rejected" in a deferred object within jQuery?

Recently, I inquired about a refreshing page solution if an internet connection is available on Stack Overflow. The user @Fabrizio Calderan provided an elegant approach utilizing deferred object implementation: setInterval(function() { $.when( ...

"Troubleshooting the issue of Delete Requests failing to persist in Node.js

Whenever I send a delete request to my node.js server, it can only delete one item from my JSON file until the server restarts. If I attempt to make a second delete request, it successfully deletes the item but also reverts the deletion of the last item. ...

Issue with utilizing Vuejs variable in Google Maps Matrix API function

Having trouble accessing a Vue.js variable in a function using the Google Maps Matrix API. I am trying to use the Google Distance Matrix API to calculate the distance between two locations. I have declared a variable globally and changed it within a functi ...

Leverage the `dispatch` hook within a useEffect function

When it comes to triggering an action upon the React component unmounting, I faced a challenge due to hooks not allowing the use of componentWillUnmount. In order to address this, I turned to the useEffect hook: const dispatch = useDispatch(); useEffect(( ...