Since “postcode” is an array, you can generate a random index as shown below:
var s = 55;
var random = function() {
s = Math.sin(s) * 10000;
return s - Math.floor(s);
};
//...
var postIndex = Math.floor(random() * postcode.length);
var currentPost = postcode[postIndex];
For example:
import { Selector } from 'testcafe';
fixture `Getting Started`
.page `http://devexpress.github.io/testcafe/example`;
const postcode = [
"b28 8ND",
"b49 6BD",
"b28 0ST",
"b31 4SU",
"B92 9AH",
];
var s = 55
var random = function() {
s = Math.sin(s) * 10000;
return s - Math.floor(s);
};
test('My first test', async t => {
var postIndex = Math.floor(random() * postcode.length);
var currentPost = postcode[postIndex];
console.log(currentPost)
await t
.typeText('#developer-name', currentPost);
});
2
solved How do I use an array I’ve created within my Test file