0
var randomroom = ["BA783", "AP03A", "BC078", "HAW90"];
implicitFind(pkg.By.xpath("//input[@type='search']")).sendKeys("BA783");

I am new to coding and do not know how to make one random room from array go into the sendKeys, each time I run a test. The rooms will be typed on a search bar. This test will be executed on JMeter.

cruisepandey
  • 28,520
  • 6
  • 20
  • 38
Aerrop
  • 1

2 Answers2

0

We can use Math.Random to create a random number and then limit it to from 0 to randomRooms.length -1 ;

var randomRooms = ["BA783", "AP03A", "BC078", "HAW90"]; 
let randomRoom= randomRooms[Math.floor(Math.random() * (randomRooms .length))]
console.log(randomRoom)
vaira
  • 2,191
  • 1
  • 10
  • 15
0
function randomRooms(length) {
    var result           = [];
    var characters       = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    var charactersLength = characters.length;
    for ( var i = 0; i < length; i++ ) {
      result.push(characters.charAt(Math.floor(Math.random() * 
      charactersLength)));
     }
     return result.join('');
  }

  console.log(randomRooms(5));

This can be also used if you wanna try.

Md Atiqur
  • 456
  • 6
  • 10