Cypress - Typescript - How can i make my fixture variables global?

三世轮回 提交于 2021-02-10 17:49:22

问题


Fairly new to Cypress/Typescript etc, i want to grab a value from my fixture and make it usable for the 'perform search and verify returned header is correct' test. However i cant seem to access the variable from within my test, any help appreciated:

Here's the values in my fixture:

{
  "manufacturer": "Dyson",
  "product": "9kJ Hand Dryer"

}

Here's my code that creates an alias from the fixture and attempts to access the variable, but im getting the following error: Cannot find name 'manuTerm'

describe('scenario-one', () => {
beforeEach(() => {// I need these variables availabe to multiple tests
cy.fixture('manufacturer').as('manuTerm');
});

it ('perform search and verify returned header is correct', () => {
    const lp = new sourceElements();
    lp.enterSearchTerm(manuTerm.manufacturer);
    lp.verifySearchResult(manuTerm.manufacturer);
});
});

Current errors

manuTerm: any


回答1:


this working for me. But have you try create a high var?

describe('scenario-one', () => {
  let manu: any;
  before(() => {
    cy.fixture('manufacturer').then((val: any) => {
      manu = val;
    });
  });

  it('perform search and verify returned header is correct', () => {
    const lp = new sourceElements();
    lp.enterSearchTerm(manu.manufacturer);
    lp.verifySearchResult(manu.manufacturer);
  });
});


来源:https://stackoverflow.com/questions/63301256/cypress-typescript-how-can-i-make-my-fixture-variables-global

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!