Thursday, 14 July 2016

__setProperty & __property

           If we have multiple threads in our application and we need to define global variable so that every thread have access to the variable,we may use "__setProperty" function in one thread to set the variable value and then use "__property" function to get the variable value in different thread

Hypothetical Scenario:
 Use user password set at thread 1 in Thread 2

Functions are defined as below

Set Property:

${__setProperty(userpassword,*password*,)}

where,
  1. Property name:  userpassword
  2. Property value: *password*
Get Property:
${__property(userpassword,,)


So we will use set property function to set the property in one thread and use get property function to access the password value in other thread.


Test Plan :

We have set user password in one of the request.So "userpassword" has been assigned with value "*password*"



Now we will use get property function to use the set password in thread 1 in thread 2



Now if you execute your test script,this should successfully run.



Wednesday, 13 July 2016

"__StringFromFile" function

If there is requirement to fetch strings like user name from a single file or multiple file then we might use "__StringFromFile" function.



Hypothetical Scenario:


Read "user name" from multiple input files and then login the user



Jmeter Scripting to implement above scenario:


Let us consider that we have below three text files which contains user ids

 
Text files have user names as below
  


Now we need to prepare our jmeter script in such a way that script reads each user name from multiple files and login the user using each user id.So we can use "__StringFromFile"  function to implement the scenario

${__StringFromFile(D:\Test#.txt,userNameFile,1,3)}

Where
1.       D:\Test#.txt : Absolute path 
2.       userNamefile: Name of variable in which to store the result 
3.       1: Start file sequence number
4.       3: Final file sequence number 

in (Test#.txt) file name,# will be replaced by 1,2 and 3 sequentially. Considering we have 10 user names in our 3 files, we will keep the thread number as 10 so all the user names are picked one after another


Test Plan Details:

1.       Considering we have 10 user names in our 3 files, we will keep the thread number as 10 so all the user names are picked one after another

 


Functionality description:
User opens the landing page and then enters user id  and password to move to dashboard screen
 
 
Note:I have kept 1 user in each file and executed the script.Out of three users only 1 is a valid user and rest are invalid.So result shows failure for two invalid users.U may use appropriate assertions to capture the failure

 


Conclusion: So this way we can use StringFromFile function to parameterize our test cases as done using “CSV data set config”.