cypress: Unable to connect multiple DB
Current behavior:
I have tests to execute SQL queries to two DB under same server Select * from customers - execute in DB Customers Select * from roles - execute in DB identity.
I have used Cypresses-Sql-Server which is given here https://www.npmjs.com/package/cypress-sql-server
created two DB configuration, but it always ended with executing query in database identity. Fails all the test cases which are in database Customers.
Is there a way to connect and work with Multiple DB.
Test code to reproduce
plugins\index.js
database = require('./database');
databaseIdentity = require('./identityDatabase')
const sqlServer = require('cypress-sql-server');
const sqlIdentityServer = require('cypress-sql-server')
module.exports = (on, config) => {
var dbconfig = database(on, config);
sqlTask = sqlServer.loadDBPlugin(dbconfig);
on('task', sqlTask);
var dbconfig1 = databaseIdentity(on, config);
tasks = sqlServer.loadDBPlugin(dbconfig1);
on('task', tasks);
};
support - index.js:
import sqlServer from 'cypress-sql-server';
Cypress.Commands.add(sqlServer, sqlServer.loadDBCommands())
Plugins\database.js
var dbconfig = {
server: "ddddddddddd",
port:yourport,
userName: "dfdsfdsf",
password: "xxxxxxxxxx",
options: {
database: Customers,
encrypt: true,
rowCollectionOnRequestCompletion : true
}
};
return dbconfig;
Plugins\identityDatabase.js (deleted original values)
var dbconfig = {
server: "dddddddddd",
port: yourPort,
userName: "dddddddddddd",
password: "xxxxxxxxx",
options: {
database: Orders,
encrypt: true,
rowCollectionOnRequestCompletion : true
}
};
return dbconfig;
TestCase:
cy.task('sql.server:execute':'select * from Customers').then(output=>
{
})
Failing with error Customers not found.
Versions
Cypress - 4.1.0
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (1 by maintainers)
@djpasch Thanks you so much!!
I had the same problem like @isabellemr had with index.js. But the problem was what I used the last version of Tedius with the last version not work but if you use the same version 8.3.0 for tedious and 2.5.1 for coffeescript this works. Then before what you write “npm install” you should write this:
package.json:
“dependencies”: { “coffeescript”: “^2.5.1”, “tedious”: “^8.3.0” },
And later when you write “npm install”. This will make it install with the same version that @djpasch proposes.
The result in my case was here! This works perfectly well!!!
Finally. If you use this comand “npm install tedious” don’t works because for a weird reason with the last version don’t work for me.
This was my result with the last version. This not work 😦
Hope this is some help to everyone who is frustrated with this.
Regards!
I have a solution for you. cypress-sql-server is using Tedious. So you could use Tedious directly. The following code is based on cypress-sql-server
Install Tedious
package.json:
plugins/index.js
support/command.js
cypress.json (config)
Application code could then use:
Any suggestions for improvement are welcome.
Good to hear it’s working for you!