Forum Discussion

mdehaan's avatar
mdehaan
Occasional Contributor
2 months ago
Solved

Get raw Alias from sub object

Hi there,

I've been using TestComplete (primarily Javascript) for over a year now but I never managed to figure out how to get the raw Alias value from a stub object. 

The context:
I have a generic search field object with the following Alias: Aliases.Application.SearchField

As it takes a while for the field to render I want to use WaitAliasChild to wait for the search field to appear. However the function processing the search field can also be applied to a different screen where the search field is defined as Aliases.Application.Screen1.SearchField. There are a dozen more similar Aliasses pointing to SearchFields I want to process with the same function. Therefore I'm passing the target Alias as a parameter to the function. 

Ideally I would want to use the Alias parameter and call .MappedName. Then snip up the string into smaller bits and call WaitAliasChild for each snippet. For example calling the function with an Alias of Aliases.Application.Screen1.SearchField would then result in Aliases.Application.WaitAliasChild('Screen1').WaitAliasChild('SearchField'). Perfect!

However, since the object is not yet on screen the Alias parameter only carries a stub object. Alias.MappedName does not work as stubs only contain the .Exists parameter. 

So my question is: is there a way to get the MappedName parameter from a stub object? 

The oddest thing is that calling aqObject.CheckProperty on the Alias will throw an error which contains the actual MappedName. So I'm sure it is accessible somehow:

Unable to find the following object when executing the aqObject.CheckProperty command:
Aliases.​Application.​SearchField

I have been thinking about listing all Aliases as strings in the codebase and evaluating them when needed as objects but this will sever all ties to the actual Aliases library and is much more prone to typo's.

I hope someone can help, thanks!

  • Hello mdehaan,

    This would be a new feature.  Have you dropped an idea in the Feature Requests forum?  If you don't think there is a way to do this other than through the returned stub object this would be the best action.  You could also reach out to support.

    Feature Request:
    TestComplete Feature Requests | SmartBear Community

    Support:
    https://support.smartbear.com/testcomplete/message/

    I hope you find an answer to this soon!  Don't forget to mark a best answer to complete this issue when you think you have one and drop a few likes for the comments.  We would really appreciate it!

    Have a great day!

    Scott

