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

Viewers also liked (20)

PPT
Script Driven Testing using TestComplete
srivinayak
 
PPT
Testing with test_complete
binuiweb
 
PPTX
TestComplete – A Sophisticated Automated Testing Tool by SmartBear
Software Testing Solution
 
PPTX
Test complete, work done so far
Leonel More, CSM, PMP, ITIL
 
PPT
Testing_with_TestComplete
Samanuru G Chakravarthy
 
PPT
Keyword Driven Testing using TestComplete
srivinayak
 
PPTX
TestComplete 7.50 New Features
Vlad Kuznetsov
 
PDF
social prez - mpcc - mholterhaus
mholterhaus
 
PDF
Web Service Testing using TestComplete
srivinayak
 
PPTX
Scrum master motivation role
Viresh Doshi
 
PPTX
AWS CloudFormation Automation, TrafficScript, and Serverless architecture wit...
PolarSeven Pty Ltd
 
PPTX
Prioritization by value (DevOps, Scrum)
Tommy Quitt
 
PDF
Selenium bootcamp slides
seleniumbootcamp
 
PDF
AWS OpsWorks for Chef Automate
PolarSeven Pty Ltd
 
ODP
DevOps and Chef improve your life
Juan Vicente Herrera Ruiz de Alejo
 
PDF
Behat bdd training (php) course slides pdf
seleniumbootcamp
 
PDF
Foundation selenium java
seleniumbootcamp
 
PPTX
Gherkin for test automation in agile
Viresh Doshi
 
PPTX
Continuous test automation
Viresh Doshi
 
PDF
DbOps, DevOps and Ops
Eduardo Piairo
 
Script Driven Testing using TestComplete
srivinayak
 
Testing with test_complete
binuiweb
 
TestComplete – A Sophisticated Automated Testing Tool by SmartBear
Software Testing Solution
 
Test complete, work done so far
Leonel More, CSM, PMP, ITIL
 
Testing_with_TestComplete
Samanuru G Chakravarthy
 
Keyword Driven Testing using TestComplete
srivinayak
 
TestComplete 7.50 New Features
Vlad Kuznetsov
 
social prez - mpcc - mholterhaus
mholterhaus
 
Web Service Testing using TestComplete
srivinayak
 
Scrum master motivation role
Viresh Doshi
 
AWS CloudFormation Automation, TrafficScript, and Serverless architecture wit...
PolarSeven Pty Ltd
 
Prioritization by value (DevOps, Scrum)
Tommy Quitt
 
Selenium bootcamp slides
seleniumbootcamp
 
AWS OpsWorks for Chef Automate
PolarSeven Pty Ltd
 
DevOps and Chef improve your life
Juan Vicente Herrera Ruiz de Alejo
 
Behat bdd training (php) course slides pdf
seleniumbootcamp
 
Foundation selenium java
seleniumbootcamp
 
Gherkin for test automation in agile
Viresh Doshi
 
Continuous test automation
Viresh Doshi
 
DbOps, DevOps and Ops
Eduardo Piairo
 

Similar to Coding using jscript test complete (20)

PPT
JSConf: All You Can Leet
johndaviddalton
 
PPTX
Windows 8 JavaScript (Wonderland)
Christopher Bennage
 
KEY
CoffeeScript - A Rubyist's Love Affair
Mark
 
PPTX
Why learn new programming languages
Jonas Follesø
 
KEY
JavaScript Growing Up
David Padbury
 
PDF
JavaScript 1.5 to 2.0 (TomTom)
jeresig
 
PDF
Say It With Javascript
Giovanni Scerra ☃
 
PPTX
JavaScript (without DOM)
Piyush Katariya
 
PPT
File System Object in QTP
Praveen Gorantla
 
PPTX
Dynamic C#
Antya Dev
 
PPTX
11. session 11 functions and objects
Phúc Đỗ
 
PPTX
C# 6 and 7 and Futures 20180607
Kevin Hazzard
 
PPT
Tips and Tricks of Developing .NET Application
Joni
 
PDF
Refactoring In Tdd The Missing Part
Gabriele Lana
 
PPT
Understanding linq
Anand Kumar Rajana
 
PPTX
A Test of Strength
Chris Oldwood
 
PDF
JavaScript - Like a Box of Chocolates
Robert Nyman
 
