Forum Discussion

Bharadwaj's avatar
Bharadwaj
Contributor
8 years ago
Solved

The web site has built in auto refresh every 4 seconds,so I lose my web control's object references.

procedure testcase1;
var
  prObj;
begin
  //This is how I get my parent Object and store it in a var in my test case execution,
  //the object exists until the page gets refreshed
  prObj := GetWebObject(page,nil,nil,['ContentText','VisibleOnScreen','ObjectType'],['xyz',true,'Panel']);
  if not prObj.exists then
    Log.Error('Parent obj does not exists');
  //execute my test case  steps
  //Step 1
  //Step 2
  //step3
  //work fine if the page is not refreshed as we have the reference to prObj but fails if page refreshes;
  //how can I solve these kind of page auto refresh problems which cause my object references to crash.
  prObj.Button(1).Click();
end;

Hi All,

I am testing a web calendar application which auto refreshes every 4 seconds and fetches the events added to the calendar by other parallel users of the application. So lets say if 10 users are using the website at one time they all will automatically see the events added by others (if any new events are added to it) every 4 seconds due to built in auto refresh. My lets say the scope of my test case is to check if the events added are displayed right. for this I am fetching the Parent Panel object reference (which is the Calendar) and have my own logic to check the contents (which are the children in the panel) of the Parent Panel. All works well if the auto refresh does not happen and my test case runs with in that four seconds. But if the auto refresh happens I lose the object reference of my parent panel and my code  fails as the object does not exist at that point so I cant access its children.Is there any specific way of testing this kind of applications. What I thought was the first time I get the object reference of the parent panel,I save the path in some variable and in the middle of the tests where ever I access that panel ,if the object does not exist I access the variable and get back the object. But what I found with this approach is its too expensive and I have to write the unnecessary code to buffer the object reference in a variable. Is there any better approach to solve this issue.

I have gone through this link in test complete help 

Smart Bear Help

actually I can use name mapping approach but the problem with this approach I believe name of a control is mapped using its hard coded object path or alias and if some how the path changes due to changes made by developers (we are not informed of any such changes made in our case if the internal structure or layout changes in the page)adding more contents in between or deleting certain contents then it may again fail and I have to remap my object which I want to avoid

Please help. Thanks in advance.

 

cheers,

Bharadwaj. 

  • Hi Bharadwaj,

     

    I am afraid that you don't have too many options here if my guess about your tested application is correct.

    I am taking that when an auto-refresh event occurs, script code on the web page destroys some parent object that you are trying to use in your test code and create it anew with the new data. Because this object is really released (and maybe even garbage collected), actions like refresh against it will not help and the only option is to get a new reference to the new created object and proceed.

    Two possible workarounds that came to my head are:

    a) Implement a OnLogError event handler in your test project and renew a reference to the not found object within it. This might work but you are anyway at risk that the number of events change after refresh and you will get a false negative test result;

    b) Consider injection of your code into the tested web page. Ideally, this code must be executed within the function that updates the list of events so the auto-update event is not triggered until your code done. Maybe even the best approach is to ask developers to include some hidden controls on the web page and populate these controls with the data that you need. More about injection of custom script code into the web page: https://support.smartbear.com/articles/testcomplete/embedding-scripts-into-web-pages/ (from https://support.smartbear.com/articles/testcomplete/) and https://support.smartbear.com/viewarticle/69056/.

     

    However, I think that the most reliable approach is to separate the auto-refresh functionality and the tested business functionality.

    You may talk to developers and ask them how you can disable the auto-refresh. (You may use the approach from paragraph b) above and either set some variable on the page or call some page script function to disable the auto-refresh.) This will guarantee you that page structure will remain unchanged until your test code completes and you are guaranteed from false negatives. Auto-refresh can be enabled after the test is done.

4 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi Bharadwaj,

     

    I am afraid that you don't have too many options here if my guess about your tested application is correct.

    I am taking that when an auto-refresh event occurs, script code on the web page destroys some parent object that you are trying to use in your test code and create it anew with the new data. Because this object is really released (and maybe even garbage collected), actions like refresh against it will not help and the only option is to get a new reference to the new created object and proceed.

    Two possible workarounds that came to my head are:

    a) Implement a OnLogError event handler in your test project and renew a reference to the not found object within it. This might work but you are anyway at risk that the number of events change after refresh and you will get a false negative test result;

    b) Consider injection of your code into the tested web page. Ideally, this code must be executed within the function that updates the list of events so the auto-update event is not triggered until your code done. Maybe even the best approach is to ask developers to include some hidden controls on the web page and populate these controls with the data that you need. More about injection of custom script code into the web page: https://support.smartbear.com/articles/testcomplete/embedding-scripts-into-web-pages/ (from https://support.smartbear.com/articles/testcomplete/) and https://support.smartbear.com/viewarticle/69056/.

     

    However, I think that the most reliable approach is to separate the auto-refresh functionality and the tested business functionality.

    You may talk to developers and ask them how you can disable the auto-refresh. (You may use the approach from paragraph b) above and either set some variable on the page or call some page script function to disable the auto-refresh.) This will guarantee you that page structure will remain unchanged until your test code completes and you are guaranteed from false negatives. Auto-refresh can be enabled after the test is done.

    • Bharadwaj's avatar
      Bharadwaj
      Contributor

      Thanks a lot for the replies guys.

      AlexKaras I will be using the approach b (However, I think that the most reliable approach is to separate the auto-refresh functionality and the tested business functionality.)which you have suggested as that's the closest solution I can use with out extra overhead of re-fetching the objects ,when their references are lost due to auto refresh.

  • Hello Bharadwaj,

     

    Use descriptive programming for storing the parent object. I hope this will work for you.

     

    set objCalender = Sys.Browser.Page(...).find("PropName","PropCValues","Waittime")

     

    In this find you can use any distinguish property to map that parent.

     

    Thanks,

    Mayank Gupta 

     

  • One more thing i want to add. Before click on button, use ObjParent.Refresh

     

    Regards,

    Mayank Gupta