KEMBAR78
Coding using jscript test complete | PPTX
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);

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 atext 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 anarray 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 //Checkthat the object isn't null if (obj == null) throw "Null object passed to generateXMLFromObjectFields";
  • 14.
    Push an itemto an array myArray = []; myArray.push(item);
  • 15.
    Project variables //access test complete project variables var MyAppPath=Project.Variables.MyAppPath;
  • 16.
    prototype //prototype varDog=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.0xml 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 varfso = 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 fromobject 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 Createa 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 andmethods 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); } }