Skip to content

Instantly share code, notes, and snippets.

@jpita
Last active September 6, 2018 10:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpita/9954138 to your computer and use it in GitHub Desktop.
Save jpita/9954138 to your computer and use it in GitHub Desktop.
testcomplete helpers
/**
* File with all the helper functions
*
* @class helpers
*/
/**
* variable to count the time between actions
* @type {Array}
*/
var StopWatchObj = new Array();
var browserInUse = "iexplore";
function setBrowser(browser)
{
//Default browser is Internet Explorer
//USE:
//"iexplore" for Internet Explorer
//"firefox" for Mozilla Firefox
//"chrome" for Google Chrome
//"safari" for Safari
browserInUse=browser;
}
function clickComponent(propertyName, propertyValue, depth, parentObject)
{
if(parentObject == undefined)
parentObject = Sys.Browser(browserInUse).Page();
if(depth == undefined)
depth = 20;
var object = parentObject.Find(propertyName, propertyValue, depth, true)
object.Click();
return object;
}
function setTextComponent(propertyName, propertyValue,text, depth, parentObject)
{
if(parentObject == undefined)
parentObject = Sys.Browser(browserInUse).Page();
if(depth == undefined)
depth = 20;
var object = parentObject.Find(propertyName, propertyValue, depth, true)
if(object.ObjectType != "TextArea")
object.setText(text);
else
object.Keys(text);
return object;
}
/**
* creates a folder in your log and puts the stepDescription text in your indicator
* @param {string} stepDescription description that goes to the log and indicator
* @method begin
*/
function begin(stepDescription){
startTimer();
Log.AppendFolder(stepDescription);
Indicator.Clear();
Indicator.PushText(stepDescription);
}
function end(){
Indicator.PopText();
stopTimer();
Log.PopLogFolder();
}
function startTimer()
{
StopWatchObj.push(HISUtils.StopWatch);
StopWatchObj[StopWatchObj.length-1].Start();
}
function stopTimer()
{
if(StopWatchObj.length > 0)
{
StopWatchObj[StopWatchObj.length-1].Stop();
if(!aqString.StrMatches("00:00:00", StopWatchObj[StopWatchObj.length-1].ToString()))
{
Log.Message("[TIME SPENT ] "+StopWatchObj[StopWatchObj.length-1].ToString());
}
StopWatchObj.splice(StopWatchObj.length-1, 1);
} // if(StopWatchObj.Exists)
}
function GeneralEvents_OnStopTest(Sender)
{
if(StopWatchObj)
end();
}
function sqlQueryExecute(server, query, uid, pwd)
{
var ConnectionString = "DRIVER=SQL Server;SERVER="+ server +";UID=+"uid"+;PWD=+"pwd;
// Creates a new connection
var ConnDB = ADO.CreateConnection();
var adoRecSet = ADO.CreateRecordset();
ConnDB.ConnectionString = ConnectionString;
ConnDB.Open();
// Opens a recordset
ConnDB.Execute(query);
Log.Message("QUERY EXECUTED")
// Closes the connection
ConnDB.Close();
}
function sqlQuerySelect(server, query, uid, pwd)
{
var ConnectionString = "DRIVER=SQL Server;SERVER="+ server +";UID=+"uid"+;PWD=+"pwd;
// Creates a new connection
var ConnDB = ADO.CreateConnection();
ConnDB.ConnectionString = ConnectionString;
ConnDB.Open();
var resultArray = new Array();
// Opens a recordset
var Tbl = ConnDB.Execute(query);
// Scans all records returned by the query
Tbl.MoveFirst();
var arrIndex = 0;
while (! Tbl.EOF)
{
for (i = 0; i < Tbl.Fields.Count; i++)
{
Log.Message(Tbl.Fields.Item(i).Name +" -> "+Tbl.Fields.Item(i).Value);
resultArray[arrIndex] = Tbl.Fields.Item(i).Value;
}
Tbl.MoveNext();
arrIndex++;
}
// Closes the recordset and the connection
Tbl.Close();
// Closes the recordset and the connection
ConnDB.Close();
return resultArray;
}
/**
* this method tells you the type of object you are working with
* @method objectType
* @param {Object} value object to identify
* @return {string} type of the object
*/
function objectType(value)
{
return Object.prototype.toString.call(value);
}
/**
* method to stop the execution
* @method stopTest
*/
function stopTest(){
Runner.Stop(true);
}
function SendEmail(mFrom, mTo, mSubject, mBody, username, password)
{
var i, schema, mConfig, mMessage;
try
{
schema = "http://schemas.microsoft.com/cdo/configuration/";
mConfig = Sys.OleObject("CDO.Configuration");
mConfig.Fields.Item(schema + "sendusing") = 2; // cdoSendUsingExchange
mConfig.Fields.Item(schema + "smtpserver") = "SMTP server goes here"; // SMTP server
mConfig.Fields.Item(schema + "smtpserverport") = 25; // Port number
mConfig.Fields.Item(schema + "smtpauthenticate") = 1; // Authentication mechanism
mConfig.Fields.Item(schema + "sendusername") = username; // User name (if needed)
mConfig.Fields.Item(schema + "sendpassword") = password; // User password (if needed)
mConfig.Fields.Update();
mMessage = Sys.OleObject("CDO.Message");
mMessage.Configuration = mConfig;
mMessage.From = mFrom;
mMessage.To = mTo;
mMessage.Subject = mSubject;
mMessage.HTMLBody = mBody;
mMessage.Send();
}
catch (exception)
{
Log.Error("E-mail cannot be sent", exception.description);
return false;
}
Log.Message("Message to <" + mTo + "> was successfully sent");
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment