How to use custom library in Robot Framework
RobotFramework have rich set of libraries to do all the necessary tasks,
but sometimes we are not that much familiar with the library and we want to
write our own method and want to import that method as a library in RF.
Let me take an example here, suppose you have a CSV file
data.csv
Name,Age,region,country,Marks
pankaj,22,delhi,india,45
neeraj,32,noida,india,75
Task is to find value of 2nd Row and 3rd Column from a Robot Script.
How one like to proceed from here ?.
There are two options to do this
1. Using existing Libraries developed by other users
you can use libraries created by other users and see if that solves our
purpose
e.g. for this use-case you can search some csv library for robotframework available in git hub
These libraries have enough documentation and example to download and use them.
2.Creating our own library to do the task
if you are well versed in python or java and if you know how it can be
done in your preferred language, then the solution is super easy.
Let’s proceed with python, I have created below function which will
parse the csv and help us to find the value of any desired row or column
csv2.py
- import csv
- def go_to_nth_row_nth_column(File,row_no,col_no):
- inputFile = File
- row_no=int(row_no)
- col_no=int(col_no)
- with open(inputFile) as ip:
- reader = csv.reader(ip)
- for i, row in enumerate(reader):
- if i == row_no: # here's the row
- #print row[col_no] # here's the column
- return row[col_no]
if i run this function
- qa=go_to_nth_row_nth_column("data.csv",2,1)
- print qa
output is
32
which is 2nd row 1st column
Now, we have created a function, lets use this in robot
framework.
here is how our robot file should look like
Test.robot
- *** Settings ***
- Library csv2.py #both robot and python file is in same folder
-
- *** Test Cases ***
- Test
- Check row column
- Search String
-
- *** Keywords ***
- Check row column
- ${result} = go_to_nth_row_nth_column data.csv 2 1
- log ${result}
*** Settings ****
inside settings section , if python and robot file are with in same folder then you can simple refer the python file as shown below.
When you see the output
This is the way by which you can create your custom
libraries and import in RF.
you have written an excellent blog.. keep sharing your knowledge...
ReplyDeleteRobot Framework Test Automation Training in Chennai
Robot Framework Test Automation Online Training
This comment has been removed by a blog administrator.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteFantabulous content, great guidance
ReplyDeleteSales Classes In Chennai
Sales Training In Chennai
Mmorpg
ReplyDeleteinstagram takipçi satın al
tiktok jeton hilesi
Tiktok Jeton Hilesi
Sac ekimi antalya
İNSTAGRAM TAKİPÇİ SATIN AL
INSTAGRAM TAKİPCİ SATİN AL
metin2 pvp serverlar
takipci satin al
Fon Perde Modelleri
ReplyDeleteNumara Onay
mobil ödeme bozdurma
nft nasıl alınır
ankara evden eve nakliyat
trafik sigortası
dedektör
web sitesi kurma
aşk kitapları
Smm panel
ReplyDeleteSMM PANEL
İs İlanlari Blog
instagram takipçi satın al
hirdavatciburada.com
BEYAZESYATEKNİKSERVİSİ.COM.TR
Servis
Jeton Hilesi İndir
kartal arçelik klima servisi
ReplyDeleteümraniye arçelik klima servisi
tuzla mitsubishi klima servisi
ataşehir vestel klima servisi
çekmeköy bosch klima servisi
ataşehir bosch klima servisi
çekmeköy arçelik klima servisi
ataşehir arçelik klima servisi
maltepe samsung klima servisi