Sick of writing same query

March 3rd, 2010 by andrei

I’m currently working on a DataWarehouse project which implies writing a lot of select, insert, delete queries over and over again mostly against SQLServer and Oracle environments …. when I decided to write a Jscript function using TestComplete.

I prefer populating the function data with the needed parameters than writing the query from the start.

Here’s a short, still dumb, example for SQLServer which might inspire you:

function Main()
{
try
{
// Enter your code here.
insertUser(“\’auto2\’”,”\’fn2\’”,”\’ln2\’”);
}
catch(exception)
{
Log.Error(“Exception”, exception.description);
}
}

function insertUser(username,fn,ln)
{

TestedApps.cmd.Run();
Aliases.cmd.wndSQLCMD.Drag(503, 13, -52, -5);
Aliases.cmd.wndSQLCMD.Click(653, 10);
TestedApps.cmd.Run();
Aliases.cmd.wndConsoleWindowClass.Keys(“sqlcmd -S localhost\\SQLEXPRESS -E[Enter]“);
Aliases.cmd.wndConsoleWindowClass.Keys(“use users[Enter]go[Enter]select * from tbl_users;[Enter]go[Enter]“);
Aliases.cmd.wndConsoleWindowClass.Keys(“insert into tbl_users values ” +
“(’4′”+”,” + username  + “,”+fn+”,”+ln + “,” + “‘mail@qa.com’,’25′)”   +
“[Enter]go[Enter]“);

Aliases.cmd.wndSQLCMD.Keys(“go[Enter]select * from tbl_users[Enter]go[Enter]“);
}

Enjoy QA!

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes