How can I import Web3 in Jmeter? - jmeter

I am trying to import Web3 in jmeter using component JSR223 Sampler by command:
load("https://cdn.jsdelivr.net/npm/web3#latest/dist/web3.min.js");
but I got an error:
ERROR o.a.j.p.j.s.JSR223Sampler: Problem in JSR223 script JSR223 Sampler, message: javax.script.ScriptException: ReferenceError: "window" is not defined in https://cdn.jsdelivr.net/npm/web3#latest/dist/web3.min.js
How can I use Web3 in Jmeter?

As per the Window interface documentation
The Window interface represents a window containing a DOM document; the document property points to the DOM document loaded in that window.
the window object is something belonging to the web browser, you don't have it in Nashorn implementation.
The only way to use the library is using a real browser, JMeter can be integrated with Selenium browser automation framework via WebDriver Sampler

Related

alternate option for window object in jmeter

When we try to encrypt and decrypt the application for front end request and response data,
Window object is not getting support in Jmeter.
As it generate 2 session id .
Kindly let us know any method in Groovy to support .
Window object is specific to the browser
As per JMeter project main page:
JMeter is not a browser, it works at protocol level. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages. Nor does it render the HTML pages as a browser does (it's possible to view the response as HTML etc., but the timings are not included in any samples, and only one sample in one thread is ever displayed at a time).
So there is no equivalent in any language supported by JMeter's JSR223 Test Elements
The options are in:
Use WebDriver Sampler for getting the session IDs you're looking for, they can be passed later on to "normal" HTTP Request samplers (but this way each JMeter virtual user will kick off a real browser instance)
Extract the code responsible for request encryption and session ID generation using browser developer tools and convert it to something JMeter could execute (remove the browser context), preferably in Groovy as it's the most performing scripting option

JMeter - Webdriver - Multiple iframe

How to test iframes with jmeter
I have windows with multiple iframes
I tried to used with pkg.SwitchTo().Frame(0)
or pkg.SwitchTo().Frame("iframe name")
but I received an error : "SwitchTo is not a function in
There is different way to Identify iframes with jmeter?
I don't know what is pkg but the shorthand for the WebDriver class instance when it comes to the WebDriver Sampler is WDS.browser
Therefore you can switch to the desired frame as simple as:
WDS.browser.switchTo().frame("myFrame")
and when you need to switch back:
WDS.browser.switchTo().defaultContent()
More information: The WebDriver Sampler: Your Top 10 Questions Answered

Performance - how to capture all the Request in the Network tab of chrome in an automated way

I am in a process to capture all the request when an HTML page is loaded. My end goal is to create a report with the time taken for each individual request and also for the total time taken to load the entire page. I have tried to use the performance.getEntries() but it is limited to store only 150 request in the buffer. To overcome this I tried to set the performance.setResourceTimingBufferSize(size) but this buffer size is reset to default 150 when i refresh the page.
I would like to know the solution for below few things,
how to set the performance.setResourceTimingBufferSize(size) before loading any page (if I set it when the page is loading it misses to capture some of the request). Few suggested to set this in HTML head tag, but this is not possible in my case because i need to use selenium and i cant modify anything in source file.
I also found that we can save all the request as HAR file in chrome console. is there any way to do it in automated way?
Is there any other way to capture all the request ?
PS: I a using Jmeter (to simulate multiple users) to run the selenium scripts using web driver sampler. The automated way in the sense it should be done using selenium.
You can use BrowserMob proxy in order to create and start a proxy server which will capture data and save it in form of .har
Download BrowserMob proxy and put .jar files somewhere into JMeter Classpath
Restart JMeter to pick the .jars put
In setUp Thread Group add JSR223 Sampler and put the following code into "Script" area
import net.lightbody.bmp.BrowserMobProxy
import net.lightbody.bmp.BrowserMobProxyServer
import net.lightbody.bmp.proxy.CaptureType
def proxy = new BrowserMobProxyServer()
def captureTypes = new HashSet<>();
captureTypes.addAll(CaptureType.getAllContentCaptureTypes());
captureTypes.addAll(CaptureType.getHeaderCaptureTypes());
captureTypes.addAll(CaptureType.getCookieCaptureTypes());
proxy.setHarCaptureTypes(captureTypes);
proxy.start(8080)
proxy.newHar()
props.put('proxy', proxy)
Set up your Chrome Driver Config to use proxy from the step 3
Add tearDown Thread Group to your Test Plan and in another JSR223 Sampler use the following code to store requests made by the WebDriver Sampler(s) into a .har file:
def proxy = props.get('proxy')
proxy.getHar().writeTo(new File('some.har'))
proxy.stop()
That's it, now you should have .har file generated during test execution.
References:
BrowserMob Proxy: Embedded Mode
Apache Groovy - Why and How You Should Use It
For your goal, you can try https://gtmetrix.com/. This will give you a report for the load time and all the requests in waterfall model like in browser. Moreover, you can download the full report in pdf and can do compare and retest.
There you can also download the HAR file.
Though, it is not related to selenium but may fit your goal and It can be automated.

How to use JavaScript global function in Jmeter

How can i use global javaScript function sellerInterface.addBidOnline() in JMeter?
I can use this function in browser, but I do not know how to call it in JMeter.
Use in console
I try using this function in BSF Sampler, but it did not work
enter image description here
As per JMeter Project main page:
JMeter is not a browser, it works at protocol level. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages. Nor does it render the HTML pages as a browser does (it's possible to view the response as HTML etc., but the timings are not included in any samples, and only one sample in one thread is ever displayed at a time).
If the JavaScript call generates a HTTP Request - you can record it using HTTP(S) Test Script Recorder and replay as HTTP Request sampler. For the time being it is not possible to execute JavaScript from JMeter tests.
You can take a look at WebDriver Sampler which provides JMeter integration with Selenium so each JMeter Thread (virtual user) will have its own real browser so you will be able to execute JavaScript like
WDS.browser.executeScript('your_script')
however real browsers are very resource intensive and the number of browsers you will be able to kick off will be very limited.

How to make ajax calls by using jmeter?

I have a game website to do the load testing, but I need to do load testing of scoreboard, which is an Ajax call and changes dynamically.
I have tried to do this by using Groovy language and jsr223 sampler, but it's not working. Then I tried using the web driver sampler. I am unable to do it in both cases.
By using the web driver, a new browser gets launched every time and it's unable to do load testing by simulating 100 or more users.
Is there any way to do this?
Please take an help from below:
https://blazemeter.com/blog/how-load-test-ajaxxhr-enabled-sites-jmeter
Performance Testing of AJAX calls via JMeter

Resources