The usage of MongoDB is growing and a lot of different solutions are built on the database. By introducing the Database building block Leaptest gives direct access to data in MongoDB to prepare test of these systems, to validate results without accessing the UI etc.
In this post I’ll walk through how to use the Database building block with MongoDB.

Database building blockdatabase_bb_basic_sml

The Database block was introduced with version 1.0.36 and is using the ODBC interface to integrate with a wide range of databases, ranging from the classical relational databases (RDBMS) to the newer NoSQL databases.

The Database block has a Connection property that should hold the name of the ODBC DSN (see later). The Query property should contain the query to be executed (following the ODBC standards).

Once the Connection and the Query are specified, the columns returned from the query will be added to the Database building block by clicking Refresh.

MongoDB

In order to use the Database building block with MongoDB, I installed a MongoDB v3.2.10 Community server downloaded from https://www.mongodb.com/download-center. I could also have used a cloud hosted MongoDB instance (Amazon, Azure etc.) which is the same setup.

Using a tool like MongoChef I have imported the following data into a new collection, ‘Customers’ in the MongoDB:

firstName

lastName

phone

Fiona

Hogan

319-9099

Robert

Wiggins

1-554-847-2734

Nolan

Quinn

1-398-818-0984

Jennifer

Reid

1-903-752-5103

Alea

Beard

212-1883

Heather

Bender

831-2152

Melissa

Serrano

976-9118

Mari

Head

591-9308

Victoria

Barker

759-7069

ODBC

There are several ODBC drivers for MongoDB on the market. I have used the driver from Simba, which had a simple and intuitive installation and licensing model. Other providers of ODBC drivers to MongoDB are Easysoft and Progress.

Once installed you can create a ODBC DSN (Data Source Name) by opening the “ODBC Data Source Administrator” from the Control Panel and adding a new “User DSN”.

Select the “Simba MongoDB ODBC Driver” and click Finish.

In the DNS setup specify the DSN (the Connection property in the Database building block. In this case ‘LeaptestMongo’), server name, port and the database to use. In this case I’m running local on the default port (27017). End by clicking “Test” to verify if the ODBC connection is working as it should.

Setting up the Database building block with MongoDB

In the Database building block I have specified the name of the ODBC DSN created previously. Further I have added a simple query returning all rows from the Customer collection.

By clicking Refresh the data is collected from MongoDB and columns in dataset returned are added as properties to the building block.

database_bb_mongo

Iterating all the customer data in the MongoDB gave the following result (click to enlarge the image) :

mongo_example

I can now use the standard features of Leaptest to select the “First row”, take a specific row or iterate all of the rows or I can use the query to select a specific record from the database:

mongo_example_where_clause

Conclusion

If your system under test is built on MongoDB you can use the Database building block to ensure data is ready before the test and to do verification as part of the test. The Database block enables to select individual rows, to do complex queries and to iterate a full dataset as part of a test run.

Learn more about codeless test automation with Leaptest

TRY LEAPTEST FREE
LEARN MORE