SlideShare a Scribd company logo
Test Complete Coding 
Quick guide to using jScript with Test Complete by SmartBear
Create an object/class 
function myLogFileObject() 
{ 
this.myPublicObjectArray = []; 
var myPrivateObjectArray = []; 
var myPrivateCounter = 0; 
this.readFunction=function(); 
return true; 
} 
} 
Why? 
Nice way to organize 
functions and variables 
that represent that object. 
How to use? 
var myObject 
myLogFileObject(); 
myObject.readFunction();
Write to a text file 
var objFSO = new ActiveXObject("Scripting.FileSystemObject"); 
var outFile = objFSO.CreateTextFile(FileNameIncludingPath, 
true,false); 
outFile.WriteLine("Write me to the file"); 
outFile.Close();
Read a file 
var file=fso.OpenTextFile 
(fileLocationAndNameGolden, 
FileReadOnly); 
while (!file.AtEndOfStream){ 
var line=file.ReadLine(); 
}
Try/catch/finally 
try{ 
} 
catch(e){ 
Log.Message(e.description 
); 
} 
Finally{ 
{
Copy a file 
aqFile.Copy 
(FromFullPathINcludingFileName,ToFullPathIncludingFileNa 
me, true)
Iterate through an array 
var myArray = []; 
for(var k=0; k < myArray.length; k++){ 
outFile.WriteLine(myArray[k]); 
}
Switch statement 
switch(){ 
case "": 
{ 
//do 
something 
} 
case2 "" 
{ 
//do 
something 
} 
default: 
{ 
//do 
something 
} 
}
Built in Parameters 
// Built in Parameters 
function ProcessCommandLine(config) { 
for (i = 1; i<= BuiltIn.ParamCount();i++){ 
ProcessCommandLineArgument(BuiltIn.ParamStr(i),config); 
} 
}
Test Complete aqString 
aqString.Replace 
aqString.Trim 
aqString.Find 
aqString.ToLower 
aqString.ChangeListItem 
aqString.GetListItem 
aqString.FindLast 
aqString.GetLength 
aqString.SubSting( 
aqString.GetListLength
Do loop 
do{ 
//some commands 
}while( something is true)
Delete /copy file 
aqFileSystem.DeleteFile(outPath + newFileName + ".xml"); 
aqFileSystem.CopyFile(from, to) 
aqFile.Copy(FromFullPathINcludingFileName,ToFullPathIncl 
udingFileName, true)
Throw error 
//Check that the object isn't null 
if (obj == null) throw "Null object passed to 
generateXMLFromObjectFields";
Push an item to an array 
myArray = []; 
myArray.push(item);
Project variables 
// access test complete project variables 
var MyAppPath=Project.Variables.MyAppPath;
prototype 
//prototype 
var Dog=function(name) { 
this.name = name; 
var barkCount = 0; 
this.bark = function() { 
barkCount++; 
Log.Message(this.name + " 
bark"); 
}; 
this.getBarkCount = function() 
{ 
Log.Message(this.name + " 
has barked " + barkCount + " 
times"); 
};
prototype 
this.wagTail2= function() { 
Log.Message(this.name + " 
wagging tail2"); 
} 
}; 
Dog.prototype.wagTail = function() 
{ 
Log.Message(this.name + " 
wagging tail"); 
}; 
function dog_test(){ 
var dog = new Dog("Dave"); 
dog.bark(); 
dog.bark(); 
dog.getBarkCount(); 
dog.wagTail2(); 
dog.wagTail(); 
}
Extend Array - unique 
//Extend Array to return unique numbers only 
Array.prototype.unique = function() 
{ 
var tmp = {}, out = []; 
for(var i = 0, n = this.length; i < n; ++i) 
{ 
if(!tmp[this[i]]) { tmp[this[i]] = true; out.push(this[i]); } 
} 
return out; 
}
Read xml 
objXMLDoc = 
Sys.OleObject("Msxml2.DOMDocument.6.0") 
objXMLDoc.async = false ; 
objXMLDoc.setProperty("SelectionLanguage","XPath"); 
result=objXMLDoc.load(xmlConfigFile); 
xmlNode=xmlTestConfig.selectSingleNode("TestClass");
Read DOM 6.0 xml 
var objXMLDoc = 
Sys.OleObject("Msxml2.DOMDocument.6.0"); 
objXMLDoc.async = false; 
objXMLDoc.setProperty("SelectionLanguage","XPath"); 
var ns= "xmlns:a='http://smpte-ra. 
org/schemas/2021/2008/BXF'"; 
objXMLDoc.setProperty("SelectionNamespaces", ns); 
ar AsRunList=objXMLDoc.SelectNodes("//a:AsRun");
File functions 
var fso = Sys.OleObject("Scripting.FileSystemObject"); 
var file = fso.GetFile(file_path); 
var fol = fso.GetFolder(folder_path); 
fol.size 
var filesCount = fol.files.Count;
Generate XML from object 
var docSection = Storages.XML(""); 
var colFields = aqObject.GetFields(obj, false); 
var sec = docSection.GetSubSection(root_name);
Connect to UDP 
socket = dotNET.System_Net_Sockets.Socket.zctor( 
dotNET.System_Net_Sockets.AddressFamily.InterNetwork 
, 
dotNET.System_Net_Sockets.SocketType.Dgram, 
dotNET.System_Net_Sockets.ProtocolType.Udp);
SQL Server DB 
Conn = new ActiveXObject("ADODB.Connection"); 
var constr= "Provider=SQLOLEDB.1;Data 
Source=SERVERN;Initial Catalog=cat1;User 
ID=sa;Password=myPassword"; 
Conn.Open(constr); 
var catalogue = new ActiveXObject('ADOX.Catalog'); 
rs = new ActiveXObject("ADODB.Recordset");
Literal Object 
Create a simple constructor that contains the fields for that 
object 
Function User(theParam1){ 
This.param1 = theParam1; 
} 
Extend that object using the Literal prototype feature 
User.prototype = { 
Constructor: User, 
Functoin1: function(theParam2){ …
Shorter if/then 
Variable = (condition) ? True-value : false_value
Object fields and methods 
Var FieldsCol = aqObject.GetFields(Obj); 
Iterate through the fields 
while ( FieldsCol.HasNext() ){ 
Log.Message( FieldsCol.Next().Name ); 
} 
Use this to get the methods: 
aqObject.GetMethods(Obj);

More Related Content

PDF
Great ideas in music distribution
PDF
When and How to Set up a Security Operations Center
DOCX
Trabalho capa
PPTX
Salesforce integration best practices columbus meetup
PPTX
Automation Testing with Test Complete
PPSX
Test Complete
PPTX
Automation Testing with TestComplete
PPT
Script Driven Testing using TestComplete
Great ideas in music distribution
When and How to Set up a Security Operations Center
Trabalho capa
Salesforce integration best practices columbus meetup
Automation Testing with Test Complete
Test Complete
Automation Testing with TestComplete
Script Driven Testing using TestComplete

Viewers also liked (20)

PPT
Testing with test_complete
PPTX
TestComplete – A Sophisticated Automated Testing Tool by SmartBear
PPTX
Test complete, work done so far
PPT
Testing_with_TestComplete
PPT
Keyword Driven Testing using TestComplete
PPTX
TestComplete 7.50 New Features
PDF
social prez - mpcc - mholterhaus
PDF
Web Service Testing using TestComplete
PPTX
Scrum master motivation role
PPTX
AWS CloudFormation Automation, TrafficScript, and Serverless architecture wit...
PPTX
Prioritization by value (DevOps, Scrum)
PDF
Selenium bootcamp slides
PDF
AWS OpsWorks for Chef Automate
ODP
DevOps and Chef improve your life
PDF
Behat bdd training (php) course slides pdf
PDF
Foundation selenium java
PPTX
Gherkin for test automation in agile
PPTX
Continuous test automation
PDF
DbOps, DevOps and Ops
PPTX
Devops Journey - internet tech startup
Testing with test_complete
TestComplete – A Sophisticated Automated Testing Tool by SmartBear
Test complete, work done so far
Testing_with_TestComplete
Keyword Driven Testing using TestComplete
TestComplete 7.50 New Features
social prez - mpcc - mholterhaus
Web Service Testing using TestComplete
Scrum master motivation role
AWS CloudFormation Automation, TrafficScript, and Serverless architecture wit...
Prioritization by value (DevOps, Scrum)
Selenium bootcamp slides
AWS OpsWorks for Chef Automate
DevOps and Chef improve your life
Behat bdd training (php) course slides pdf
Foundation selenium java
Gherkin for test automation in agile
Continuous test automation
DbOps, DevOps and Ops
Devops Journey - internet tech startup
Ad

Similar to Coding using jscript test complete (20)

PPT
JSConf: All You Can Leet
PPTX
Windows 8 JavaScript (Wonderland)
KEY
CoffeeScript - A Rubyist's Love Affair
PPTX
Why learn new programming languages
KEY
JavaScript Growing Up
PDF
JavaScript 1.5 to 2.0 (TomTom)
PDF
Say It With Javascript
PPTX
JavaScript (without DOM)
PPT
File System Object in QTP
PPTX
Dynamic C#
PPTX
11. session 11 functions and objects
PPTX
C# 6 and 7 and Futures 20180607
PPT
Tips and Tricks of Developing .NET Application
PDF
Refactoring In Tdd The Missing Part
PPT
Understanding linq
PPTX
A Test of Strength
PDF
JavaScript - Like a Box of Chocolates
PDF
The Future of JavaScript (Ajax Exp '07)
PDF
Intro to Advanced JavaScript
JSConf: All You Can Leet
Windows 8 JavaScript (Wonderland)
CoffeeScript - A Rubyist's Love Affair
Why learn new programming languages
JavaScript Growing Up
JavaScript 1.5 to 2.0 (TomTom)
Say It With Javascript
JavaScript (without DOM)
File System Object in QTP
Dynamic C#
11. session 11 functions and objects
C# 6 and 7 and Futures 20180607
Tips and Tricks of Developing .NET Application
Refactoring In Tdd The Missing Part
Understanding linq
A Test of Strength
JavaScript - Like a Box of Chocolates
The Future of JavaScript (Ajax Exp '07)
Intro to Advanced JavaScript
Ad

Recently uploaded (20)

PDF
How to Get Funding for Your Trucking Business
PDF
Chapter 5_Foreign Exchange Market in .pdf
PPTX
Amazon (Business Studies) management studies
PPT
340036916-American-Literature-Literary-Period-Overview.ppt
PDF
Elevate Cleaning Efficiency Using Tallfly Hair Remover Roller Factory Expertise
PPTX
HR Introduction Slide (1).pptx on hr intro
PDF
WRN_Investor_Presentation_August 2025.pdf
PDF
Roadmap Map-digital Banking feature MB,IB,AB
PPTX
New Microsoft PowerPoint Presentation - Copy.pptx
PDF
Stem Cell Market Report | Trends, Growth & Forecast 2025-2034
PDF
Laughter Yoga Basic Learning Workshop Manual
DOCX
Euro SEO Services 1st 3 General Updates.docx
PPTX
CkgxkgxydkydyldylydlydyldlyddolydyoyyU2.pptx
DOCX
Business Management - unit 1 and 2
PPTX
AI-assistance in Knowledge Collection and Curation supporting Safe and Sustai...
PDF
Types of control:Qualitative vs Quantitative
PPTX
Belch_12e_PPT_Ch18_Accessible_university.pptx
PDF
DOC-20250806-WA0002._20250806_112011_0000.pdf
PDF
Training And Development of Employee .pdf
PDF
Power and position in leadershipDOC-20250808-WA0011..pdf
How to Get Funding for Your Trucking Business
Chapter 5_Foreign Exchange Market in .pdf
Amazon (Business Studies) management studies
340036916-American-Literature-Literary-Period-Overview.ppt
Elevate Cleaning Efficiency Using Tallfly Hair Remover Roller Factory Expertise
HR Introduction Slide (1).pptx on hr intro
WRN_Investor_Presentation_August 2025.pdf
Roadmap Map-digital Banking feature MB,IB,AB
New Microsoft PowerPoint Presentation - Copy.pptx
Stem Cell Market Report | Trends, Growth & Forecast 2025-2034
Laughter Yoga Basic Learning Workshop Manual
Euro SEO Services 1st 3 General Updates.docx
CkgxkgxydkydyldylydlydyldlyddolydyoyyU2.pptx
Business Management - unit 1 and 2
AI-assistance in Knowledge Collection and Curation supporting Safe and Sustai...
Types of control:Qualitative vs Quantitative
Belch_12e_PPT_Ch18_Accessible_university.pptx
DOC-20250806-WA0002._20250806_112011_0000.pdf
Training And Development of Employee .pdf
Power and position in leadershipDOC-20250808-WA0011..pdf

Coding using jscript test complete

  • 1. Test Complete Coding Quick guide to using jScript with Test Complete by SmartBear
  • 2. Create an object/class function myLogFileObject() { this.myPublicObjectArray = []; var myPrivateObjectArray = []; var myPrivateCounter = 0; this.readFunction=function(); return true; } } Why? Nice way to organize functions and variables that represent that object. How to use? var myObject myLogFileObject(); myObject.readFunction();
  • 3. Write to a text file var objFSO = new ActiveXObject("Scripting.FileSystemObject"); var outFile = objFSO.CreateTextFile(FileNameIncludingPath, true,false); outFile.WriteLine("Write me to the file"); outFile.Close();
  • 4. Read a file var file=fso.OpenTextFile (fileLocationAndNameGolden, FileReadOnly); while (!file.AtEndOfStream){ var line=file.ReadLine(); }
  • 5. Try/catch/finally try{ } catch(e){ Log.Message(e.description ); } Finally{ {
  • 6. Copy a file aqFile.Copy (FromFullPathINcludingFileName,ToFullPathIncludingFileNa me, true)
  • 7. Iterate through an array var myArray = []; for(var k=0; k < myArray.length; k++){ outFile.WriteLine(myArray[k]); }
  • 8. Switch statement switch(){ case "": { //do something } case2 "" { //do something } default: { //do something } }
  • 9. Built in Parameters // Built in Parameters function ProcessCommandLine(config) { for (i = 1; i<= BuiltIn.ParamCount();i++){ ProcessCommandLineArgument(BuiltIn.ParamStr(i),config); } }
  • 10. Test Complete aqString aqString.Replace aqString.Trim aqString.Find aqString.ToLower aqString.ChangeListItem aqString.GetListItem aqString.FindLast aqString.GetLength aqString.SubSting( aqString.GetListLength
  • 11. Do loop do{ //some commands }while( something is true)
  • 12. Delete /copy file aqFileSystem.DeleteFile(outPath + newFileName + ".xml"); aqFileSystem.CopyFile(from, to) aqFile.Copy(FromFullPathINcludingFileName,ToFullPathIncl udingFileName, true)
  • 13. Throw error //Check that the object isn't null if (obj == null) throw "Null object passed to generateXMLFromObjectFields";
  • 14. Push an item to an array myArray = []; myArray.push(item);
  • 15. Project variables // access test complete project variables var MyAppPath=Project.Variables.MyAppPath;
  • 16. prototype //prototype var Dog=function(name) { this.name = name; var barkCount = 0; this.bark = function() { barkCount++; Log.Message(this.name + " bark"); }; this.getBarkCount = function() { Log.Message(this.name + " has barked " + barkCount + " times"); };
  • 17. prototype this.wagTail2= function() { Log.Message(this.name + " wagging tail2"); } }; Dog.prototype.wagTail = function() { Log.Message(this.name + " wagging tail"); }; function dog_test(){ var dog = new Dog("Dave"); dog.bark(); dog.bark(); dog.getBarkCount(); dog.wagTail2(); dog.wagTail(); }
  • 18. Extend Array - unique //Extend Array to return unique numbers only Array.prototype.unique = function() { var tmp = {}, out = []; for(var i = 0, n = this.length; i < n; ++i) { if(!tmp[this[i]]) { tmp[this[i]] = true; out.push(this[i]); } } return out; }
  • 19. Read xml objXMLDoc = Sys.OleObject("Msxml2.DOMDocument.6.0") objXMLDoc.async = false ; objXMLDoc.setProperty("SelectionLanguage","XPath"); result=objXMLDoc.load(xmlConfigFile); xmlNode=xmlTestConfig.selectSingleNode("TestClass");
  • 20. Read DOM 6.0 xml var objXMLDoc = Sys.OleObject("Msxml2.DOMDocument.6.0"); objXMLDoc.async = false; objXMLDoc.setProperty("SelectionLanguage","XPath"); var ns= "xmlns:a='http://smpte-ra. org/schemas/2021/2008/BXF'"; objXMLDoc.setProperty("SelectionNamespaces", ns); ar AsRunList=objXMLDoc.SelectNodes("//a:AsRun");
  • 21. File functions var fso = Sys.OleObject("Scripting.FileSystemObject"); var file = fso.GetFile(file_path); var fol = fso.GetFolder(folder_path); fol.size var filesCount = fol.files.Count;
  • 22. Generate XML from object var docSection = Storages.XML(""); var colFields = aqObject.GetFields(obj, false); var sec = docSection.GetSubSection(root_name);
  • 23. Connect to UDP socket = dotNET.System_Net_Sockets.Socket.zctor( dotNET.System_Net_Sockets.AddressFamily.InterNetwork , dotNET.System_Net_Sockets.SocketType.Dgram, dotNET.System_Net_Sockets.ProtocolType.Udp);
  • 24. SQL Server DB Conn = new ActiveXObject("ADODB.Connection"); var constr= "Provider=SQLOLEDB.1;Data Source=SERVERN;Initial Catalog=cat1;User ID=sa;Password=myPassword"; Conn.Open(constr); var catalogue = new ActiveXObject('ADOX.Catalog'); rs = new ActiveXObject("ADODB.Recordset");
  • 25. Literal Object Create a simple constructor that contains the fields for that object Function User(theParam1){ This.param1 = theParam1; } Extend that object using the Literal prototype feature User.prototype = { Constructor: User, Functoin1: function(theParam2){ …
  • 26. Shorter if/then Variable = (condition) ? True-value : false_value
  • 27. Object fields and methods Var FieldsCol = aqObject.GetFields(Obj); Iterate through the fields while ( FieldsCol.HasNext() ){ Log.Message( FieldsCol.Next().Name ); } Use this to get the methods: aqObject.GetMethods(Obj);

Editor's Notes

  • #20: // read xml file // Now read other test config items from the XML file objXMLDoc = Sys.OleObject("Msxml2.DOMDocument.6.0"); objXMLDoc.async = false ; objXMLDoc.setProperty("SelectionLanguage","XPath"); result=objXMLDoc.load(xmlConfigFile); /* <ITXConfig> <TestConfig> <StartDesktop>False</StartDesktop> <StopDesktop>False</StopDesktop> <ClearWorkspace>True</ClearWorkspace> <KeepLogImages>False</KeepLogImages> <DelayFactor>100</DelayFactor> </TestConfig> </ITXConfig> */ // Report an error, if, for instance, the markup || file structure is invalid if(objXMLDoc.parseError.errorCode != 0){ s = "Reason:" + "\t" + objXMLDoc.parseError.reason + "\r" + "\n" + "Line:" + "\t" + parseInt(objXMLDoc.parseError.line,10) + "\r" + "\n" + "Pos:" + "\t" + parseInt(objXMLDoc.parseError.linePos,10) + "\r" + "\n" + "Source:" + "\t" + objXMLDoc.parseError.srcText // Post an error to the log && exit Log.Error("Cannot parse the document." + s); return false; } var xmlTestConfig =objXMLDoc.SelectSingleNode("//TestConfig"); if(xmlTestConfig==null){ return true; } var xmlDataStr; var xmlNode; /* // Read the TestConfig items from the xml xmlNode=xmlTestConfig.selectSingleNode("TestClass"); if(xmlNode != null){ config.testClass=xmlNode.text; } */ xmlNode=xmlTestConfig.selectSingleNode("StartDesktop"); if(xmlNode != null){ xmlDataStr=xmlNode.text; if(xmlDataStr.toLowerCase() == "true"){ config.startDesktop=true; } else if(xmlDataStr.toLowerCase() == "false"){ config.startDesktop=false; } } var xmlTestClass =objXMLDoc.SelectSingleNode("//TestClass"); config.testClass=(xmlTestClass == null)?"iTXAutoTest":xmlTestClass.Text; xmlTestDescription=objXMLDoc.SelectSingleNode("//TestDescription"); config.scriptComment=(xmlTestDescription == null)?"":xmlTestDescription.Text; var xmlCommands =objXMLDoc.SelectNodes("//Command");
  • #21: //Read DOM6. based XML documents var objXMLDoc = Sys.OleObject("Msxml2.DOMDocument.6.0"); objXMLDoc.async = false; objXMLDoc.setProperty("SelectionLanguage","XPath"); // We need to do this because DOM6.0 is stricter about security and requires a namespace resolution // By delaring an alias to the namespace here in the properties then we can use the alias (a:) in subsequent selects rather than the full namespace string var ns= "xmlns:a='http://smpte-ra.org/schemas/2021/2008/BXF'"; objXMLDoc.setProperty("SelectionNamespaces", ns); var result=objXMLDoc.load(latestAsRunLogFileFullPath); // Report an error, if, for instance, the markup || file structure is invalid if(objXMLDoc.parseError.errorCode != 0){ var s = "[bxf_GetCountAsRunEvents]Reason:\t" + objXMLDoc.parseError.reason + "\r\n" + "Line:\t" + objXMLDoc.parseError.line + "\r\n" + "Pos:\t" + objXMLDoc.parseError.linePos + "\r\n" + "Source:\t" + objXMLDoc.parseError.srcText; // Post an error to the log && exit Log.Error("Cannot parse the document." + s) return -1; } var AsRunList=objXMLDoc.SelectNodes("//a:AsRun");
  • #22: //Get size of filefunction getSizeOfFile(file_path) { var fso = Sys.OleObject("Scripting.FileSystemObject"); var file = fso.GetFile(file_path); return file.Size; } function getNameOfFile(strPath) { var rev = strPath.split("").reverse().join(""); var dotIndex = rev.indexOf(""); var ret = rev.substr(dotIndex, rev.indexOf("\\") - dotIndex); var arr = ret.split("").reverse().join("").split("."); return arr[0]; } function getSizeOfFolder(folder_path) { var fso = Sys.OleObject("Scripting.FileSystemObject"); var fol = fso.GetFolder(folder_path); return fol.Size; } function getNoFilesInFolder(folder_path) { var fso = Sys.OleObject("Scripting.FileSystemObject"); var fol = fso.GetFolder(folder_path); var filesCount = fol.files.Count; return filesCount; }
  • #23: // generate XML from OBject Fields function generateXMLFromObjectFields(obj, root_name, save_path) { //Check that the object isn't null if (obj == null) throw "Null object passed to generateXMLFromObjectFields"; //Get all Fields of the Object var colFields = aqObject.GetFields(obj, false); //Create a new XML document by passing a blank string as the filepath var docSection = Storages.XML(""); //Create the root node var sec = docSection.GetSubSection(root_name); //insert the date sec.SetOption("Date", aqDateTime.Now()); //Create a child node var subSec = sec.GetSubSection("ObjectData"); //Write all fields in the object to the child node while (colFields.HasNext()) { var item = colFields.Next(); if(item.Name != "XMLWriteNested") { if(IsArray(item.Value)) { // var arr = item.Value; // var str = ""; // for(var i = 0; i < arr.length; i++) // { // str += arr[i] + "|"; // } subSec.SetOption(item.Name, item.Value); } else if(GetVarType(item.Value) == 9) { if(IsSupported(item.Value, "OleValue")) { subSec.SetOption(item.Name, item.Value.OleValue); } else if(IsSupported(obj, "XMLWriteNested")) { //insert logic here. } else { subSec.SetOption(item.Name, item.Value); } } else { subSec.SetOption(item.Name, item.Value); } } } //Save the document to the passed filepath docSection.SaveAs(save_path); }
  • #24: //dot.NET sockets UDP // Send Command and Comment to monitor app.. function MonitorMessage(Command,Comment) { var address, port, socket, broadcast, endpoint, byteType, binaryData, maxLength, sendbuf; var binaryRxData; var MonitorAddress=Project.Variables.MonitorAddress; var MonitorPort=Project.Variables.MonitorPort; if(MonitorAddress==null || MonitorAddress=="" || MonitorPort==null || MonitorPort==0) { return false; } socket = dotNET.System_Net_Sockets.Socket.zctor( dotNET.System_Net_Sockets.AddressFamily.InterNetwork, dotNET.System_Net_Sockets.SocketType.Dgram, dotNET.System_Net_Sockets.ProtocolType.Udp); broadcast = dotNET.System_Net.IPAddress.Parse(MonitorAddress); endpoint = dotNET.System_Net.IPEndPoint.zctor_2(broadcast, MonitorPort); byteType = dotNET.System.Type.GetType("System.Byte"); binaryData = dotNET.System_Text.Encoding.ASCII.GetBytes_2(Command + "|" + Comment); socket.SendTo(binaryData, endpoint);a } function MonitorProgress (progressStr) { MonitorMessage("MonitorProgress",progressStr); } function MonitorEnd () { // Don;t shut down remote monitors.. (i.e. if we didn;t start it locally) // Check if monitor has been specified in project variables var MonitorAppPath=Project.Variables.MonitorAppPath; if(MonitorAppPath==null || MonitorAppPath=="") { return false; } MonitorMessage("MonitorEnd",""); } function MonitorTitle (titleStr) { MonitorMessage("MonitorTitle",titleStr); } function test_DelayCountdownWithProgressMonitor(){ ret=DelayCountdownWithProgressMonitor(3000); } function DelayCountdownWithProgressMonitor(milliSecs) { var delay = milliSecs/1000; var countdown = 0; while( countdown < delay ){ aqUtils.Delay(1000); MonitorProgress("Pausing for " + delay + " secs.." + (delay-countdown)); countdown++; } return; }
  • #25: function TestADO() { var Conn, Rs, Fldr; //Fldr = Log.CreateFolder("Authors table"); //Log.PushLogFolder(Fldr); // Creates and opens a connection try { Conn = new ActiveXObject("ADODB.Connection"); var constr= "Provider=SQLOLEDB.1;Data Source=SVRQA1116;Initial Catalog=itx;User ID=sa;Password=Omn1bu51tx"; Log.Message("Provider defult=" + Conn.Provider); // Conn.ConnectionString = constr; Conn.Open(constr); } catch(err) { Log.Error(err.description); return false; } var catalogue = new ActiveXObject('ADOX.Catalog'); catalogue.ActiveConnection = Conn; for(var i = 0; i < catalogue.Tables.Count; i++) { var tab = catalogue.Tables.item(i); for(var j = 0; j < tab.Columns.Count; j++) { Log.Message(tab.Name + " : " + tab.Columns.item(j).Name); } } Conn.Close(); // // Creates and opens a recordset // Rs = new ActiveXObject("ADODB.Recordset"); // //Rs.Open("Authors", Conn, 3 /* adOpenStatic */, // //1 /* adLockReadOnly */, 2 /* adCmdTable */); // // // Processes data // Rs.MoveFirst(); // // while(!Rs.EOF) // { // Log.Message(Rs.Fields.Item("Author").Value); // Rs.MoveNext(); // } // // // Closes the recordset and connection // Rs.Close(); } function getDataFromDB(strQuery) { var conn = new ActiveXObject("ADODB.Connection"); var connStr = "Provider=SQLOLEDB.1;Data Source=SVRQA1116;Initial Catalog=itx;User ID=sa;Password=Omn1bu51tx"; try { conn.Open(connStr); } catch (err) { Log.Error('Cannot open connection to database'); return; } var rs = new ActiveXObject("ADODB.Recordset"); try { rs.Open(strQuery, conn); } catch (err) { conn.Close(); throw err; } var res = []; if(!rs.EOF) { rs.MoveFirst(); var titles = []; for(var i = 0; i < rs.Fields.Count; i++) { titles.push(rs.Fields(i).Name); } res.push(titles); while(!rs.EOF) { var row = [] for(var i = 0; i < rs.Fields.Count; i++) { row.push(rs.Fields(i).Value); } res.push(row); rs.MoveNext(); } } rs.Close(); conn.Close(); return res; } function recordExistsInDB(strAssetName, strType) { var table = ""; var column = ""; switch(strType.toUpperCase()) { case 'VIDEO': table = "Opus_VideoClip_VCP"; column = "VCP_Name" break; case 'AUDIO': table = "Opus_AudioClip_ACP"; column = "ACP_Name" break; case 'LOGO': table = "Opus_Logo_LGO"; column = "VCP_Name" break; case 'GRAPHICS': table = "Opus_Graphic_GFX"; column = "VCP_Name" break; case 'SCHEDULE': table = "Opus_Schedule_SCH"; column = "VCP_Name" break; default: var err = new Error(); err.description = "could not resolve type string " + strType + ". Valid options are 'video', 'audio', 'logo', 'graphics' and 'schedule'."; throw err } var strQuery = "SELECT 1 FROM [ITX].[dbo].[" + table + "] WHERE [" + column + "] = '" + strAssetName + "'" var conn = new ActiveXObject("ADODB.Connection"); var connStr = "Provider=SQLOLEDB.1;Data Source=SVRQA1116;Initial Catalog=itx;User ID=sa;Password=Omn1bu51tx"; try { conn.Open(connStr); } catch (err) { Log.Error('Cannot open connection to database'); return; } var rs = new ActiveXObject("ADODB.Recordset"); try { rs.Open(strQuery, conn); } catch (err) { conn.Close(); throw err; } var exists = !rs.EOF rs.Close(); conn.Close(); return exists; } function DB_GetVideoAssetData(strAssetName) { return getDataFromDB("SELECT * FROM [ITX].[dbo].[Opus_VideoClip_VCP] WHERE [VCP_Name] = '" + strAssetName + "'"); } function DB_GetAudioAssetData(strAssetName) { return getDataFromDB("SELECT * FROM [ITX].[dbo].[Opus_AudioClip_ACP] WHERE [ACP_Name] = '" + strAssetName + "'"); } function DB_GetLogoAssetData(strAssetName) { return getDataFromDB("SELECT * FROM [ITX].[dbo].[Opus_Logo_LGO] WHERE [LGO_Name] = '" + strAssetName + "'"); } function DB_GetGraphicsAssetData(strAssetName) { return getDataFromDB("SELECT * FROM [ITX].[dbo].[Opus_Graphic_GFX] WHERE [GFX_Name] = '" + strAssetName + "'"); } function DB_GetScheduleAssetData(strAssetName) { return getDataFromDB("SELECT * FROM [ITX].[dbo].[Opus_Schedule_SCH] WHERE [SCH_Name] = '" + strAssetName + "'"); } function tstDBAccess() { var a = DB_GetVideoAssetData('AET-CMAP-000236'); var b = DB_GetAudioAssetData('BNE015_2'); var c = DB_GetGraphicsAssetData('20th_Century_Fox'); var d = DB_GetLogoAssetData('20th_Century_Fox'); var e = DB_GetScheduleAssetData('SVRQA1117'); e; } function tstdoesExist() { var s = recordExistsInDB('BNE015_1', 'audio'); }
  • #26: http://blog.pluralsight.com/the-prototype-pattern-structuring-javascript-code-part-ii http://javascriptissexy.com/oop-in-javascript-what-you-need-to-know/?WPACFallback=1&WPACRandom=1418040605766 Implementation of Combination Constructor/Prototype Pattern The User Function: I will explain each line. function User (theName, theEmail) { this.name = theName; this.email = theEmail; this.quizScores = []; this.currentScore = 0; } User.prototype = { constructor: User, saveScore:function (theScoreToAdd) { this.quizScores.push(theScoreToAdd) }, showNameAndScores:function () { var scores = this.quizScores.length > 0 ? this.quizScores.join(",") : "No Scores Yet"; return this.name + " Scores: " + scores; }, changeEmail:function (newEmail) { this.email = newEmail; return "New Email Saved: " + this.email; } } Make Instances of the User function // A User firstUser = new User("Richard", "Richard@examnple.com"); firstUser.changeEmail("RichardB@examnple.com"); firstUser.saveScore(15); firstUser.saveScore(10); firstUser.showNameAndScores(); //Richard Scores: 15,10 // Another User secondUser = new User("Peter", "Peter@examnple.com"); secondUser.saveScore(18); secondUser.showNameAndScores(); //Peter Scores: 18
  • #28: function GettingObjectProperties(Obj) { // Obtains the fields collection var FieldsCol = aqObject.GetFields(Obj); Log.Message("The fields are:"); // Posts the fields names to the test log while ( FieldsCol.HasNext() ){ Log.Message( FieldsCol.Next().Name ); } // Obtains the collection of methods var colMethods = aqObject.GetMethods(Obj); Log.Message("The methods are:"); while (colMethods.HasNext()){ Log.Message(colMethods.Next().Name); } }