SimoneB
SimoneB

Reputation: 178

Checking if a checkbox is checked returns always true

On WebdriverIO I was able to assert if the same checkbox was checked using:

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>

Here you can see what happens if I check the code: https://photos.app.goo.gl/XnXgCufNxPF2YqoZ6

What I am trying is:

async areSubcasesEnabled() {
  await t
    .navigateTo(urlFor('?/cases/settings'))

  if(this.elements.subcases.checked)
    return true
  else 
    return false
}

and it always returns true.

Upvotes: 2

Views: 1049

Answers (1)

mlosev
mlosev

Reputation: 5227

Selector return a Promise that resolves to DomNodeSnaphot that contains the checked property - https://devexpress.github.io/testcafe/documentation/test-api/selecting-page-elements/dom-node-state.html#members-specific-to-element-nodes.

So, you need to add the await keyword to get the Promise value.

async areSubcasesEnabled() {
  await t
    .navigateTo(urlFor('?/cases/settings'))

  return await this.elements.subcases.checked;
}

Upvotes: 4

Related Questions