Getting session x-Authorization token using Jmeter webdriver sampler

15 views
Skip to first unread message

sirish s

unread,
Sep 8, 2021, 10:48:47 AM9/8/21
to jmeter-plugins
Hi,

I need some suggestion to get session x-autorizations tokens after login to the web application using Jmeter Webdriver sampler plugin.

Thanks,
Sirish

sirish s

unread,
Sep 8, 2021, 10:51:16 AM9/8/21
to jmeter-plugins
I tried with below codes using script Language: javascript

var cookie=WDS.browser.manage().getCookieNamed("sessionToken").toString();
WDS.log.info('session Token: ',cookie);

var vars = org.apache.jmeter.threads.JMeterContextService.getContext().getVariables()
vars.put('sessionToken',cookie.split('=')[1].split(';')[0]) 

DT

unread,
Sep 9, 2021, 2:13:26 AM9/9/21
to jmeter-plugins
I think there is an easier/better way of doing this


So you could amend your code to look like:

var cookie = WDS.browser.manage().getCookieNamed("sessionToken")
WDS.vars.put('sessionToken', cookie.getValue())

sirish s

unread,
Sep 9, 2021, 12:42:51 PM9/9/21
to jmeter-...@googlegroups.com
I tried amending the code change suggested above, but getting error as show below

image.png

--
You received this message because you are subscribed to the Google Groups "jmeter-plugins" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jmeter-plugin...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jmeter-plugins/dea1dccd-cab2-4c34-a2c4-a31c601b27d8n%40googlegroups.com.

DT

unread,
Sep 10, 2021, 2:50:52 AM9/10/21
to jmeter-plugins
It means that there is no sessionToken cookie in the browser, you can print all the cookies to jmeter.log file by using the following code snippet:

var cookies = WDS.browser.manage().getCookies().toArray()
for (var i =0; i < cookies.length; i++) {
    WDS.log.info('Cookie # ' + i + ': ' + cookies[i].getName() + '=' + cookies[i].getValue())
}

Untitled.png

My expectation is that you should have the sessionToken cookie set once you successfully log in and looking into your listener output it seems that the previous sampler has failed so I would rather look at your login logic, most probably when you fix it the code for extracting the cookie value will start working as well. One of examples is Selenium 101: How To Automate Your Login Process

sirish s

unread,
Sep 10, 2021, 10:34:00 AM9/10/21
to jmeter-...@googlegroups.com
Yes, I see there is nothing coming in the cookie. I was trying to get the sessionToken, which are stored in sessionsStorage from the browser after login to the application. Any suggestions?

image.png

Thanks,
Sirish

Reply all
Reply to author
Forward
0 new messages