赛普拉斯-打字稿-如何使夹具变量全局化? [英] Cypress - Typescript - How can i make my fixture variables global?
本文介绍了赛普拉斯-打字稿-如何使夹具变量全局化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于Cypress/Typescript等来说,这是一个新手,我想从我的装置中获取一个值,并使它可用于执行搜索并确认返回的标题正确"测试.但是我似乎无法从测试中访问变量,感谢任何帮助:
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:
这是我的灯具中的值:
{
"manufacturer": "Dyson",
"product": "9kJ Hand Dryer"
}
这是我的代码,该代码从固定装置创建别名并尝试访问变量,但出现以下错误:找不到名称"manuTerm"
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);
});
});
推荐答案
此
为我工作.但是,您是否尝试创建高var?
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);
});
});
这篇关于赛普拉斯-打字稿-如何使夹具变量全局化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文