Best tip I could give you is to see it as standard programming... Because scripting is programming.
Use the object browser and learn how to identify objects....
Personnaly, I don't use Name Mapping because it expect the objects to be structured in specific hierarchie and I'm stuck with developers who spend their time changing that.... so instead, I seek for specific object properties of objects or components and developed a generic function that uses FindChildren and returns a null or the object itself.
When automating, you're building a program that will interact with another one... decompose, build function libraries, be modular... (standard development practices :smileywink: )
Depending on the scripting language, you can even develop your automation in an Object Oriented fashion... C#, JScript do understand the "this" keyword and allowes you to encapsulate properties and methods in objects... thus, allowing lots of code reuse...
Think of a screen as an object.... your script code as a unit... a Test Scenario simply steps from one screen to another and performs whatever controls you want to perform...
Here's a sample of a Browser Class I've built in C# that I use instead of using TestedApp
function myBrowserClass()
{
// Initialisation of FIELDS
this.Component = Object(); // L'object TestComplete.Browser
this.BrowserType = varInteger; // Le type de Browser (int, -1=IE, -2=FF, -3=Chrome)
this.currentPage = Object(); // Object de type Page, Page courante du Browser
this.URL = varString; // URL de la page de type String
this.isVirtual = Boolean();
this.Description = varString;
// A method
this.Open = function(BrowserType,isVirtual) // Instancie un fureteur selon le type
{
if (isVirtual) { // Si on utilise un Browser Virtuel
this.isVirtual = true;
var supported = VirtualBrowsers.Count;
var myName = "chrome";
if (BrowserType<supported) // Est-ce que celui demandé est supporté (Voir dans les Projets-Properties-Open App-Web Test-Virtual
{
var mybrowser = VirtualBrowsers.Item(BrowserType);
Log.Message(mybrowser.UserAgent);
}
this.Description = mybrowser.UserAgent;
} else { // Le fureteur est réel (IE ou autre)
this.isVirtual = false;
switch (BrowserType) {
case "-1" : Log["Message"]("Fureteur demandé : " + "Microsoft Internet Explorer");
var mybrowser = Browsers["Item"](btIExplorer);
var myName = "iexplore";
break;
case "-2" : Log["Message"]("Fureteur demandé : " + "Mozilla Firefox");
var mybrowser = Browsers["Item"](btFirefox);
var myName = "firefox";
break;
case "-3" : Log["Message"]("Fureteur demandé : " + "Google Chrome");
var mybrowser = Browsers["Item"](btChrome);
var myName = "chrome";
break;
case "-6" : Log["Message"]("Fureteur demandé : " + "Edge");
var mybrowser = Browsers["Item"](btEdge);
var myName = "edge";
break;
default : Log["Message"]("Fureteur demandé : " + "Microsoft Internet Explorer");
var mybrowser = Browsers["Item"](btIExplorer);
}
Log.Message("Fureteur : "+ mybrowser.Description);
Log.Message("Family " + mybrowser.Family);
this.Description = mybrowser.Description;
}
mybrowser.Run(Project["Variables"]["StartupURL"]); // La variable StartupURL se retrouve dans tous les projets.
if (myName == 'edge')
this.Component = Sys.Browser(myName); // Pour obtenir le processus du Browser
else
this.Component = Sys.Browser('*',0); // Pour obtenir le processus du Browser
if (!this.isVirtual) { // Si le Browser n'est pas virtuel (les dimensions sont fixes pour les virtuels)
this.Component["BrowserWindow"](0)["Maximize"]();
}
this.BrowserType = BrowserType;
Log["PopLogFolder"]();
return this.Component; // On retourne l'objet Browser
}
this.Navigate = function(url) // Navigue vers l'URL jusqu'Ã chargement complet
{
Log["AppendFolder"]("Navigation vers l'URL : "+url);
var myClock = HISUtils["StopWatch"];
myClock["Start"]();
var myPage = this.Component["ToUrl"](url);
while (myPage["contentDocument"] == null)
Delay(200);
while (myPage["contentDocument"]["readyState"] != "complete")
myPage["Wait"]();
Project["Variables"]["CurrentPage"]=myPage;
myClock["Stop"]();
//var myName = MakeLogName(Project["Variables"]["MyProject"]);
//PushToLog(myName,"Page ; " + url + " ; "+myClock["ToString"]());
Log["Message"](url + " ; "+myClock["ToString"]());
this.currentPage = myPage;
this.URL = url ;
// this.URL = myPage["URL"];
Log["PopLogFolder"]();
return this.currentPage; // On retourne l'objet Page de la navigation
}
this.Close = function() // Ferme le fureteur
{
this.Component["Close"]();
return null;
}
}
Regards