Showing posts with label website search testing. Show all posts
Showing posts with label website search testing. Show all posts

Wednesday, 26 October 2016

Jmeter, IF controller checking empty variable using


Sometimes you need to add HTTP samplers with dynamic URL or with dynamic part of the URL which are stored in some variable after HTTP sampler post-processing.



But if Regular Expression Extractor will not find any matching string result variable will be set to default value (empty value in our case). We should test this variable for emptyness before we will use it.


Now if the News page has not any news we are sure that JMeter will handle this situation correctly.

HTTP Request sampler with dynamic URL in JMeter


If you need to add HTTP Request sampler with dynamic URL that can be different each time from testing to testing you must use one of the Post-Processors offered by JMeter. I usually use Regular Expression Extractor for this purposes.

So, let's imaging that you have "Popular News" web page which contains the links to "News Story" web pages that contains the full texts of news and you want to write a test which will include both "News" page and random "News Story" page.

For this you must include "News" page HTTP Request sampler inside Simple Controller with a Regular Expression Extractor to store random "News Story" page URL to a variable:


Then use the variable with the stored random "News Story" page URL in "News Story" HTTP sampler:

Thursday, 7 February 2013

Jmeter bean shell script, create file, read jmeter variable value, store script variable value into jmeter variable

Hi All,

Some times in JMeter scripting we need to store the output value in file or wanna show the run time  variable value in console window. OR we need to get the current JMeter script directory path. This can be achieved via scripting in Bean Shell Pre/Post Processor.

Here I am using time and counter function of JMeter to create the file.In bean shell scripting we are reading the JMeter variables value and storing script variable value into JMeter variable or creating Jmeter variable

Here is the  Bean Shell script :

import org.apache.jmeter.services.FileServer;
import org.apache.jmeter.services.FileServer;
import java.util.Date;
import java.text.SimpleDateFormat;

SimpleDateFormat formatter = new SimpleDateFormat( "yyyyMMddHHmmss" );  
String datetime = formatter.format( new java.util.Date() ); 

// Get current running counter value(C refrence name deifned in counter config element)

String counter= vars.get("C");

// Get Jmeter variable value in bean shell script by vars.get method

String timer= vars.get("JmeterTimerVariable");

// here JmeterTimerVariable defined in User Defined variable  config element


//  Display value in Console 

System.out.println("Current counter value = " + counter);

System.out.println("JmeterTimerVariable value = " + timer);


// Store beanshel script variable into Jmeter variable by using vars.put method and we will user this jmetervariable in Wikisearch http request

vars.put("JmeterSearchVariable",datetime+counter);

// get JmeterSearchVariable value in beanshell script

String SearchVariable = vars.get("JmeterSearchVariable");

System.out.println("SearchVariable value = " + SearchVariable);

// Here we can get the directory path of Jmeter script file

String DirPath = FileServer.getFileServer().getBaseDir();

// write into jmeter.log file under Jmeter/bin directory

log.info(DirPath);

System.out.println("Directory path of Jmeter script file = " + FileServer.getFileServer().getBaseDir());

// we will create a file under directory of jmeter script file with name JmeterReords using File system True file will be created if not and data will //append into the file False will create a new file with fresh data

f = new FileOutputStream(FileServer.getFileServer().getBaseDir()+"\\JmeterReords.txt", true); 
p = new PrintStream(f); 
// write data into file 
p.println("Current counter value = " + counter);
p.println("JmeterTimerVariable value = " + timer);
p.println("Directory path of Jmeter script file = " +DirPath);
p.close();
f.close();

// if you want to create unique file for each loop counter refer below script

String uniquefilename = timer+counter;
f = new FileOutputStream(FileServer.getFileServer().getBaseDir()+"\\"+uniquefilename+".log", true); 
p = new PrintStream(f); 
// write data into file 
p.println("Current counter value = " + counter);
p.println("JmeterTimerVariable value = " + timer);
p.println("Directory path of Jmeter script file = " +DirPath);
p.close();
f.close();





Here is the structure of JMeter script

Jmeter Bean Shell script
Jmeter bean Shell script


Monday, 29 October 2012

Jmeter: pass a value between threads

Synopsis: 
Find out ways to pass a value between threads (i.e. capturing a value in one of the thread and passing it to the other thread in the same test plan).
Tool Used:     JMeter: Performance testing tool.

Solution:       Sharing Variables



1)      Used Sampler : BSF Sampler
1)      Screenshot displaying the use of the BSF Sampler using  ${__setProperty(storeid, ${storeid})}; for capturing the time. The website used is http://www.mail-archive.com/jmeter-user@jakarta.apache.org/info.html for displaying the value captured in one thread to the other thread.
Screenshot 1: Displaying the BSF Sampler capturing the time value using ${__setProperty(storetime, ${__time(HMS)})};
Screenshot 2: Displaying the time captured using ${__property(storetime)} in the other thread.
Screenshot3: Successful execution of the script displaying the time value captured in Thread2