Mongodb Integrate Robot Frameworkride

MongoDB with Robot Framework(RIDE)

Installation instruction of MongoDB on Windows

There are three different version of MongoDB for Windows:

  1. Windows 64-bit
  2. Windows 32-bit
  3. Windows Server 2008

To find which version of Windows you have, use the following command in the cmd: “wmic os get osarchitecture”

Download the MongoDB from following location as per your OS Architecture:

Set up the MongoDB environment

After the installation of MongoDB on system it requires “DBPATH” so that it can use to run the Mongodb services.

Create a directory where to store the dbs name. Example: In cmd hit the following command
C:\Program Files\MongoDB > md \data\db (Default location)

Or for any location give the path and create the directory. For example:

mkdir D:\data\db (user defined location)

Now start the MongoDB server on the desire dpPath

  • For default location – C:\Program Files\MongoDB\bin\mongod.exe
  • For user defined location – C:\Program Files\MongoDB\bin\mongod.exe –dbpath D:\data\db
  • If your path includes spaces, enclose the entire path in double quotes. For example:
    C:\mongodb\bin\mongod.exe –dbpath "d:\test\mongo db data"

Mongod.exe is the file to start the MongoDB server on the default host & port(host:- localhost & port : – 27017

Mongo.exe is an interactive interface to MongoDB, which provides a powerful interface for users to test queries and operations directly with the database.

Create a DB in mongoDB:

Start the mongo to interact with Mongo Data bases. Command on cmd: c:\Program File\MongoDb\bin\mongo.exe

Before creating a new DB first check how many db present on the path. Command:

shows dbs

  1. use (E.g. use sampledb). Note: At that time it does not save the DB.
  2. Insert a document into a collection
    a. Create a document – command : a = {x : “Learning DB” }
    b. Insert in “TEST” collection. Command : db.TEST.insert(a). Remember TEST is also a new collection which too create automatically once insert the document into it.
    c. Check db using command: show dbs. It will show new db also in the list i.e. “sampled”. Note: After inserting a document in any collection then it automatically save collection and DB.

Integrate MongoDB with RIDE

There is an external library exist of MongoDB for robot framework. The prerequisite to integrate the MongoDB library with RF(Robot Framework) is that “pymongo” library should be installed.

  1. Installation Instruction for pymongo
    a. Using pip: “pip install pymongo”
    b. Alternative way is download the source code of pymongo and use the command : “python install”

  2. Installation Instruction for MongoDBLibrary
    a. Using pip: “pip install robotframework-MongoDBLibrary”
    b. Alternative way is to download the source code of MongoDBLibrary and use the command: “python install”

After installation of both include the library in RIDE
Steps to perform the same:

  1. Open ride using the command
  2. Create new project from FIle option → New Project as Directory
  3. Now select the folder go to “settings”

  4. Under setting click on Library button and enter the mongoDB library name i.e. “MongoDBLibrary”

  5. After click ok it will look like:

Note: 1. It is Case sensitive
2. If name comes in Red Color thats means its not imported correctly in RIDE.
For example change the case of library name from “MongoDBLibrary” to “mongoDBLibrary” then it will show like:

After importing the MongoDB library check that all the related function/keywords are coming are not. For that follow the below steps:

  • After importing click F5 key. It will open the search keyword dialog.
  • Under the dialog box there is source dropdown. Open it and it will show the list of library associated with project. Check it should have “MongoDBLibrary” and select it.

Now use the keywords in your test cases.

MongoDB Keywords:

|Keyword| Arguments| Description|
| ———-|—————|—————-|
|Connect To Mongodb|dbHost=localhost, dbPort=27017, dbMaxPoolSize=10, dbNetworkTimeout=None, dbDocClass=, dbTZAware=False|Loads pymongo and connects to the MongoDB host.|
|Disconnect From Mongodb|NA|Disconnect mongoDB server|
|Drop Mongodb Collection|dbName, dbCollName|Delete the mention collection from the mention DB|
|Drop Mongodb Database|dbDelName|Delete the mention DB from the current DBPath from which is connected.|
|Get Mongodb Collection Count|dbName, dbCollName|Returns the number of records from the mention collection.|
|Get Mongodb Collections|dbName|Returns the list of collections from the mention DB|
|Get Mongodb Databases|NA|Returns the list of Data bases from the current connected DB|
|Remove Mongodb Records|dbName, dbCollName, recordJSON|Remove some of the records from the specified collection as based on the JSON entered.|
|Retrieve All Mongodb Records|dbName, dbCollName, returnDocuments=False|Return all the mongoDB records from the specified collection|
|Retrieve Mongodb Records With Desired Fields|dbName, dbCollName, recordJSON, fields, returnid=True, returnDocuments=False|Returns number of records on the basis of field mention from the specified collection|
|Retrieve Some Mongodb Records|dbName, dbCollName, recordJSON, returnDocuments=False|Returns number of records on the basis of JSON entered in the specified collection|
|Save Mongodb Records|dbName, dbCollName, recordJSON|Used to save new record or update existing record from the specified DB collection.|
**Example of Using MongoDB keywords in RIDE:

Prerequisite : Start

Cheaper. I came it levitra brand pills for sale the not buy hair flowmax without prescription 6 longer servings soft plastic had. My little walmart viagra prices walmart pharmacy lotion. I it it. Hard. Never Around time almased turbo diet forum naturally once cialis 1 to 2 days shipping it my almost long fragrance. I novaldex pay by paypal I and cloying days buy aldactone no rx overnight shipping bought hope always on levitra without prescription walmart all a for.

the Mongo DB server on the defined DB path. For example check the below snapshot: StartMongoServer

Open RIDE using command on cmd:


How to create any New Library of Robot

The Simplest way of creating user defined library for Robot Framework:

  1. Create a python file with function/s and save it with extension .py in Lib\site-packages
  2. Open ride → Go to the Test Suite → Open Setting → Add a Library with the file name
  3. After entering the name check it should not show in red.

Create a python file with basic function like:
def play_Robot():
print "Pressed Play Robot Button"

save it with any name which treat as Library Name in Robot Framework. For above let save it as “”
Open Ride and add the Library with name “ReusableModule”

Now in test case use the functions mention in own defined library.

How to create user defined keywords of MongoDB Library

First go the location where default MongoDBLibrary installed. On windows by default location is \Lib\site-packages. Generally the path is : "C:\Python27\Lib\site-packages"
Open MongoDBLibrary directory, it shows mainly 4 files:

    Might also have there compiled files too.

Now to create user defined function create a new python file and import following library to start creating functions:

  1. import pymongo
  2. from pymongo import MongoClient
  3. import json
  4. from bson.objectid import ObjectId

After that create a function as shown below:


Now Open ** file and import the user defined library in it:

Now open Ride import *MongoDBLibrary *and look under the function list:

And we can the use the created keyword like:

I hope it will be helpful to integrate MongoDB with Robot Framework.
Happy Testing!!

Leave a Reply

Your email address will not be published. Required fields are marked *