Using localStorage in JMeter

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Using localStorage in JMeter

Jean-Sebastien Vachon
Hi All,

I am trying to build a test suite to test the performance of one of our
system and I need to provide some information to each thread so that the
following code will work...

  <script type="application/javascript">
        var getName = function() {
            var name;
            try {
                name = window.localStorage.getItem("user-name");
            } catch(error) {
                console.log(error);
            }
            if(!name) {
                name = window.prompt("What's your name, please ?", "Rachel
Smith");
            ...


I tried setting a cookie using the CookieManager but I can not get it to
pass a predefined value.

Is there a way to put something in the localStorage so that the javascript
code will see it and proceed?

Thanks
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using localStorage in JMeter

support@ubikloadpack.com
Hello,
JMeter is not a browser, so it does not interpret Javascript.

It works on protocol level. You javascript here will end up sending a
request to the server, that's where the information will be available.
If you need to provide this to the request then you will use a CSV Data Set
(and a CSV file containing the names) and variables to send it:
- http://jmeter.apache.org/usermanual/functions.html#functions
-
http://jmeter.apache.org/usermanual/component_reference.html#CSV_Data_Set_Config

If you need to extract it from a response, you will use Extractors (CSS/
JQuery extractor, JSON-Path, XPath or regex):
-
http://jmeter.apache.org/usermanual/component_reference.html#postprocessors


Another option if you don't have much load to inject is to use WebDriver
and a plugin for it from jmeter-plugins.org

Regards
@ubikloadpack

On Thu, Dec 15, 2016 at 3:26 PM, Jean-Sebastien Vachon <[hidden email]>
wrote:

> Hi All,
>
> I am trying to build a test suite to test the performance of one of our
> system and I need to provide some information to each thread so that the
> following code will work...
>
>   <script type="application/javascript">
>         var getName = function() {
>             var name;
>             try {
>                 name = window.localStorage.getItem("user-name");
>             } catch(error) {
>                 console.log(error);
>             }
>             if(!name) {
>                 name = window.prompt("What's your name, please ?", "Rachel
> Smith");
>             ...
>
>
> I tried setting a cookie using the CookieManager but I can not get it to
> pass a predefined value.
>
> Is there a way to put something in the localStorage so that the javascript
> code will see it and proceed?
>
> Thanks
>
Loading...