jasmine - 在量角器茉莉花中得到“预期未定义为假”
问题描述
我正在验证是否不能显示其中一个元素。
代码如下:
规格文件:
expect(usersPage.isCreateTabDisplayed()).toBe(false);
方法的 usersPage 定义:
this.isCreateTabDisplayed = function()
{
waitUtil.isElementVisible(usersTab,repo.configData.configuration.longWaitTime);
createUserTab.isPresent()
.then( function(displayed) {
console.log("create user tab : "+ displayed);
return displayed;
});
}
元素定义如下:
<li ng-class="{active: (subview == 'add')}" ng-show="iSU || dp.ua" class="ng-hide"><a href="#/setup/users/all/add/" class="ng-binding">Create user</a></li>
当我运行代码时,我收到“预期未定义为假”错误消息。
控制台日志显示为“创建用户选项卡:false”,但为什么我会收到错误消息以及如何处理它。
解决方案
你需要有then
序列和return
.
this.isCreateTabDisplayed = function()
{
return waitUtil.isElementVisible(usersTab,repo.configData.configuration.longWaitTime).then(() => {
return createUserTab.isPresent().then( function(displayed) { // or you can just "return createUserTab.isPresent()"
console.log("create user tab : "+ displayed);
return displayed;
});
});
}
另外,您的问题中有量角器标签,那么为什么不使用它呢?您的代码应如下所示:
expect(usersPage.getCreateTab().isDisplayed()).toBe(false);
getCreateTab(): ElementFinder {
browser.wait(ExpectedConditions.visibilityOf(usersTab), repo.configData.configuration.longWaitTime).then(() => {
return createUserTab; // or put there locator to "element" (find) createUserTab
});
}
如果我错过了什么,请在评论中指出我。
推荐阅读
- c# - 从面板中删除子项,绑定到 ItemsSource
- python - 结构列在 pyspark 数据框中为 NONE
- java - Java:我的 .jar 文件已创建,但找不到主类?
- ios - 使用 sender.tag 更改 UIView 颜色
- php - 插入中的PHP数组到字符串转换
- postgresql - Sequelize Postgres - 处理并发请求
- url - Excel从jpg url获取尺寸和文件大小
- qt - 在 SwipeView QML 上动态添加 QML 页面
- amp-html - 如何使用 amp-bind 将从我的 web 服务返回的 HTML 放入一个 div 中?
- android - Android P 中的 BiometricDialog 导致内存泄漏