PDF
The Future of JavaScript (Ajax Exp '07)
jeresig
 
PDF
Intro to Advanced JavaScript
ryanstout
 
JSConf: All You Can Leet
johndaviddalton
 
Windows 8 JavaScript (Wonderland)
Christopher Bennage
 
CoffeeScript - A Rubyist's Love Affair
Mark
 
Why learn new programming languages
Jonas Follesø
 
JavaScript Growing Up
David Padbury
 
JavaScript 1.5 to 2.0 (TomTom)
jeresig
 
Say It With Javascript
Giovanni Scerra ☃
 
JavaScript (without DOM)
Piyush Katariya
 
File System Object in QTP
Praveen Gorantla
 
Dynamic C#
Antya Dev
 
11. session 11 functions and objects
Phúc Đỗ
 
C# 6 and 7 and Futures 20180607
Kevin Hazzard
 
Tips and Tricks of Developing .NET Application
Joni
 
Refactoring In Tdd The Missing Part
Gabriele Lana
 
Understanding linq
Anand Kumar Rajana
 
A Test of Strength
Chris Oldwood
 
JavaScript - Like a Box of Chocolates
Robert Nyman
 
The Future of JavaScript (Ajax Exp '07)
jeresig
 
Intro to Advanced JavaScript
ryanstout
 
Ad

More from Viresh Doshi (6)

PPTX
DevOps terms for 2018
Viresh Doshi
 
PPTX
Ansible top 10 - 2018
Viresh Doshi
 
PPTX
Scrum master's role - top 20 challenges
Viresh Doshi
 
PPTX
Devops Journey - internet tech startup
Viresh Doshi
 
PDF
Capital markets testing - Calypso
Viresh Doshi
 
PDF
Collaboration in testing
Viresh Doshi
 
DevOps terms for 2018
Viresh Doshi
 
Ansible top 10 - 2018
Viresh Doshi
 
Scrum master's role - top 20 challenges
Viresh Doshi
 
Devops Journey - internet tech startup
Viresh Doshi
 
Capital markets testing - Calypso
Viresh Doshi
 
Collaboration in testing
Viresh Doshi
 
Ad

Recently uploaded (20)

PDF
SAG Infotech Issues Press Release for Media and Publications
SAG Infotech
 
PDF
Walt Disney Business Proposal for Hollywood Studios
balazscsillag
 
PDF
Global Media Planning and Buying Market Trends 2025
Rupal Dekate
 
PDF
Toolszen SEO Tools Group Buy 2026 India.pdf
Group Buy Seo Tools
 
PDF
Albaik Franchise All Information Update.pdf
AL-Baik Franchise
 
PDF
How is IMSLP Wagner Connected with Pachelbel & Shostakovich.pdf
SheetMusic International
 
PDF
Thane Stenner - A Leader In Extreme Wealth Management
Thane Stenner
 
PDF
PTAC Repair Near Me | Heating and Cooling
angisonairnyc
 
PDF
Netflix Social Watchlists Business Proposal
lexarofficial222
 
PPTX
Vedanta’s Pivotal Role in India’s Growth with Record Vedanta Tax Contribution...
Vedanta Cases
 
PPTX
The Strategic Landscape of Essar’s CSR Initiatives in 2024
essarupdate
 
PPT
Impact of Hand Block Printing Manufacturers in the Bedsheet Retail Market.ppt
Top Supplier of Bedsheet, Razai, Comforters in India - Jaipur Wholesaler
 
PDF
MusicVideoTreatmentForFreebyParrisLaVon.pdf
gamilton
 
PPTX
business and preparing for good business
jaslehannvillaflor
 
PPTX
Baby Solids Food Schedule - Introducing Solids at 5 Months.pptx
Sanchita Daswani
 
PDF
Natesan Thanthoni: The Agile Visionary Transforming Virbac IMEA (India, Middl...
red402426
 
PDF
Beyond the Launch: Solving Deep Problems in Traditional Industries with Tech
EkoInnovationCentre
 
PDF
Adnan Imam - A Dynamic Freelance Writer
Adnan Imam
 
PPTX
2. The History of New Digital Economy.pptx
WidiSriwahyuniPasari1
 
PPTX
Appreciations - June 25.pptxggggggghhhhhh
anushavnayak
 
SAG Infotech Issues Press Release for Media and Publications
SAG Infotech
 
Walt Disney Business Proposal for Hollywood Studios
balazscsillag
 
Global Media Planning and Buying Market Trends 2025
Rupal Dekate
 
Toolszen SEO Tools Group Buy 2026 India.pdf
Group Buy Seo Tools
 
Albaik Franchise All Information Update.pdf
AL-Baik Franchise
 
How is IMSLP Wagner Connected with Pachelbel & Shostakovich.pdf
SheetMusic International
 
Thane Stenner - A Leader In Extreme Wealth Management
Thane Stenner
 
PTAC Repair Near Me | Heating and Cooling
angisonairnyc
 
Netflix Social Watchlists Business Proposal
lexarofficial222
 
Vedanta’s Pivotal Role in India’s Growth with Record Vedanta Tax Contribution...
Vedanta Cases
 
The Strategic Landscape of Essar’s CSR Initiatives in 2024
essarupdate
 
Impact of Hand Block Printing Manufacturers in the Bedsheet Retail Market.ppt
Top Supplier of Bedsheet, Razai, Comforters in India - Jaipur Wholesaler
 
MusicVideoTreatmentForFreebyParrisLaVon.pdf
gamilton
 
business and preparing for good business
jaslehannvillaflor
 
Baby Solids Food Schedule - Introducing Solids at 5 Months.pptx
Sanchita Daswani
 
Natesan Thanthoni: The Agile Visionary Transforming Virbac IMEA (India, Middl...
red402426
 
Beyond the Launch: Solving Deep Problems in Traditional Industries with Tech
EkoInnovationCentre
 
Adnan Imam - A Dynamic Freelance Writer
Adnan Imam
 
2. The History of New Digital Economy.pptx
WidiSriwahyuniPasari1
 
Appreciations - June 25.pptxggggggghhhhhh
anushavnayak
 

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", "[email protected]"); firstUser.changeEmail("[email protected]"); firstUser.saveScore(15); firstUser.saveScore(10); firstUser.showNameAndScores(); //Richard Scores: 15,10 // Another User secondUser = new User("Peter", "[email protected]"); 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); } }