Forum Discussion

OV's avatar
OV
Frequent Contributor
7 years ago

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

17 Replies

  • shankar_r's avatar
    shankar_r
    Community Hero

    Basically you want to click the HomeButton irrespective which screen it belongs to and you want to print the log that shows from which screen it got clicked. Is that correct?

    • OV's avatar
      OV
      Frequent Contributor

      That's correct, or more like to say irrespective what object hierarchy tree it belongs to, that will shorten my waiting time dramatically.

       

      I'm attaching a screenshot of the object/s NameMapping

       

      Thanks

  • shankar_r's avatar
    shankar_r
    Community Hero

    Also you haven't  used below variables anywhere in your code,

     

    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)

    • OV's avatar
      OV
      Frequent Contributor

      Yes, that might be from previous attemps to solve the problem :-).

       

      What i was thinking now, and correct me if i'm wrong.

      When i created the home button for each hierarchy i've changed its name so i'll know to where it belongs to. if i wouldn't change the name and just use WaitAliasChild or WaitChild to find the HomeButton for the Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree object, would that work?

       

      Thanks

      • shankar_r's avatar
        shankar_r
        Community Hero

        If you have any property for AutomationBindingsControl, DataSourcesControl and etc to display name of the Screen then you can try logic in your function.

         

        Not sure the exact business flow but i hope this will give you a idea.

         

         

        // Navigate to the right place
        function Navigate(TheHomeButton, HomeButton, TheButtonToClickInHomeScreen, BreadScrumbItem) {
        	
              var BreadScrumpTree = Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree;
              
              var HomeButton = BreadScrumpTree.FindChild("ClrFullClassName","System.Windows.Controls.Button",10);
              
              if(HomeButton.Exists && HomeButton.VisibleOnScreen)
              {
                    var CurrentScrenName = HomeButton.Parent.Parent.WPFControlText;//You need to identify a property that will have current Page name
                    
                    if(BreadScrumbItem == CurrentScrenName )
                    {
                          Information("Navigation is on " + CurrentScrenName + " screen");
        		      ClickObjectInBreadScrumbTree(BreadScrumbItem)
                    }
                    else
                    {
                          Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree.AutomationBindingsControl.Border.AutomationBindingHomeButton.Click()
        			return    
                    } 
              } 
              else
              {
                    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();
              } 
        }