问题
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