e2e 自动化集成测试 架构 实例 WebStorm Node.js Mocha WebDrive
e2e 自动化集成测试 架构 京东 商品搜索 实例 WebStorm Node.js Mocha WebDriverIO Selenium Step by step 二 图片验证码的识别 , 下面讲一下Node.js中如何访问数据库, 在做自动化测试过程中, 经常可能遇到需要到数据库取值,或是更新值。来验证页面上的
e2e 自动化集成测试 架构 京东 商品搜索 实例 WebStorm Node.js Mocha WebDriverIO Selenium Step by step 二 图片验证码的识别”,
下面讲一下Node.js中如何访问数据库, 在做自动化测试过程中, 经常可能遇到需要到数据库取值,或是更新值。来验证页面上的数据正确性。 之前,在google, baidu.com上找了非常多的文章关于Node.js如何访问Sql Server的文章, 都是不行的, 我想是因为, Node.js的开源性, 对于MongoDB, Mysql, 等数据库访问是有请多的模块支持。但对于Sql server就只有微软写的驱动, 但是由于安装非常复杂, 我就没安装成功过。 最后,在baidu.com的时候,找到了一个牛人写的模块叫 mssqlhelper https://www.npmjs.org/package/mssqlhelper, 虽然有蛮多的不支持, 但是对于一些简单的sql操作,还是可以的。
如下是Node.js使用, 我将它们做了一下封装,可以提供select, add, delete,update操作
var db = require('./dbHelper');
function select(sqlScript, EntityName, topNum, callback)
{
if(topNum == null)
{
topNum = '';
}
if(topNum == '')
{
sqlScript = sqlScript.replace('select', 'select @Param1 Parmal1, ')
}
else
{
sqlScript = sqlScript.replace('select', 'select top '+ topNum +' @Param1 Parmal1, ')
}
db.config({
host: 数据库地址
,port: 1433
,userName: 用户名
,password: 密码
,database: 数据库名
});
console.log('执行 SQL ' + sqlScript.green);
db.query( sqlScript
,{
Param1: { type : 'NVarChar', size: 7,value : 'systemDefault' }
}
,function(res){
if(res.err)throw new Error('database error:'+res.err.msg);
if(res.tables.length == 0){
console.log('无任何记录返回');
//hrow new Error('无任何记录返回');
return;
}
var rows = res.tables[0].rows;
if(rows.length == 0){
callback('');
}
else {
var jsonString = toJson(res.tables[0], EntityName);
var result = JSON.parse(jsonString);
console.log('数据库查询结果' + jsonString.green);
callback(result);
// var columnLength = rows[0].metadata.columns.length;
// for (var i = 0; i // console.log(rows[i].getValue('Name'));
// }
}
}
);
};
function exeScript(sqlscript, callback){
db.query(
sqlscript
,{
}
,function(res){
if(res.err)throw new Error('database error:'+res.err.msg);
callback();
}
);
};
function del(sqlscript,callback){
exeScript(sqlscript,callback);
}
function update(sqlscript,callback){
exeScript(sqlscript,callback);
}
function add(sqlscript,callback){
exeScript(sqlscript,callback);
}
//convert table to json
function toJson(data, entityName)
{
var jsonString;
if (data != undefined && data.rows.length > 0)
{
var rowLen=data.rows.length;
var colLen=data.rows[0].metadata.columns.length;
jsonString="{";
jsonString+="\""+entityName+"\":[";
for (var i = 0; i {
jsonString+="{";
for (var j = 1; j {
if (j {
jsonString+="\"" + data.rows[0].metadata.columns[j].name + "\":" + "\"" + data.rows[i].getValue(j)+ "\",";
}
else if (j == colLen - 1)
{
//console.log(j + ' ' + i );
jsonString+="\"" + data.rows[0].metadata.columns[j].name + "\":" + "\"" + data.rows[i].getValue(j) + "\"";
}
}
if (i == rowLen - 1)
{
jsonString+="}";
}
else
{
jsonString+="},";
}
}
jsonString+="]}";
return jsonString;
}
return jsonString;
}
exports.Add=add;
exports.Delete=del;
exports.Update=update;
exports.Select=select;

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

To restart WebStorm, follow these steps: Use the shortcut keys: Windows/Linux: Ctrl + Shift + A, macOS: Cmd + Shift + A. Enter "restart" in the search field and select "Restart". Using the menu: Click the File menu and select Restart under Reload. Using Task Manager: In Task Manager or Force Quit the application window, select the WebStorm process and click Restart or Restart.

For developers who focus on web development and pursue deep functionality, WebStorm is a better choice; while users who value customizability, lightweightness, and multi-language support are more suitable for VSCode.

Automatic line wrapping can be set in WebStorm by following these steps: Check the "Wrap lines" checkbox and set the maximum line width. Select automatic line wrapping rules: None, line wrapping at any position, or line wrapping after keywords. Optional settings: retain manual line wrapping and automatic line wrapping after carriage return. Apply the settings and close the settings window. Note: This setting applies to all file types and can be set individually for specific file types.

WebStorm is tailor-made for web development and provides powerful features for web development languages, while IntelliJ IDEA is a versatile IDE that supports multiple languages. Their differences mainly lie in language support, web development features, code navigation, debugging and testing capabilities, and additional features. The final choice depends on language preference and project needs.

Steps to launch UniApp project preview in WebStorm: Install UniApp Development Tools plugin Connect to device settings WebSocket launch preview

SpringDataJPA is based on the JPA architecture and interacts with the database through mapping, ORM and transaction management. Its repository provides CRUD operations, and derived queries simplify database access. Additionally, it uses lazy loading to only retrieve data when necessary, thus improving performance.

The main differences between Navicat and DataGrip are: Supported databases: Navicat supports more than 30, while DataGrip focuses on JetBrains databases. Integration: DataGrip is tightly integrated with JetBrains tools, while Navicat has limited integration. Collaboration features: DataGrip offers code review and collaboration features, while Navicat does not.

The "Inaction Test" of the new fantasy fairy MMORPG "Zhu Xian 2" will be launched on April 23. What kind of new fairy adventure story will happen in Zhu Xian Continent thousands of years after the original work? The Six Realm Immortal World, a full-time immortal academy, a free immortal life, and all kinds of fun in the immortal world are waiting for the immortal friends to explore in person! The "Wuwei Test" pre-download is now open. Fairy friends can go to the official website to download. You cannot log in to the game server before the server is launched. The activation code can be used after the pre-download and installation is completed. "Zhu Xian 2" "Inaction Test" opening hours: April 23 10:00 - May 6 23:59 The new fairy adventure chapter of the orthodox sequel to Zhu Xian "Zhu Xian 2" is based on the "Zhu Xian" novel as a blueprint. Based on the world view of the original work, the game background is set
