I found a weird bug which seems to be related to Collection Variables. I believe this to be the case since it only appeared when I moved away from setting the request parameters as environment variables (as this doesn’t make much sense in Test Automation).
I kept running my same old script, but out of nowhere, I started seeing NaN in my request. This was weird. The parameter was being selected from an array using array.shift(), and I determined there was nothing wrong with the code after I logged each step. Simply, during the request the collection variable was being set to NaN. Weird behavior, and very frustrating as the code is all correct, so debugging is hard.
['string','string',123,**'string getting set to NaN'**]
I began playing around with the contents of the array, and this is where it gets really weird. It was always my fourth variable, a string, in the array that was being set to NaN. The third element was a number. So I added another string after the number, ‘testing’.
['string','string',123,**'testing'**,'string getting set to NaN']
Again I saw a NaN. However, the original string was now being displayed. So I removed ‘testing’ and added another number after the culprit.
['string','string',123,**456**,'string getting set to NaN']
Now both numbers were being displayed, but now the original string was back to NaN. So I removed the string.
Now the first element in the array, also a string, was being set to NaN. So I removed the numbers completely.
And all of the issues disappeared. It cycled through the array as expected and the collection variable was never set to null.
TL;DR: Collection Variables sets the first string after a number in an array to NaN during a request when using array.shift() to get and set the variable; even though the response of array.shift() is not NaN. Pls fix or advise on what to do.
Request Looks like:
Pre-request Script w/ Buggy Behavior:
var usernames = ['Test', 123, 'testing']; var username = usernames.shift(); console.log(username); pm.collectionVariables.set("username", username) pm.collectionVariables.set("usernames", usernames)
Pre-request Script w/o Buggy Behavior:
var usernames = ['Test', '123', 'testing']; var username = usernames.shift(); console.log(username); pm.collectionVariables.set("username", username) pm.collectionVariables.set("usernames", usernames)