JMeter Web Driver Test randomly fails for some threads - jmeter

I have a JMeter Web Driver Test plan. Where I have:
a Thread group with 3 users
a Web Driver Sampler,
Firefox Driver Config
and View Results in Tree listener.
Also I have a CSV Data Set Config wherein I have mapped it to a CSV file to receive Username and Passwords.
In the Web Driver Sampler we have just written a Simple code which invokes Firefox browser, passes the url to it, passes Username and Passwords to it.
Then makes a search for a term and logs out.
Once I run this test with 3 users, the test runs fine for first and second user and fails for the third one.
And when I run the test again, First and Third user passes but fails for the second.
When I go and check on the Response message, it says it was unable to locate element.
Whereas it would have ran fine for the next user.
I'm not sure why the test is behaving like this, Can someone Help me on this issue.

Elements may not appear in DOM immediately after WebDriver get() request, I would suggest to add an extra step which will ensure that specified element is present in DOM and may be interacted with prior to clicking/typing by something like:
var pkg = JavaImporter(org.openqa.selenium)
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait)
wait.until(support_ui.ExpectedConditions.presenceOfElementLocated(pkg.By.id('element_id')))
var element=WDS.browser.findElement(pkg.By.id('element_id'))
element.click()
See Using Selenium with JMeter's WebDriver Sampler guide for more details on Selenium scripting in JMeter

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

Can JMeter do automation testing like Selenium can do?

i am still new to JMeter and i was assigned to a work that I will need to use JMeter to perform automation testing. The idea is to write script using JMeter and run the script to fill in the forms in the website. I was curious that can JMeter use different data from the database to fill in the form of the website everytime it execute?(unique data for every user)
I have followed this tutorial (https://www.blazemeter.com/blog/fill-forms-and-submit-with-jmeter-made-easy/ ) and it succeed, however, when i try to change the parameter name (to some other names that do not matches the field name found in the inpect mode), it still works. So i was wondering how JMeter knows where to put in the parameter even i have change to a wrong field name?
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).
Browsers don't do any magic, they execute HTTP Requests, wait for response and render it. JMeter in its turn can execute the same HTTP requests so traffic would be the same, however it will not render the response, but rather measure the time and collect some more metrics.
If you change the names of the inputs in the form most probably the request will be successful, to wit you will get HTTP Status Code below 400 hence JMeter will mark the result as "green", however if you inspect the response using View Results Tree listener you will see that the form is not filled and/or you still at the same page.
If you want to use JMeter for checking the data returned by the application you're testing consider using JMeter Assertions to test presence of expected values, absence of errors, set response time thresholds, etc.
You can automate the form submission or order placement usin JMeter. You can JMeter for API testing as well by adding assertions. But the main purpose of the JMeter is to test the performance of the application. Its not like selenium which performs actions on the browser whereas JMeter sends the request in various protocols to relevant server and can also simulate many users at the same time.
If you want to do extensive automation testing,JMeter isnt the ideal tool for that.
You can use webdriver sampler to run the selenium with jmeter. It requires to configure sampler and browser config which are plugin and can be downloaded using plugin manager.
For more info:-https://www.blazemeter.com/blog/jmeter-webdriver-sampler/
Now, without the plugin it is working on protocol level and not on the frontend as pointed out in the above comments.
So, yes it can depend on which layer you want to work. It can work on frontend like selenium using the webdriver plugin and can submit the form with different data as a direct request to the server without using the frontend/GUI.
Hope this helps.
It depends on what you are trying to automate. If you plan to automate API invocation where there are some pre-requisites like grabbing tokens, cookies, session IDs from the browser, then JMeter can probably be used where existing JMeter capabilities can be leveraged using BeanShell scripting and other plugins.
But if you plan to have a full blown UI automation framework then JMeter might not be an ideal choice.

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.

Error while executing checkout script in JMeter

[404-Not found]
Hello All,
I'm running one script having Checkout functionality but my script gets fail at particular page instance giving me "404 - Not found" error in logs.
But while executing manually I'm able to go to the page successfully.Below is the error message. Do i need to pass cookies in the same while execution.
Any help will be appreciated
Most likely this is due to missing or not properly working correlation. You can record the test scenario using HTTP(S) Test Script Recorder but it will be only a "skeleton" of the test containing hard-coded values like IDs or URLs or whatever.
So given you checked something out and recorded the relevant request(s) next time you will try to replay the recorded script you will get an error as the item has already been checked out, so basically you need to find another one to work with.
Normally the situation is worked around as follows:
Record the test 2 times
Identify request parameters which are changing
Using JMeter PostProcessors (the most commonly used is Regular Expression Extractor, however it may vary depending on your response data nature) convert hard-coded recorded values into JMeter Variables
Use Debug Sampler and View Results Tree listener combination to inspect:
JMeter Variables values
Request details
Server responses

JMeter - link clicking to generate a username

Sorry if this has been answered already, i tried to search but could get the exact information i am after.
The issue:
I am using JMeter to run some tests on a web application, as part of one of the flow, I under a first and surname in 2 input fields and i have link (Get userid) on clicking on the link the system will generate a user name. The user name is made up of first 4 letters from surname and first letter from the firsname and number at the end example: firstname is Test and surname is Environment, on clicking the get user id link the username will be generated as 'envit1' if 'envit1' is already existing then it would generated 'envirt2'
How do I simulate the click which generates the userid using jMeter.
Apologies but I am fairly new with JMeter, please ask if you need more infomratmation.
Many thanks in advance, Kay
If you're new to JMeter the best way to get things done is recording your user ID generation steps using one of the following approaches:
JMeter bundled HTTP(S) Test Script Recorder which acts like a browser proxy
A Google Chrome Extension which is capable of recording JMeter .jmx scripts right from your browser.
You can see what requests are being sent and HTML responses using handy View Results Tree listener.
However if clicking on link isn't being recorded, it's being handled by client-side Javascript. JMeter is not a browser and isn't capable of executing Javascript so you'll have to use WebDriver Sampler as Releasematic suggests.
You can use WebDriver Sampler but in each iteration it opens browser which may increase RAM usage. There is another option is to generate user id by running JS code in "JSR223 Sampler". With JSR223 Sampler you can run JS code but can't get access to DOM, so such JS code won't work:
function () {document.getElementById("edit-buttons-cleanup").click();};
You can install the plugin pack for the JMeter WebDriver sampler. Then, using some Javascript commands, you can start either a Firefox or a headless HTMLUnit and operate upon a webpage in a Jmeter step.

Resources