0

Bad title, I know, but it's hard to explain in few words.

I'm automating on nightwatch and ran into something that has me stumped as I'm used to coding on JS only for automation. Normally, it's easy to verify that an element is present, or that an element is not. But for this, I have an html element that shows that results of a search and I need to verify that the results contain only elements

So, I need to make sure that all result-item on the entity-results div only have results with hint-val-fragment match equal to -1000000.0 and hint-prop equal to cpuLimit:, in this example.

<div class="results" style="">
   <!----> 
   <div>
      <div class="results-set-title">Results</div>
      <!----> 
      <div class="entity-results">
         <div class="result-item">
            <div class="result-item-label">
               <div class="result-item-name">Resources</div>
               <div class="result-item-source"><span>source:</span> <span>cz0</span></div>
            </div>
            <div class="result-item-hint">
               <div class="hint-prop">cpuLimit:</div>
               <div class="hint-val">
                  <div class="hint-val-fragment">
                  </div>
                  <div class="hint-val-fragment match">
                     -1000000.0
                  </div>
                  <div class="hint-val-fragment">
                  </div>
               </div>
            </div>
         </div>
         <div class="result-item">
            <div class="result-item-label">
               <div class="result-item-name">Resources</div>
               <div class="result-item-source"><span>source:</span> <span>cz0</span></div>
            </div>
            <div class="result-item-hint">
               <div class="hint-prop">cpuLimit:</div>
               <div class="hint-val">
                  <div class="hint-val-fragment">
                  </div>
                  <div class="hint-val-fragment match">
                     -1000000.0
                  </div>
                  <div class="hint-val-fragment">
                  </div>
               </div>
            </div>
         </div>
         <div class="result-item">
            <div class="result-item-label">
               <div class="result-item-name">Resources</div>
               <div class="result-item-source"><span>source:</span> <span>cz0</span></div>
            </div>
            <div class="result-item-hint">
               <div class="hint-prop">cpuLimit:</div>
               <div class="hint-val">
                  <div class="hint-val-fragment">
                  </div>
                  <div class="hint-val-fragment match">
                     -1000000.0
                  </div>
                  <div class="hint-val-fragment">
                  </div>
               </div>
            </div>
         </div>
         <div class="result-item">
            <div class="result-item-label">
               <div class="result-item-name">Resources</div>
               <div class="result-item-source"><span>source:</span> <span>cz0</span></div>
            </div>
            <div class="result-item-hint">
               <div class="hint-prop">cpuLimit:</div>
               <div class="hint-val">
                  <div class="hint-val-fragment">
                  </div>
                  <div class="hint-val-fragment match">
                     -1000000.0
                  </div>
                  <div class="hint-val-fragment">
                  </div>
               </div>
            </div>
         </div>
      </div>
   </div>
</div>
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
  • How do you want to make sure that _...all result-item on the entity-results div only have results with hint-val-fragment match equal to -1000000.0 and hint-prop equal to cpuLimit:..._? Code trials? – undetected Selenium Sep 15 '19 at 14:50

1 Answers1

0

Below I've defined isValid, which is applied to every element in an array passed to allValid. This function can be applied after there's been an update on the DOM and you need to recheck the elements:

const isValid = elem => {
    const val = elem.getElementsByClassName('hint-val-fragment match')[0].innerHTML.trim()
    const hint = elem.getElementsByClassName('hint-prop')[0].innerHTML.trim()
    return (
        val === '-1000000.0'
        && hint === 'cpuLimit:'
    )
}
const allValid = arr => arr.every(isValid)


const parent = document.getElementsByClassName('entity-results')[0]
const children = Array.from(parent.children)


const allAreValid = allValid(children)
Jacob Penney
  • 725
  • 4
  • 9