jeudi 18 février 2016

How to select a valid random value from drop down using NightwatchJS?

I am trying to automate some UI testing with nightwatch.js, I need to select a random value from the drop down which looks like the code below.

<select class="form-control" name="drop_ddl" id="drop_ddl">
<option value=""></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="11">11</option>
<option value="12">12</option>
</select>

As of now I am using an approach where I have no reliability in case the random number I have selected doesn't exist in the drop down option values.

  var drop_ddl=Math.floor((Math.random() * 8) + 1);
  return this.client.click("#drop_ddl option[value='"+drop_ddl+"']");

In case the random number is say 6 which doesn't appear in the list it will fail the further tests.

Is there a way we can read the values to an array and then select randomly out of these available values only ?

Aucun commentaire:

Enregistrer un commentaire