Hi there, I’m new to testing/automation so I wanted to ask for help on something.
When it comes to Puppeteer: Is there a way to dynamically change the data the headless client would enter into the website input depending on some kind of unique ID? What I mean is: the first headless client I open should have an UserIndex/ID of 1. Based on that, it will enter the username “botone”. Then the second headless client I open would have an UserIndex/ID of 2 and will enter the username “bottwo”, so on up until 500 IDs/clients. How can I do that?
There’s a puppeteer repo that lets you run multiple instances of the same headless client with one simple command, but I’m not sure how to give each one of them a different ID (like one, two, three, etc) that I could access inside the code
Thanks in advance!
Any particular reason you need a browser for this?
It seems you want to perform a regular performance testing of your API (HTTP?)…
As João mentioned, this is an unusual scenario, so it could help if you share more about what you are trying to accomplish (is it for performance testing, is it a functional test for an edge-case or a very specific use case, etc.). Depending on the answer you may be able to avoid the problem altogether and use a different approach or tool.
Ignoring that and noting that I’m not familiar with Puppeteer or Node.js, one solution I can think of is creating a class to hold this information. Each object should have a headless client plus all the information you need for it. Then you can iterate over all these objects in a list. Maybe someone that knows more about js and node can help confirm if this is a good idea or not.
You could easily give out an identifier using node’s
process.pid. Each instance of puppeteer running an headless session will have a different process id (pid). Here’s an interactive session to demonstrate this in the node console.
Welcome to Node.js v16.14.2.