-->

Verify Regex in Robot Framework?

Problem:- How to verify given regular expression using Robot Framework

Solution:-

A pessimist sees the difficulty in every opportunity; an optimist sees the opportunity in every difficultyyyyy

1.Create a regular expression using online tool
Example:- we want to verify 34.4% we will create a regular expression first 
Regex robot framework



2.Use Should Match Regex keyword

regex robot framework

Example 1 :-
We want to verify whether dynamic pattern like 34.4% exists on UI
Example2:-
Verify that uuid like 9100d6678-1b1c-45b445-bdf9-47bc0b15a603 exists on UI 

Code:-
${cpuUsage} Get Text //test/div 
Should Match Regexp ${cpuUsage} ^[0-9]{1,2}[.][0-9]% CPU Usage validation
${uuidNumber} Get Text //test/div 
Should Match Regexp ${uuidNumber} [0-9a-z-] UUID validation

More Examples

Basic Linux commands for beginners

Scenario:- What are some of basic commands one should know when moving from windows enviornment to linux(say ubuntu)?

Solution:- Its a learning experience when moving from mouse click(windows) to terminal evniornment(ubuntu)

We are trying to cover some the very basic commands, please feel free to add more from experience as comments to this post, as its said
If you want to lift yourself up, lift up someone else ..


1.Sudo(Run as adminstator in windows) - sudo command executes a command with administrative privileges (root-user administrative level), which is necessary
example sudo mkdir test 

mkdir ubuntu

2.mkdir(new folder), creates new working directory in the selected location 

3.pwd, tells the current working directory

4. ls, list all the files in the given folder 

5.ll, another form of listing the items try it out

6.Editing a file :-

  • Open file sudo vi filename
  • press ESC
  • press i (for inserting values into file)
  • move cursor the position where editing need to be done
  • edit
  • type :wq (to write and quit the file after saving)
7.Change to root user, sudo -s
8.Rename a file by using move, sudo mv "oldfilename" "new file name"
9.clear, for clearing the terminal
10. Most important how to launch terminal, press ALT+SHIFT+T
11.How to open new tab in terminal, CTRL+SHIFT+T
12.Get to know the existing used commands in terminal, use history in terminal 

history command in linux

Practical issues and solutions for working with JMeter - Part2

jmeter issues



More Scenarios

Scenario:- 
How to display results from Beanshell sampler to response?

Solution :- 

Simple code example:- 

String display="HelloWorld";

//Taking results and displaying in response
SampleResult.setResponseData( display);

SampleResult.setDataType( org.apache.jmeter.samplers.SampleResult.TEXT );


Scenario:- 
Not able to understand the error message thrown by jmeter in beanshell sampler or beanshell assertions?


Solution :-  

Use try-catch

try{
 int expectedMsgs = ${noOfMessages} * ${messageThreads};
 int actualCount =Integer.parseInt(SampleResult.getResponseDataAsString());
 
 //System.out.print(actualCount);
 if (expectedMsgs!=actualCount) {
    Failure = true;
    FailureMessage ="Expected Messages Sent"+expectedMsgs+"!="+actualCount+"ActualMessages in cassandra";
    print("Expected Messages Sent"+expectedMsgs+"!="+actualCount+"ActualMessages in cassandra");
 }
}
catch(Exception e){
 log.error("Failed check the erro"+e);
 }


Scenario:- 
Connect to remote mySql instance (say ubuntu box) using JMeter?

Solution :- 
Before doing this we need to provide privileges to the remote user to access the database using 
1.SSH into remote machine
ssh username@ip address > enter password

2.Login to mysql using root user
mysql -u root -pPassword
login to mysql using terminal

3.Grant permission as below
GRANT ALL PRIVILEGES ON *.* TO remote@'10.0.110.***' IDENTIFIED BY 'pwd' WITH GRANT OPTION;

4.Make sure to comment the following line in Mysql configuration file,
/etc/mysql/mysql.conf.d/mysqld.cnf 

comment bind-address = 127.0.0.1 using the # symbol


Mysql configuration file

5.Now we can replace the localhost, username and password in our connection settings for mysql.

Practical Examples

Practical issues and solutions for working with JMeter - Part1

Most of the time we are struck with very granular issues with JMeter. To overcome these type of hurdles we are sharing the pragmatic solutions to problems.

Refer part2 of learning for more issues

Do share your issues/solutions in the comment section below to help others as we always believe sharing is caring, and Life is short..share while you still have knowledge

Scenario:- 
How to pass random value in Json URI or Json parameters for API call using Jmeter?

Solution :- 
By using "Random Variable"
Where to find in JMeter
Add > Config Element > Random Variable

Name the variable as you want, put the range or create your own formula and start using this variable in Json URI or Json parameters


Random variable in jmeter

Scenario:- 
Not to execute the second sampler if first sampler value fails in Jmeter?

Solution :- 
By using "if controller"
Where to find in JMeter
Add > Logic controller > if controller

In condition add ${JMeterThread.last_sample_ok} 
Note:- Above value is predefined variables in jmeter


if controller jmeter

Scenario:- 
How to execute python script(command script) in jmeter?

Solution :- 
By using "OS sampler"
Where to find in JMeter

