Forum Discussion

grant_volker_2's avatar
grant_volker_2
Contributor
13 years ago

Possible to decouple the object search from CSS, HTML and property changes?

Hi,



I work in an Agile environment and the properties of some objects get changed during sprints, for example a link's tagName might

change from LI to A (and I think even formatting such as H1 or BOLD)!



I've also experienced circumstances where objects such as combo-boxes and text boxes have no label applied until the CSS styling

is implemented in a later sprint and a Name such as Textbox(0) or ObjectIdentifier of 0 aren't much help at all.



There's little if any communication from the developers about these changes, so I have applied an approach that can be fairly

easily adapted to search for various properties, but this is becoming manually intensive. (Please see the code below).



Is there a method that someone can suggest to decouple the object search from CSS, HTML and property changes please?



Thank you





  Set objObjectToStartFrom = objPage

  arrProperty(0) = "tagName"

  arrProperty(1) = "contentText"

  arrValue(1) = "Visit W3Schools.com!"

  intDepthOfSearch = 12

  clkStopTime = GetTickCount() + 30000

 

  On Error Resume Next

  Do While GetTickCount() < clkStopTime

    arrValue(0) = "LI" 'try for this obect type

    Set objLink = objObjectToStartFrom.NativeWebObject.Find(arrProperty(1), arrValue(1), arrValue(0))

    If Err.Number <> 0 Then

      Log.Warning Err.Description & " when attempting to set object " & arrValue(0), pmNormal

      On Error Goto 0

      Err.Clear

      Exit Function

    End If

    If objLink.Exists Then

      Log.Checkpoint "Object found: " & arrValue(0), "", pmNormal

      Exit Do

    Else

      arrValue(0) = "A" 'if the TextNode was not found then try this object type

      Set objLink = objObjectToStartFrom.NativeWebObject.Find(arrProperty(1), arrValue(1), arrValue(0))

      If objLink.Exists Then

        Log.Checkpoint "Object found: " & arrValue(0), "", pmNormal

        Exit Do

      End If

    End If

    aqUtils.Delay(100)

  Loop

  If Err.Number <> 0 Then

    Log.Warning Err.Description, pmNormal

    On Error Goto 0

    Err.Clear

    Exit Function

  End If

  On Error Goto 0

3 Replies

  • Hi Grant,



    It's a big problem you are facing. I've been working for too much time this way, and it is really hard. The worst of it, it is a waste of time (my opinion), because as the code grows and sprints go away, you will be more time maintaining your code than developing new one (it's a fact, I'm so sorry)



    But the world is that way and there is no justice at all, so let's see what we can do. I'm using JavaScript and I don't know much about VB, so you will have to adapt it to your own code (sorry again)



    First, we create an array of properties and values for an object. For example:





    var loginLink = {

      "ObjectType": "Link",

      "innerText": "Login",

      "idStr": "login_link"

    }





    Now, you can search for that object by using a function like that:





    function parseObjectInfoToArray(objectInfo)

    {

      var object = new Object();

      var aProp = new Array();

      var aVal = new Array();

      

      var i = 0;

      for ( e in objectInfo ) {

        aProp = e;

        aVal = objectInfo;

        i++;

      }

      

      return new Array(aProp, aVal);

    }





    This will create an array of properties and values. You can use those arrays to search for the object. The point is that you can change the variable loginLink that way:





    var loginLink = {

      "ObjectType": "TextNode",

      "idStr": "login_link",

      "className": "login-link"

    }





    And you will only have to worry to change it once, in one place. No need to seek for it on all your code.



    I don't know how to implement it on VB, but I hope there is a way.



    Have luck!
  • Hi Javier,



    I appreciate your response and will think about how I can apply the information you have shared.



    I am wondering whether the Name Mapping feature of TestComplete is intended to overcome this challenge, what do you think?



    Thank you,

    Grant
  • Hi Grant,



    I don't really know. I have never used NameMapping on my projects (neither my team mates)



    I'm sure other forum users could help you with that.



    See you