I created one (using jp#gc - WebDriver Sampler) script for UI login using a single user. Now I want to log in to 100 different users with different credentials. How we can achieve this in JMeter?
In the majority of cases people put credentials into a .CSV file and read them using CSV Data Set Config for JMeter tests parameterization.
If you need to use a JMeter Variable in the WebDriver Sampler script you can use WDS.vars shorthand for JMeterVariables class instance like:
var user = WDS.vars.get('username')
var pass = WDS.vars.get('password')
WDS.browser.findElement(org.openqa.selenium.By.id('someId')).sendKeys(user)
//etc.
Related
While doing Testing I need to taken the token from Oath API and use it in another subsequent API's which is successfully done. But when HTML report is generated through CLI the Oath API's Response time and Throughput is also calculated, is there a way we can ignore that request ?
Add to requests JSR223 PostProcessor below them which will ignore request/response
prev.setIgnore()
prev - (SampleResult) - gives access to the previous SampleResult
Call this method to tell JMeter to ignore this SampleResult by Listeners
There are following options:
Add JSR223 PostProcessor as a child of the Sampler(s) you need to exclude from Listeners/test results/whatever and put the following code into "Script" area:
prev.setIgnore()
Use FilterResults Tool (available via JMeter Plugins project, can be installed using JMeter Plugins Manager), it allows excluding sample results basing on strings or regular expressions or time offsets or both
JMeter .jtl result files are basically CSV files, you can use your favourite text editor or tool like MS Excel to remove the result entries you're not interested in
I have a scenario where one of the test REST API returns a transaction_Id, this transaction Id I need to pass in my next request(API Request), also upload the file as well. This upload file has name format like ${transaction_Id}_1_1_bkg.raw,without correct format backend server may not be able to analyze the data.
Since I have to run a load test, these transaction Ids will generate at run time and the same I have to change the file name and upload it as well.
Did any one had face this challenge before in Jmeter to change the file name at run time and upload it, if yes, what was the solution.
Thanks,
Akshat
You could copy the file to a new one with the desired name using JSR223 PreProcessor like
org.apache.commons.io.FileUtils.copyFile(new File('template_bkg.raw'), new File(vars.get('transaction_Id') + '_1_1_bkg.raw'))
where vars stands for JMeterVariables class instance, see the JavaDoc for more information on all existing functions and Top 8 JMeter Java Classes You Should Be Using with Groovy article to learn more about JMeter API shorthands available for the JSR223 Test Elements.
Once upload is finished you can delete the file using JSR223 PostProcessor
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.
I am performing HTTP Request samples (both GET and POST) in JMeter and am trying to figure out how to include pieces of the request (right now, just the query and form parameters) in the CSV log output. It seems like I'll have to use something like BeanShell Listener to write my own log file using the JMeter API. Does that sound right?
References:
http://qainsights.com/how-to-write-data-to-excel-csv-in-jmeter-using-beanshell-scripting/
Not necessarily. Given your parameters are in form of JMeter Variables (if not - you can convert them via User Defined Variables test element) you can use samples_variable property in order to add values to JMeter's .jtl results file
Add the next line to user.properties file (it's located under /bin folder of your JMeter installation)
sample_variables=var1,var2,etc.
where var1 and var2 are your JMeter Variables
Restart JMeter to pick the property up
Next time you run your test variable values will be added to .jtl results file
References:
Sample Variables chapter of JMeter User Manual
Apache JMeter Properties Customization Guide - comprehensive information on JMeter Properties and ways of working with them
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