Add > Sampler > Os sampler

Example:- Lets say we want to run our MQTT test generator code
We will replicate the command step in OS sampler, 
python3 mqttgen.py 10 10 1  and define the working directory(referring to the script path)


command script from jmeter

More scenarios

Working with database in JMeter

Scenario:- Creating a database test plan, such that we can do the performance testing for CRUD operations.

Solution:-
Key Points:- 
1. JDBC connector files(jdbc jar).
2. Database connection details, so we can communication with database.
3. JDBC request, this is important to set the database connection details in jmeter

Step1:- Download the required connector file and place in lib folder of jmeter
For our example we have taken mySQL db, so we need the relevant connector(jar file).

Extract and place the file inside the lib folder in jmeter 

mysql connector placed in lib folder jmeter


Step2:-Add users as we did in our first test case.

Step3:-JDBC Connection configuration,establishing the connection of jmeter with database.

Right click "Thread Group" > ADD > Config element > JDBC Connection configuration
Fill the variable name, database name, driver details, and access credentials for the database.
jdbc connection with jmeter

Step4:-Use JDBC request to communicate with database and execute CRUD operations.

Right click "Thread Group" > ADD > Sampler > JDBC request.

Use the same Variable Name as we used in Step3, why ? as it tells jmeter to use the given connection string and its adds flexibility that in future we can use different connection string by adding new jdbc configuration and updating the variable name in jdbc request.

Add the CRUD operation (query)
jsbc request in jmeter

Note:- In working code we have added extra "Regular Expression Extractor", just to extract a given value from the response of query and add that value to a variable that we can use in the future requests.

Step5:-Add reporting.

Step6:- Run :)

Creating first test case using Jmeter?

Scenario:- How to create a basic level test case(its called test plan) in jmeter?

Most of us things that ppl r born smart, but truth is 99% of the smartest ppl n this world are driven by commitment to learn, learn and learn more.Learn more and share more :) Fb,G+,Twitter


Prerequisites:-
1.Test plan :- Container for running the tests. Its the starting point, by default jmeter opens up with test plan.

2.Users(called as Thread Group in JMeter) :- How many users should be involved in sending the request to the server, how often, and ramp up time.
Why this ? it mimics the interaction of real users with the application at given time.

3.Task( what type of request that needs to be send to server, called as Samplers):-For example if we want to access the google.com we are sending http request thus we need a particular type of sampler called http request sampler. If we are sending request to database we make use of jdbc sampler.

Note:- JMeter sends request to server based on the order they appear in the tree.

4.Assertions:- Verify the response send by server, comparing the actual value with expected value.

5.Report(called as Listeners in JMeter):- Request is send to server how to report the results for the response, we use Listeners for this.


Solution:- Lets create a pipeline for the above steps, 

ThreadGroup (We created users) > Samplers (users send request to server) > Assertions (Verify the response for the request) > Listeners (Report the response results as graphs, table and so on).

Step1:-Launch jmeter 
Step2:-Add thread group 
Note:- We have renamed the test plan in our example below.

Right click Test Plan > Add > Thread(Users) > Thread Group
Rename Thread group to something logical.
Change the thread properties like number of users.

Thread group in jmeter

Step3:-Add sampler 

Right click Thread Group > Add > Sampler > HTTP Request 
Rename it something logical
Define user defined variables for a test plan (FirstTestCaseJMeter) .

  • Open test plan
  • click on Add
  • Enter name and value
Why this as it add to maintainability of application url at one place.

user defined variables in jmeter


Add APP variable into the Sampler "Server Name" like ${APP}(this is how we use variable value in jmeter ${variableName}

Select the method as "GET"

http request jmeter



Note:-Incase we need to pass any parameters or body elements we can do it here.

Step4:-Assertions (say to check 200 status code)
Right click Thread Group > Add > Assertions > Response Assertion
Select ReponseCode  and Equals, put value as 200 

response assertion jmeter

Step5:-Listeners (Report the run results)
Right click Thread Group > Add > Listener > View Result Tree

Step6:-Run the test plan
Before running we need to save the .jmx file
Ways to run :-

  • Run > Start
  • Ctrl + r
  • Green play button on the menu bar
jmeter run options


Step7:-Check the run results
Select View Result Tree
Its green, means our assertion is successful and we got the response back :)

run results jmeter

So we successfully created the basic test plan in jmeter. To explore more change the listener type, add more users and add different type of assertions.

Learn more and share more.


Jmeter Error :- Cannot have single quote-char in quoted field:["] ?

Problem:-We used CSV data Set Config element in our Jmeter test to parameterize our request. But we faced the below error in logs:-

ERROR - jmeter.config.CSVDataSet: java.io.IOException: Cannot have single quote-char in quoted field:["] 

Solution:- 
Open the "CSV Data Set Config" > Set "Allow quoted data?" to False (By default is true)


CSV DATASET jmeter quote error

Why this as Jmeter by default will think "(quote) value in CSV file as delimiter, along with the ,(commas).

Note:-
Its always recommended to refer the jmeter logs if you are not getting the expected behaviour from the tool, as for above error we were just getting as parameters values in request data for sampler.
EOF in CSV data set error

Learn JMeter
Learn Selenium
Learn JAVA