Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

373
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda