user2478625
user2478625

Reputation: 131

Set session id in Locust object

I am sending http request (Post) using Locust object in python language. When I send multiple request using Locust object in one python file then it works but when I send each request in separate python file then it doesn't work as I get session expired message. Our requirement is to use separate python file for each request where I want to read session of previous request and want to assign that session id in next request. Somehow I am not able to do in below piece of code. There is option to set cookie but that doesn't set in request header.

subUrl='http://192.168.1.156:2016/login.aspx'
protocol='HTTP'
awaitingResponse = 1
response = self.client.post("http://192.168.1.156:2016/login.aspx", {"__EVENTTARGET":"","__EVENTARGUMENT":"","__LASTFOCUS":"","txtUserName":"Admin_Sample","txtPassword":"1","dllRole":"ProjectAdmin","cboProject":"Sample","Hdnlogin":"Please+enter+User+ID","HdnPassword":"Please+enter+Password","HdnProject":"Please+select+Project","HdnSubProject":"Please+select+Sub+Project","btnLogin":"Submit","__VIEWSTATE":VIEWSTATE1,"__VIEWSTATEGENERATOR":VIEWSTATEGENERATOR1},{"Cookie":""})

I will be thankful if you can help me to resolve my issue.

Upvotes: 1

Views: 2918

Answers (1)

Mesut GUNES
Mesut GUNES

Reputation: 7421

You should set data with your data and cookie should be sent inside the header you can set the user-agent if you need. See the example below:

response = self.client.post(
    "http://192.168.1.156:2016/login.aspx",
    headers={"Cookie": "", "User-Agent": "set_useragent"},
    data={
        "__EVENTTARGET": "",
        "__EVENTARGUMENT": "",
        "__LASTFOCUS": "",
        "txtUserName": "Admin_Sample",
        "txtPassword": "1",
        "dllRole": "ProjectAdmin",
        "cboProject": "Sample",
        "Hdnlogin": "Please enter User ID",
        "HdnPassword": "Please enter Password",
        "HdnProject": "Please select Project",
        "HdnSubProject": "Please select Sub Project",
        "btnLogin": "Submit",
        "__VIEWSTATE": VIEWSTATE1,
        "__VIEWSTATEGENERATOR": VIEWSTATEGENERATOR1,
    },
)

Upvotes: 1

Related Questions