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

151
Visualizações
Unable to share aliases across steps in cypress

I am having an issue trying to share an alias between two steps in cypress. Basically what I am trying to do is in the first then step, I get the value and pass it in as a variable storedOddsValue. In the second then step, when I try to get that alias value and complete the step, it fails because I beleive it's coming back with undefined.

I know this because instead of using:

let storedOddsValue = oddslib.from("fractional", cy.get("@storedOddsValue"));

If I replace the alias with the hardcoded value like so:

let storedOddsValue = oddslib.from("fractional", "13/5");

The whole code below executes fine and the assertion passes. So my question is what am I doing wrong, why is it not getting the alias?

Then ("The prices are formatted in fractions by default", () => {
    priceFormatElements.priceFormatDropdown().should('have.value', 'Fraction');
    const oddsValue = oddsSelectionElements.oddsButton().first().invoke("text");

    oddsValue.then((oddsValue) => {
        expect(oddsValue.trim()).contains("/");
        oddsValue.trim();
    }).as("storedOddsValue")
})

Then ("The prices are formatted in {string}", (priceFormat) => {
    let expectedOddsValue;
    let currentOddsValue = oddsSelectionElements.oddsButton().first().invoke("text");
    //let storedOddsValue = oddslib.from("fractional", "13/5");
    let storedOddsValue = oddslib.from("fractional", cy.get("@storedOddsValue"));
    
    switch (priceFormat) {
        case "Fractional":
          expectedOddsValue = storedOddsValue.to("fractional");
          break;
        case "Decimal":
          expectedOddsValue = storedOddsValue.to("decimal", {precision: 2});
          break;
        case "American":
          expectedOddsValue = "+" + storedOddsValue.to("moneyline");  
          break;
        default:
          throw new Error('unknown price format: ' + priceFormat);
    }
    
    currentOddsValue.then((oddsValue) => {
        expect(oddsValue.trim()).equals(expectedOddsValue);
    });
})
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Not sure what oddslib.from does, but to use it with an alias you need to nest in this way

Then (... () => {
  let expectedOddsValue
  let currentOddsValue = oddsSelectionElements.oddsButton().first().invoke("text")

  cy.get("@storedOddsValue").then(aliasValue => {

    let storedOddsValue = oddslib.from("fractional", aliasValue)

    switch (priceFormat) {
      ...
    }
    currentOddsValue.then((oddsValue) => {
      expect(oddsValue.trim()).equals(expectedOddsValue);
    });

  })   // end of cy.get("@storedOddsValue")
})

Because cy.get("@storedOddsValue") is asynchronous, and the switch() runs before it gives it's value.

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