0

I have a simple use case which i am trying to achieve. I basically want to pass a new random number in my URL with every request. It seems like its passing the same random number every time though.

class UserBehavior(SequentialTaskSet):


    @task
    def GETCall(self):

        seedValue = random.randrange(sys.maxsize)
        random.seed(seedValue)
        print("Seed was:", seedValue)
        num = random.randint(10, 500)
        print("Random Number", num)

       
with self.client.get("http://google.com?/waitfor=" + num,name="GET Request",headers=headers,catch_response=True) as response1:
if response1.status_code == 200:
                response1.success()
            else:
                response1.failure("Invalid code")
Contraboy
  • 99
  • 1
  • 1
  • 10

1 Answers1

1

delete these lines:

seedValue = random.randrange(sys.maxsize)
random.seed(seedValue)
print("Seed was:", seedValue)

(or if you must have them for some reason, only call then once, outside your task, maybe at top level)

Cyberwiz
  • 11,027
  • 3
  • 20
  • 40
  • Thanks for your reply. I tried that but i keep getting this error can only concatenate str (not "int") to str (this is when i try to append num variable to the url) – Contraboy Aug 31 '20 at 19:11
  • 1
    try replacing num = random.randint(10, 500) with num = str(random.randint(10, 500)) to make it a string – Cyberwiz Aug 31 '20 at 19:19
  • Thanks that fixed the issue! Seperate issue but is this the right way to check for multiple conditions if ((resp2.status_code == 200) and (resp2.text == "dummy123")): resp2.success() – Contraboy Aug 31 '20 at 19:24
  • 1
    you’d need to add else: resp2.failure(”oopsies”) to make it fail (otherwise any non-error response code would still be a success) – Cyberwiz Aug 31 '20 at 19:32