How to make script run time quicker
Hi,
I have this function I wrote and each time the script need to do the checks in this function it takes loads of time.
The function is looking for a home button, the home button looks the same but it is actually different object that belongs to a different object hierarchy so, every time i need to check whether it belongs to the right object hierarchy in order to be able to click it and if it does then i click it. in case we are talking about the last if statement to will enter enter i'll have to wait for tc to go over and wait all the time for every if to check if the object it's looking for is visible on screen, if it's not then it'll move to the next if statement. that takes a lot of time every run, time i want to save.
THE FUNCTION:
// Navigate to the right place
function Navigate(TheHomeButton, HomeButton, TheButtonToClickInHomeScreen, BreadScrumbItem)
{
Path = eval("Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree." + HomeButton + ".Border")
// Check where navigation is on, If it's in the right place there's no need to navigate if not we need to navigate to the right place
HomeButtonObjPath = Path.WaitAliasChild(TheHomeButton, -1)
// If we're not in the right place that it'll navigate us to the right one
// If we're on Automation screen
if(Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree.AutomationBindingsControl.WaitProperty("VisibleOnScreen", true, 1000))
{
// If we want to navigate to Automation screen
if(BreadScrumbItem == "Automation")
{
//navigationRoot = Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree.AutomationBindingsControl.Border.WaitAliasChild("AutomationBindingHomeButton", -1);
Information("Navigation is on Automation screen")
ClickObjectInBreadScrumbTree(BreadScrumbItem)
}
// Navigate to Home screen from Automation screen
else
{
Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree.AutomationBindingsControl.Border.AutomationBindingHomeButton.Click()
return
}
}
// If we're on Programming screen
if(Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree.AutomationPatternsControl.WaitProperty("VisibleOnScreen", true, 1000))
{
// If we want to navigate to Programming screen
if(BreadScrumbItem == "Programming")
{
//navigationRoot = Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree.AutomationPatternsControl.Border.WaitAliasChild("AutomationPatternHomeButton", -1);
Information("Navigation is on Programming screen")
ClickObjectInBreadScrumbTree(BreadScrumbItem)
}
// Navigate to Home screen from Programming screen
else
{
Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree.AutomationPatternsControl.Border.AutomationPatternHomeButton.Click()
return
}
}
// If we're on Data Source screen
if(Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree.DataSourcesControl.WaitProperty("VisibleOnScreen", true, 1000))
{
// If we want to navigate to Data Source screen
if(BreadScrumbItem == "DataSources")
{
//navigationRoot = Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree.DataSourcesControl.Border.WaitAliasChild("DataSourceHomeButton", -1);
//navigationRoot.Click();
Information("Navigation is on Data Sources screen")
ClickObjectInBreadScrumbTree(BreadScrumbItem)
}
// Navigate to Home screen from Data Source screen
else
{
Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree.DataSourcesControl.Border.DataSourceHomeButton.Click()
return
}
}
// If we're on Devices screen
if(Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree.FunctionalItemsControl.WaitProperty("VisibleOnScreen", true, 1000))
{
// If we want to navigate to Devices screen
if(BreadScrumbItem == "Devices")
{
//navigationRoot = Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree.FunctionalItemsControl.Border.WaitAliasChild("FunctionalItemsHomeButton", -1);
//navigationRoot.Click();
Information("Navigation is on Devices screen")
ClickObjectInBreadScrumbTree(BreadScrumbItem)
}
// Navigate to Home screen from Devices screen
else
{
Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree.FunctionalItemsControl.Border.FunctionalItemsHomeButton.Click()
return
}
}
// If we're on Network screen
if(Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree.NetworkControl.WaitProperty("VisibleOnScreen", true, 1000))
{
// If we want to navigate to Network screen
if(BreadScrumbItem == "Network")
{
//navigationRoot = Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree.NetworkControl.Border.WaitAliasChild("NetworkHomeButton", -1);
Information("Navigation is on Network screen")
ClickObjectInBreadScrumbTree(BreadScrumbItem)
}
// Navigate to Home screen from Network screen
else
{
Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree.NetworkControl.Border.NetworkHomeButton.Click()
return
}
}
// If we're on Projects screen
if(Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree.ProjectsControl.WaitProperty("VisibleOnScreen", true, 1000))
{
// If we want to navigate to Projects screen
if(BreadScrumbItem == "Projects")
{
//navigationRoot = Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree.ProjectsControl.Border.WaitAliasChild("ProjectsHomeButton", -1);
Information("Navigation is on Projects screen")
ClickObjectInBreadScrumbTree(BreadScrumbItem)
}
// Navigate to Home screen from Projects screen
else
{
Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree.ProjectsControl.Border.ProjectsHomeButton.Click()
return
}
}
// If we're on Users screen
if(Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree.UsersControl.WaitProperty("VisibleOnScreen", true, 1000))
{
// If we want to navigate to Users screen
if(BreadScrumbItem == "Users")
{
//navigationRoot = Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree.UsersControl.Border.WaitAliasChild("UsersHomeButton", -1);
Information("Navigation is on Users screen")
ClickObjectInBreadScrumbTree(BreadScrumbItem)
}
// Navigate to Home screen from Users screen
else
{
Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree.UsersControl.Border.UsersHomeButton.Click()
return
}
}
// If we're on overview screen
if(Aliases.QuickDesign_ConfigurationManager.OverViewScreen.VisibleOnScreen)
{
NameMapping.Sys.QuickDesign_ConfigurationManager.HwndSource_This.This.Click()
Information("Navigation is on Overview screen")
Information("Click " + TheButtonToClickInHomeScreen + " Button")
// Click the right button in home screen
ClickObjectInHomeScreen(TheButtonToClickInHomeScreen)
// Build the object to click on from the breadscrumb tree to be at the root
BreadScrumbItemToClick = Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree.ItemsControl.WaitAliasChild(BreadScrumbItem, 5000)
Delay(2000)
BreadScrumbItemToClick.Click();
}
}
Any idea for improvements?
Thank you,
OV