How to find max and min element in array when using in WebDriver sampler -selenium javascript



  • I used WebDriver sampler and wrote selenium Javascript-. I created an array and saved those elements. Now I want to know which element is maxed and minimum. so how is it found, is there any built-in function ? or any other logic?



  • What do you mean by "array"?

    If this is just a "normal" https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array - it has built-in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort so if the array contains just simple numeric values you can just call this function and the smallest element will have index 0 and the largest element will have the index of array size - 1

    enter image description here

    For more complex structures we need to see how does the array looks like as we're not telepathic enough to guess what do you have inside the array and what is the expected outcome.

    Be aware that JMeter is a pure Java application hence you have access to full power of the https://docs.oracle.com/javase/8/docs/api/ in case of more complex transformations/calculations are required

    References:

    • https://docs.oracle.com/javase/10/scripting/using-java-scripts.htm#JSJSG114
    • https://www.blazemeter.com/blog/webdriver-sampler-your-top-ten-questions-answered

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2