How can I get user id(s) of all users hitting my web page?
This depends on how your web server is set up. What exactly is a user ID in your application's context?
I'll proceed with the assumption that you have some mechanism by which you can generate a user ID.
You could have your client side get the user ID(s) (using Javascript for example) and then pass each ID along to the server in a HTTP request where you could custom define a header to contain your user ID for that request.
For example, if you're using Flask/Python to handle all the business logic of your web application, then you might have some code like:
from flask import Flask, request
app = Flask(__name__)
@app.route("/articles")
def do_something_with_user_id():
do_something(request.headers.get("user-id"))
if __name__ == "__main__":
app.run()
How to pass user information (say user id) while creating new
articles?
You could change your POST request line in your Locust script to something like:
with self.client.request('post',"/articles",headers=header_with_user_id,data={"article[title]":"computer","article[content]":"pc"},catch_response=True) as response:
where header_with_user_id
could be defined as follows:
header_with_user_id = { "user-id": <some user ID>}
where <some user ID>
would be a stringified version of whatever your mechanism to obtain the user ID gets you.