You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by arihan <ar...@gmail.com> on 2013/10/08 15:11:17 UTC

how to register and call the external javascript function in jmeter

I've a scenario like 

user logs in ( /login)

navigate to the reservations page to get all the reservation id
(/reservations)

Through json path extractor it gets first reservation id from the
JSON.($..reservationLists..id[0], reservationid)

navigate to the first reservation id (/reservation/${reservationid})

In every page it navigates , the HTTP header manager needs the handShakeKey
applicable to that page which is basically combination of url, secretKey,
publicKey. ( secretKey , publicKey are both static but url changes )

For static urls like ( /login, /reservations) I've added a BSF pre-processor
at beginning and declare variables and use those variables in the HTTP
Header Manager as ${handshakeKey_reservations}, ${handshakeKey_login} etc
which  works perfectly fine. 

var urls = ["login", "reservations", "logout", "profile"];

for (var i = 0; i < urls.length; i++) {

var handShakeKeyForStaticUrls =
CryptoJS.SHA1("/"+urls[i]+"abcdediiebneC"+"12345678"); 

handShakeKeyForStaticUrls =
handShakeKeyForStaticUrls.toString(CryptoJS.enc.Base64); 

vars.put("handshakeKey_"+urls[i], handShakeKeyForStaticUrls);
 
}

Now the problem is for Dynamic url (/reservation/${reservationid},
/reservation/${reservationid}/summary etc.......)

I was thinking to write a java script function something like 

function getHandShakeKey(url)
{

var handShakeKeyForDynamicUrls = CryptoJS.SHA1(url+"abcdeffe"+"12345678"); 

handShakeKeyForDynamicUrls =
handShakeKeyForDynamicUrls.toString(CryptoJS.enc.Base64); 

//return handShakeKeyForDynamicUrls;

vars.put("handShakeKeyForDynamicUrls", handShakeKeyForDynamicUrls);

}

Then in the HTTP header manager I would do like

handshakeKey    
${_javaScript(getHandShakeKey("/reservation/${reservationid}"))}

So question is Where I can register this java script function so that I can
call it everywhere .

Though the workaround I've done is at the moment, adding a BSF post
processor to each http sampler which contains dynamic url and generating and
declaring handShakeKey applicable for that url only and using the same in
the corresponding HTTP header manager. I need to get rid of this.  



--
View this message in context: http://jmeter.512774.n5.nabble.com/how-to-register-and-call-the-external-javascript-function-in-jmeter-tp5718378.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


Re: how to register and call the external javascript function in jmeter

Posted by arihan <ar...@gmail.com>.
Does it for registering java script class and methods so that it can be
called everywhere ????



--
View this message in context: http://jmeter.512774.n5.nabble.com/how-to-register-and-call-the-external-javascript-function-in-jmeter-tp5718378p5718443.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


Re: how to register and call the external javascript function in jmeter

Posted by Flavio Cysne <fl...@gmail.com>.
Did you try this
http://www.beanshell.org/manual/bshmanual.html#Adding_BeanShell_Commands  ?


2013/10/15 arihan <ar...@gmail.com>

> I tried a bit but didn't find the solution to register the java script
> methods/class and call it globally.Have you experimented on this?
>
>
>
> --
> View this message in context:
> http://jmeter.512774.n5.nabble.com/how-to-register-and-call-the-external-javascript-function-in-jmeter-tp5718378p5718440.html
> Sent from the JMeter - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>
>

Re: how to register and call the external javascript function in jmeter

Posted by arihan <ar...@gmail.com>.
I tried a bit but didn't find the solution to register the java script
methods/class and call it globally.Have you experimented on this? 



--
View this message in context: http://jmeter.512774.n5.nabble.com/how-to-register-and-call-the-external-javascript-function-in-jmeter-tp5718378p5718440.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


Re: how to register and call the external javascript function in jmeter

Posted by sebb <se...@gmail.com>.
On 10 October 2013 16:26, arihan <ar...@gmail.com> wrote:
> Is this actually possible to register the external java scripts and call the
> functions from that java script globally everywhere.

I don't think so currently.

However BeanShell does allow this; see jmeter.properties in particular:

beanshell.function.init

>
>
> --
> View this message in context: http://jmeter.512774.n5.nabble.com/how-to-register-and-call-the-external-javascript-function-in-jmeter-tp5718378p5718423.html
> Sent from the JMeter - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


Re: how to register and call the external javascript function in jmeter

Posted by arihan <ar...@gmail.com>.
Is this actually possible to register the external java scripts and call the
functions from that java script globally everywhere.



--
View this message in context: http://jmeter.512774.n5.nabble.com/how-to-register-and-call-the-external-javascript-function-in-jmeter-tp5718378p5718423.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


Re: how to register and call the external javascript function in jmeter

Posted by arihan <ar...@gmail.com>.
Any thoughts on this please



--
View this message in context: http://jmeter.512774.n5.nabble.com/how-to-register-and-call-the-external-javascript-function-in-jmeter-tp5718378p5718413.html
Sent from the JMeter - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org