I have been trying to connect to MSSQL database using node module in my protractor tests. I tried both the methods below but each time I am either getting undefined is not a function or getting cannot read property of "query/execute".
Error: [launcher] Running 1 instances of WebDriver
[launcher] Error: TypeError: undefined is not a function
at exports.config.onPrepare (....\conf\Conf.js:39:28)
I have my connection defined in conf.js
var HtmlReporter = require('protractor-html-screenshot-reporter');
var mysql = require('../node_modules/mssql');
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub', //desktop
allScriptsTimeout: 40000,
baseUrl: 'https://myurl.com/#/',
// frameworks to use
frameworks: 'jasmine',
//Capabilities to be passed to the webdriver instance.
multiCapabilities: [{
'browserName': 'chrome'
// }, {
// 'browserName': 'firefox'
//},
// {
// 'browserName': 'internet explorer'
}],
// Spec patterns are relative to the current working directory.
specs: [
'../tests/HomePage.js'
],
onPrepare: function() {
var sql = require('mssql/');
var config = {
server : '*****',
user : 'myusername',
password : 'pass',
database: 'mydb'
};
browser.driver.manage().window().maximize();
jasmine.getEnv().addReporter(new HtmlReporter({
baseDirectory: '/MyDirectory/screenshots'
}));
},
jasmineNodeOpts: {
showColors: true
}
};
In my Test, I did the following: test.js
describe ( " page test , function() {
it('Should add customer', function() {
blah blah....
});//This click will create a record in the backend
// I am attempting to get the record:
function runQuery() {
var connection = new sql.Connection(config, function(err) {
var request = new sql.Request(connection); // or: var request = connection.request();
request.query('select top 1 as result from customers', function(err, recordset) {
// ... error checks
console.log("this is the request: " + request);
console.dir(recordset);
});
});
};
I used dqlserver unofficial and it worked pretty well. We use Windows authentication to login to MSSQL studio so use the below.
Download MSSQL Unofficial package from here:
https://www.npmjs.com/package/node-sqlserver-unofficial