0

I am working with protractor and BDD. I want to check that the text that is present in a body of a website is the correct one. I have three dropdown boxes and the text depends on these 3 options.

I am going to read the text from the website using getText() and I want it to compare with the expected text. This expected text depends on the value of the three dropdown boxes and the section of the website, so I need to create a 4D array.

How can I declare the array and assign the expected text?

I need something like this:

template[0][2][1][0]='this is the expected text';
Liam
  • 27,717
  • 28
  • 128
  • 190
Alfredo Bazo Lopez
  • 323
  • 1
  • 4
  • 12

2 Answers2

1

you can write the custom code which can provide you the nested Array list.. example are as below :

function nestedMatrix(n) {
  var total = 0, levels = n;
  function nestedMatrix(n) {
    var matrix = [];
    for (var i = 0; i < levels; i++) {
      matrix.push(n ? nestedMatrix(n - 1) : ++total);
    }
    return matrix;
  }
  return nestedMatrix(n)[0];
}

console.log(nestedMatrix(3));
SantoshK
  • 1,789
  • 16
  • 24
0

I think it will be easier if you construct a JSON and pass the values you get from the dropdowns and get the expected text. You can check out the sample below:

var array;
for(var i=0; i<firstDimention.lentgh; i++){
    if (i == 0)
        array = {};
    for(var j=0; j<secondDimention.length; j++){
        // Initializing 2D Array
        if (j == 0)
            array[firstDimension[i]] = {};
        for(var k=0; k<thirdDimension.length; k++){
            // Initializing 3D Array
            if (k == 0)
                array[firstDimension[i]][secondDimension[j]] = {}
            .....
        }
    }
}

You can use the same code to initialize an array also if you prefer that.

koushikmln
  • 648
  • 6
  • 23