Reputation: 13
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);
});
});
Upvotes: 1
Views: 2386
Reputation: 84
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);
});
});
Upvotes: 0
Reputation: 18634
I think this should work.
describe('scenario-one', function() {
beforeEach(() => { // I need these variables availabe to multiple tests
cy.fixture('manufacturer').then(function(manuTerm:any) {
this.manuTerm = manuTerm
})
})
it('perform search and verify returned header is correct', () => {
const lp = new sourceElements();
lp.enterSearchTerm(this.manuTerm.manufacturer);
lp.verifySearchResult(this.manuTerm.manufacturer);
})
})
Upvotes: 0