I am trying to connect the DB for testing web elements that have dependencies on data, and in general to add some reliable BE testing.
Currently I have cypress.config.js:
// cypress.config.js
const { defineConfig } = require("cypress");
const sql = require('mssql');
const dbConfig = require("./db_config");
const TEST_CREDENTIALS = require("./cypress.env.json");
module.exports = defineConfig({
projectId: "iu4xc2",
e2e: {
baseUrl: "",
viewportWidth: 1400,
viewportHeight: 900,
setupNodeEvents(on, config) {
on('task', {
async testDbConnection() {
let connectionStatus = false;
try {
console.log('Attempting to connect to the database...');
await sql.connect(dbConfig)
connectionStatus = true;
console.log('✅ Database connection successful!');
return connectionStatus
} catch (err) {
console.error('❌ Database Connection FAILED:', err.message);
throw new Error(`DB Connection Error: ${err.message}`);
} finally {
sql.close();
console.log('Connection closed.');
}
}
})
.
.
.
video: false,
screenshotOnRunFailure: true,
chromeWebSecurity: false,
watchForFileChanges: false,
},
});
and db_config:
// db_config.js
module.exports = {
// Use the Server Name from your image
server: '*******',
user: '*******',
password: '*************',
database: '<default>',
options: {
encrypt: true,
trustServerCertificate: true,
}
};
I can't connect using SQL Server but same credentials connects with SSMS and with the SQL Server extension on VS Code as well.
What is going wrong here?