typescript - 如何访问 cypress/Typescript 中 cy.get() 中定义的值?
问题描述
我需要访问 getLength 函数的值。它返回未定义的值。如何访问此处的值?
我的代码是:
const verifyValue = () => {
const selector = 'nz-option-container nz-option-item';
const myActualLength = getLength(selector);
console.log('I need to access this value :' + myActualLength);
}
const getLength = (selector: string) => {
let length;
cy.get(selector).then((listItem) => {
length = listItem.length;
})
return length;
}
解决方案
This is how I am able to acces the value:
const getLength = (selector: string) => {
let length;
cy.get(selector).then((listItem) => {
length = listItem.length;
})
return cy.wrap(length);
}
getLength(selector).then(value => {
console.log('I need to access this value :' + value );
})
推荐阅读
- angular - 在角度 2 中为给定 url 打开一个新标签
- apache-kafka - 如何从具有小数类型列的主题在 ksql 中创建流
- laravel - Laravel 自动将“on update CURRENT_TIMESTAMP”添加到某些特定列
- angular - 基于ionic 4中的国家选择框生成依赖状态选择框
- reactjs - setState 回调上的这个值。一个小小的困惑
- python-3.x - 为什么“if”函数总是输出相同的结果
- angular - 如何在 Angular 8 网站中添加 Google Adsense?
- perl - 将第一个文件的第一列和第二列与第二个文件的第一列匹配
- c# - 在 NUnit 测试中将数组传递给参数
- html - 实现返回顶部按钮时页脚消失