Drop Database using JScript in TestComplete w/ MongoDB?
So I am working on a script in TestComplete where I have a scenario where I need to drop a database on MongoDB, but I am having a lot of trouble and wanted to get others opinion.
So let's say that I have the following "dropDatabase" function using JScript:
function dropDatabase(hostName, port, userName, password, databaseName) {
var conn = null;
var cmd = null;
try {
conn = ADO.CreateADOConnection();
var connectionString = "Provider=SQLOLEDB.1;Data Source=" + hostName + "," + port + ";User ID=" + userName + ";Password=" + password;
conn.Open(connectionString);
cmd = ADO.CreateCommand();
cmd.CommandText = "DROP DATABASE " + databaseName;
cmd.Execute();
Log.Message("Database dropped successfully.");
} catch (e) {
Log.Error("An error occurred while dropping the database: " + e.message);
} finally {
if (cmd != null) {
cmd = null;
}
if (conn != null) {
conn.Close();
conn = null;
}
}
}
I then have a "Then" Cucumber step definition as the following:
Then("I drop the database if \"dbEmpty\" is false", function() {
if (globalDbEmptyValue === undefined) {
Log.Error("The value of \"dbEmpty\" was not fetched.");
} else if (globalDbEmptyValue === false) {
Log.Message("The value of \"dbEmpty\" is false.");
dropDatabase("test.com", "12345", "mongo", "mongo", "Example")
} else {
Log.Message("The database was not dropped because \"dbEmpty\" is not false.");
}
});
But anytime I run the scenario, it crashes due to a "Login window" popping up for credentials, which is giving me indications that it's having a hard time creating a proper MongoDB connection.
All I need to do it to be able to make a proper connection so that I can drop the "Example" database.
Could someone give me some pointers? When I use the credentials from the example "dropDatabase" function, I am able to create a successful MongoDB connection using MongoDBCompass.
Thanks all!