Absent Member.
Absent Member.
5930 views

executing a Javascript file from silkperformer

Jump to solution

i have a javascript file which performs some password encryption. I need to call this file from my .bdf script. Is there any way by which i can do this?
I tried converting the javascript logic to its BDL equivalent, however, there are many functions and operators (bitwise xor, bitwise shift) that are not supported by silk.
Any help would be appreciated...

0 Likes
2 Solutions

Accepted Solutions
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

Hello,

if you are scripting with BDLT, have a look to BrowserExecuteJavaScript method.
If you are scripting HTTP, you can use SilkPerformer's Java framework and Java's ScriptEngineManager to execute JavaScript, see example below.

http://community.microfocus.com/cfs-file.ashx/__key/communityserver-discussions-components-files/30/7801.SilkPerformer-_2D00_-How-to-reuse-JavaScript-code-from-BDL.pdf

HTH

Jean

View solution in original post

0 Likes
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

Hi

SilkPerformer doesn't support running native JavaScript code directly from within scripts.  It can execute JavaScript in the BDLT module both in the frontend and with the BrowserExecuteJS function but these wont help you if you are using protocol level scripts.  

You can execute the code in the following ways:

- Java Frameworks approach using ScriptEngineManager as mentioned above

- Compile the javascript into an exe using .net framework JScript and run the exe from within your script when needed using ProcessInitialize functions.  This approach uses the windows command line so it is lightweight.  

You can execute the code logic after rewriting it in a natively supported language:

- Java Frameworks approach using java language to rewrite the javascript logic.

- .Net Framework approach if you rewrite the logic in .net code

Using BDLT within protocol level scripts:

You can also merge some bdlt logic into your protocol level script by starting a browser and calling the page which executes the javascript code.  for this approach to work it should return the output value to the url or to an object of the page where the bdlt functions can access it (like a browserGetText for example).  This approach has not been widely tested and has some memory overhead associated so you should use with caution.

Using BDLT script alongside protocol level scripts:

This involves having a script written in bdlt module and imported into a project which uses protocol module.  The bdlt script only runs to generate the values from the javascript logic and output them to a file.  The protocol level scripts then run and access the file for use as input values where needed.  This method also has memory overhead associated, both with using real browsers and with file access so it should be used with caution.  It is also not useful in scenarios where the JS return value is session related because it wont be available for use in time.  

Other methods worth mentioning are:

- preparing a list of values which the JavaScript would output in advance so they can be passed in from a csv to the loadtest.  

- Make the password the same for all users so the logic to encrypt is not required at all.

- Disable the encryption logic for testing.  This is not ideal but if the solution available to you is difficult to implement then this is worth considering.  

There are possibly other ways of doing this but the solutions have the potential to become more obscure.  Each of the above solutions have their own pros and cons and complexities so which one you decide to use depends completely on your scenario.  

This information is generic so if you are unsure how to proceed or if you cant decide on which option is best please feel free to log a support case and we can discuss your scenario in more detail.  

Thanks

Jonny

View solution in original post

0 Likes
6 Replies
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

Hi Pratik

There are various solutions open to you depending on your requirements however investigating these can become complex and difficult to manage through the forum.  Can you log a support case so we can investigate your requirements and provide appropriate options?

0 Likes
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

Also, I wanted to bring your attention to the built-in encryption functions just in case you weren't aware of them all.  

Encrypt3DES

Encrypt

WebMD5Encode

0 Likes
Absent Member.
Absent Member.

the encryption logic is developed by a third party vendor for client side encryption in an application and hence cannot be emulated by the standard silk functions.

0 Likes
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

Hello,

if you are scripting with BDLT, have a look to BrowserExecuteJavaScript method.
If you are scripting HTTP, you can use SilkPerformer's Java framework and Java's ScriptEngineManager to execute JavaScript, see example below.

http://community.microfocus.com/cfs-file.ashx/__key/communityserver-discussions-components-files/30/7801.SilkPerformer-_2D00_-How-to-reuse-JavaScript-code-from-BDL.pdf

HTH

Jean

View solution in original post

0 Likes
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

Hi

SilkPerformer doesn't support running native JavaScript code directly from within scripts.  It can execute JavaScript in the BDLT module both in the frontend and with the BrowserExecuteJS function but these wont help you if you are using protocol level scripts.  

You can execute the code in the following ways:

- Java Frameworks approach using ScriptEngineManager as mentioned above

- Compile the javascript into an exe using .net framework JScript and run the exe from within your script when needed using ProcessInitialize functions.  This approach uses the windows command line so it is lightweight.  

You can execute the code logic after rewriting it in a natively supported language:

- Java Frameworks approach using java language to rewrite the javascript logic.

- .Net Framework approach if you rewrite the logic in .net code

Using BDLT within protocol level scripts:

You can also merge some bdlt logic into your protocol level script by starting a browser and calling the page which executes the javascript code.  for this approach to work it should return the output value to the url or to an object of the page where the bdlt functions can access it (like a browserGetText for example).  This approach has not been widely tested and has some memory overhead associated so you should use with caution.

Using BDLT script alongside protocol level scripts:

This involves having a script written in bdlt module and imported into a project which uses protocol module.  The bdlt script only runs to generate the values from the javascript logic and output them to a file.  The protocol level scripts then run and access the file for use as input values where needed.  This method also has memory overhead associated, both with using real browsers and with file access so it should be used with caution.  It is also not useful in scenarios where the JS return value is session related because it wont be available for use in time.  

Other methods worth mentioning are:

- preparing a list of values which the JavaScript would output in advance so they can be passed in from a csv to the loadtest.  

- Make the password the same for all users so the logic to encrypt is not required at all.

- Disable the encryption logic for testing.  This is not ideal but if the solution available to you is difficult to implement then this is worth considering.  

There are possibly other ways of doing this but the solutions have the potential to become more obscure.  Each of the above solutions have their own pros and cons and complexities so which one you decide to use depends completely on your scenario.  

This information is generic so if you are unsure how to proceed or if you cant decide on which option is best please feel free to log a support case and we can discuss your scenario in more detail.  

Thanks

Jonny

View solution in original post

0 Likes
Absent Member.
Absent Member.

hey jeang.....thx for the pdf...will definitely try that out....seems the most likely solution at the moment

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.