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”.
 

 

No comments:

Post a Comment