Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

368
Views
Cypress Cucumber, how Get to data from page in one step and use it another scenario step

Below is mine scenario where in one scenario I'm getting data from page and saving it in a variable as alias. tHen I want to use same variable/data in other scenario to put in an input field.I'm using Alias but getting this error.

cy.wait() could not find a registered alias for: @Orderinfo. You have not aliased anything yet.

Even it alliased properly. Data stores in @Orderinfo but not accessable in other sceanrio step.

Then("Get Data from page", () => {
  cy.get(".os-order-number").invoke("text").then(($Oid) => {
    let Order = $Oid.text();
    let Order_id = Order.replace(/[^0-9]/g, "");
    cy.wrap(Order_id).as("Orderinfo");
  });
});


Given("Go to Login", () => {
  cy.visit("https://dev.simplifyshopping.com/register/");
});

When("Paste variable here", () => {
  cy.wait(2000);
  cy.wait("@Orderinfo")
  cy.get("@Orderinfo")).then((Orderinfo) => {
    console.log(Orderinfo);
    cy.get("#id_email").type(Orderinfo);
  });
});
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

So both, the use across several steps of the same scenario, as well as scenario overlapping are possible with Cypress using Cucumber Preprocessor.

1. Use of values across multiple steps of the same scenario

Referring to the example from the question, the Order_Id can be defined outside the steps and is thus accessible in the global scope from all steps. If I understood the code correctly, it would be something like this (probably unnecessary code commented out):

let Order_id;

Then("Get Data from page", () => {
  cy.get(".os-order-number").invoke("text").then(($Oid) => {
    let Order = $Oid.text();
    Order_id = Order.replace(/[^0-9]/g, "");
    // cy.wrap(Order_id).as("Orderinfo");
  });
});


Given("Go to Login", () => {
  cy.visit("https://dev.simplifyshopping.com/register/");
});

When("Paste variable here", () => {
  cy.wait(2000);
  // cy.wait("@Orderinfo")
  // cy.get("@Orderinfo")).then((Orderinfo) => {
  //  console.log(Orderinfo);
  //  cy.get("#id_email").type(Orderinfo);
  // });

  console.log(Order_id);
  cy.get("#id_email").type(Order_id);
});

2. Use of values across scenarios (hold state across tests)

To make certain values accessible across the execution of different scenarios, for example, a helper.js file can be created containing the following code:

export const stateStore = {};

Inside your step definition files, you can then import the stateStore and fill it with values as you like:

import { Given, When } from 'cypress-cucumber-preprocessor/steps';
import { stateStore } from '../helpers';

// step used in first scenario
Given('some value is made available in scenario 1', () => {
  stateStore.someValue = 'this is a value';
});

// step used in second scenario
When('this value can be used in another step of scneario 2', () => {
  console.log(`Print some value: ${stateStore.someValue}`);
});
about 4 years ago · Juan Pablo Isaza Report

0

It can be done using "alias" .as in cypress. Store variable .as("vaiableName") and then access it in required function as this.variableName. It could be like this.

Then("Get Data from page", function () {
    cy.get(".os-order-number").then($Oid => {
        const Order = $Oid.text()
        const Order_id = Order.replace(/[^0-9]/g, "")
        cy.log("inside Then function" + Order_id)
        cy.wrap(Order_id).as("wrapText")
    })
})

Given("Go to Login", function () {

    cy.log(this.wrapText)
})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!