Connecting Tosca with SQL Databases
Connecting Tosca (by Tricentis) with SQL databases is a common requirement in test automation, especially for data validation, test data management, and end-to-end system testing.
Here’s a complete guide to help you understand how to connect Tosca with SQL databases and perform operations like reading and writing data.
π― Use Cases for Tosca-SQL Integration
Use Case Example
Test data preparation Read user data from a database before test
Data validation Compare UI/API values with database results
Test result logging Write test results or statuses to a table
Backend logic testing Validate business rules directly in the DB
π§° Prerequisites
Before connecting:
✅ You need Tosca Commander
✅ The Tosca DB Engines AddIn must be installed
✅ A valid database driver (ODBC) for your SQL type (e.g., SQL Server, Oracle, MySQL)
✅ Appropriate read/write access to the target database
π How Tosca Connects to SQL
Tosca uses TBox DB Engine modules to:
Create connection strings
Execute SQL queries
Use buffer values for dynamic data
π Step-by-Step: Connect Tosca to SQL Database
✅ 1. Open Tosca Commander
Go to the Modules section and ensure TBox DB Engine is available.
If not:
Enable it via Settings > TBox > Engines > DB
✅ 2. Create a New TestCase for Database Interaction
Create a TestCase and add the following modules (drag and drop):
π Module: TBox DB Connection
Property Value (example)
ConnectionString Server=myServer;Database=myDB;User Id=myUser;Password=myPass;
ConnectionName MySQLConnection
ConnectionMode Connect
✅ You can reuse this connection across other steps by referring to the ConnectionName.
✅ 3. Execute a SQL Query
π Module: TBox DB Query
Property Value (example)
ConnectionName MySQLConnection
Query SELECT name FROM users WHERE id = 1
ResultName userName (used as a buffer for later steps)
✔️ The result will be stored in the {userName} buffer.
✅ 4. Use Query Result in Other Test Steps
You can now use {userName} in UI modules or logging like this:
plaintext
Copy
Edit
Validate user name: {userName}
✅ 5. Disconnect (Optional but Recommended)
π Module: TBox DB Connection
Property Value
ConnectionMode Disconnect
π‘ Advanced: Writing to a Database
You can use the same TBox DB Query module to write data:
sql
Copy
Edit
INSERT INTO audit_log (test_case, status) VALUES ('LoginTest', 'Passed')
Or update data:
sql
Copy
Edit
UPDATE users SET status = 'active' WHERE id = 5
Just make sure your user has write permissions.
✅ Best Practices
Tip Why It Matters
Use buffers to manage dynamic data Makes your tests reusable and modular
Use parameterized queries safely Avoid hardcoding and reduce maintenance
Validate DB connection early Catch setup issues before test execution
Use logs or screenshots if needed For traceability in data validation tests
π Sample Connection Strings
SQL Server:
pgsql
Copy
Edit
Server=localhost;Database=TestDB;User Id=testuser;Password=pass123;
MySQL:
ini
Copy
Edit
Server=localhost;Database=testdb;Uid=root;Pwd=admin;
Oracle:
pgsql
Copy
Edit
Data Source=MyOracleDB;User Id=myUsername;Password=myPassword;
You may also use ODBC Data Source Names (DSN) if configured on the machine.
π Summary
Step Module Purpose
Connect to DB TBox DB Connection Set up reusable DB session
Query or modify data TBox DB Query Execute SQL & store in buffer
Use buffer in validation Any UI/API module Dynamic assertion or comparison
Disconnect (optional) TBox DB Connection Release resources
Learn Tosca Training in Hyderabad
Read More
Tosca and qTest: Better Together
Tosca Integration with Azure DevOps Pipelines
How Tosca Integrates with Test Management Tools
Using Tosca with Jenkins for Continuous Testing
Visit Our IHUB Talent Training Institute in Hyderabad
Comments
Post a Comment