在WebdriverIO上,我可以断言是否使用以下命令选中了同一复选框:
return $(selector).isSelected()
<form action="/cases/enableSubcases" id="CompanyInfoSettingsForm" method="post" accept-charset="utf-8">
<div style="display:none;"><input type="hidden" name="_method" value="POST"><input type="hidden" name="data[_Token][key]" value="8f8c3c04cd70aa8207bd045382f4cc5a10d54ff6" id="Token436554541"></div>
<div class="col-xs-6 standard-checkbox"><input type="hidden" name="data[CompanyInfo][subcases_enabled]" id="CompanyInfoSubcasesEnabled_" value="0"><input type="checkbox" name="data[CompanyInfo][subcases_enabled]" value="1" id="CompanyInfoSubcasesEnabled"><label for="CompanyInfoSubcasesEnabled">Enable subcases</label></div>
<input type="submit" value="Add" data-target="" data-ajax-events="{}" class="hidden btn btn-blue btn-in-form save ajax ajax-submit" id="submitSubcasesActivate">
<div style="display:none;"><input type="hidden" name="data[_Token][fields]" value="a16a56244433cb631f47cf444d68fee6f6593663%3A" id="TokenFields1306079178"><input type="hidden" name="data[_Token][unlocked]" value="" id="TokenUnlocked441950973"></div>
</form>
在这里,您可以查看如果我检查以下代码会发生什么情况:https://photos.app.goo.gl/XnXgCufNxPF2YqoZ6
我正在尝试的是:
async areSubcasesEnabled() {
await t
.navigateTo(urlFor('?/cases/settings'))
if(this.elements.subcases.checked)
return true
else
return false
}
,它总是返回true
。
答案 0 :(得分:4)
Selector
返回一个Promise
,它解析为包含DomNodeSnaphot
属性-https://devexpress.github.io/testcafe/documentation/test-api/selecting-page-elements/dom-node-state.html#members-specific-to-element-nodes的checked
。
因此,您需要添加await
关键字以获得Promise值。
async areSubcasesEnabled() {
await t
.navigateTo(urlFor('?/cases/settings'))
return await this.elements.subcases.checked;
}