11 Replies

  • rraghvani's avatar
    rraghvani
    Icon for Champion Level 3 rankChampion Level 3

    A Stub object is like an "empty" object with minimal properties/methods, just enough to simulate the real object’s behaviour. It may not have the mapped name - you can verify this via debugging and viewing the actual contents of the Object.

     

  • scot1967's avatar
    scot1967
    Icon for Champion Level 2 rankChampion Level 2

    Hello mdehaan,

    TestObj.WaitAliasChild(ChildName, WaitTime)

    If TestObj exists it will contain a path you can return and use as a string and then concatenate ChildName to produce the path you are looking for.  The stub object can't contain the path to something it can't find but you can log what you asked it to find.  Am I over simplifying the issue (missing something)?  Let me know. 😉 

    var parent = Aliases.App;
    var childName = "MainWindow";
    
    var child = parent.WaitAliasChild(childName, 5000);
    
    if (!child.Exists) {
      Log.Warning("Object not found. Attempted alias path: " + parent.FullName + "." + childName);
    } else {
      Log.Message("Object found: " + child.FullName);
    }

    I hope this helps!  

    ... If you find my posts helpful drop me a like! 👍 Be sure to mark or post the solution to help others out and/or to credit the one who helped you. 😎

    • mdehaan's avatar
      mdehaan
      Occasional Contributor

      Well, the thing is that the function I'm using gets the Alias as a parameter. Therefore I don't know the parent without calling Alias.Parent. Neither do I know childName for the same reason. I want to pick it from the Alias using Alias.MappedName but I need for the object to Exists before I can do that. And in order to use parent.WaitAliasChild(childName) I need the MappedName. Thus I'm running in circles. If I could get the MappedName from the stub object (which is based on an Alias being exactly what I need) then I could identify the Parent and childName.
      I think the stub object should contain {Exists: false, MappedName: Aliases.Application.SearchField, FullName: Sys.ApplicationName.Yada.Yada.Yada.SearchField}

      A little code example of the problem:
      test(Aliases.Application.Screen1.SearchField)
      test(Aliases.Application.Screen2.SearchField)

      function test (Alias) {
         Aliases.Application.???.WaitAliasChild('SearcField')
      }

      • rraghvani's avatar
        rraghvani
        Icon for Champion Level 3 rankChampion Level 3

        Based on your example code -  as an example, you can do this

        function test()
        {
            // Assuming Aliases.Application.Screen1/2 object exists.
            search(Aliases.Application.Screen1);
            search(Aliases.Application.Screen2);
        }
        
        function search(obj)
        {
            // Use the WaitAliasChild method to delay the test execution until the object specified 
            // by its alias appears in the system or until the specified time limit is reached
            if (obj.WaitAliasChild("SearchField", 30000).Exists) {
                Log.Message("Found child 'SearchField'.")
            } else {
                Log.Warning("Did not find child 'SearchField' within the specified time period.")
            }
        }

        The parent object is Aliases.Application.Screen1, and you are waiting for the child object SearchField to appear within the 30 second time period.

  • scot1967's avatar
    scot1967
    Icon for Champion Level 2 rankChampion Level 2

    Hello mdehaan,

    This would be a new feature.  Have you dropped an idea in the Feature Requests forum?  If you don't think there is a way to do this other than through the returned stub object this would be the best action.  You could also reach out to support.

    Feature Request:
    TestComplete Feature Requests | SmartBear Community

    Support:
    https://support.smartbear.com/testcomplete/message/

    I hope you find an answer to this soon!  Don't forget to mark a best answer to complete this issue when you think you have one and drop a few likes for the comments.  We would really appreciate it!

    Have a great day!

    Scott

    • mdehaan's avatar
      mdehaan
      Occasional Contributor

      I submitted the Feature Request: https://community.smartbear.com/idea/testxcompletefeaturerequests/access-alias-path-information-from-stub-objects-in-testcomplete/278191

  • mdehaan's avatar
    mdehaan
    Occasional Contributor

    Yeah, that's correct. The stub object only has the .Exists property. Still, somewhere in the system should be a reference to the Alias (Aliases.Application.SearchField in this case) cause how else would the system know this particular object does not exist. And how is it listed in the Unable to find the following object logging? And I'm wondering what I need to do to find it. In essence I just want to know which Alias I'm processing

    • rraghvani's avatar
      rraghvani
      Icon for Champion Level 3 rankChampion Level 3

      I suggest you read through Object Browser and you will get a better understanding of how TestComplete goes about identifying objects.

       

    • Hassan_Ballan's avatar
      Hassan_Ballan
      Icon for Champion Level 3 rankChampion Level 3

      I don't claim that I am grasping the conversation or the framework you are building. When I started working with TestComplete I first focused on learning how it was intended to be used going thru its features for strength and weaknesses. After that I built a unique framework described in https://smartbear.com/blog/pro-tips-from-the-smartbear-community-scaling-salesforce-testing-with-testcomplete/

      One thing for sure you must wait for the object before retrieving mapping info. Always call .WaitProperty("Exists", true, timeout) on the alias first—otherwise the child may not yet be registered in the mapping table. Than use WaitAliasChild before interacting with a child object.

      💬 Found the answer helpful? Give it a Like!
      ✅ Got your issue resolved? Mark it as the solution so others can find it fast.

      • mdehaan's avatar
        mdehaan
        Occasional Contributor

        But isn't that odd? Since the framework uses the Alias and FullName to check if the object exists in the first place.

        I think the stub object should contain 
        {
            Exists: false,
            MappedName: Aliases.Application.SearchField,
            FullName: Sys.ApplicationName.Yada.Yada.Yada.SearchField
        }

        Or there should be some other way to fetch the pointer from an Alias-defined non-existent object.

        A little code example of the problem:
        test(Aliases.Application.Screen1.SearchField)
        test(Aliases.Application.Screen2.SearchField)

        function test (Alias) {
           Aliases.Application.???.WaitAliasChild('SearcField')
        }


        How do I identify the Parent? Assuming there can be many input Aliases in this function