Forum Discussion

lucieneven's avatar
lucieneven
Contributor
13 years ago

no distinct variable when generated the script

Hello,



When i tried to figure out ObjectNotFound exception,by chance i noticed that the script recorded has given multiple value to one variable. Example is like enclosed 2011-12-07 9-49-56 AM.png. i'm just curious about this.



I understand program will always use the latest value on one variable when executing the script line by line. But why TestComplete can't always create distinct or unique variable, because indeed it created a lot of similar variable as can be seen from enclosed 2011-12-07 9-57-26 AM.png. Otherwise, will it raise any conflict when playing back the script?



Can you help shed some light here, thanks!



Lucien






  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Is this causing a problem?  I'm not sure what the concern is.



    This is actually a pretty standard tactic that I use even in my manually created scripts.  Let's say, during the course of writing a test, I open a Form... I assign that form to a variable so I can go back and reference that form later... then I open a child form... well, I want to preserve my first form so I create a new variable and assign it... I close that child form... and I can now use my first variable to reference the form from earlier.  I open a different child form... well, the first child form is "gone" so I can reuse the variable



    ...and so on.  



    The idea is that you assign an object to a variable for two reasons.  First, to make it easier to reference it ( a lot easier to say "Button1.ClickButton" than "Sys.Myapp.MyForm1.MyForm2.MyForm3.Button1.ClickButton") and secondly to be able to refer back to the object later in the same script.  So, if the object technically still exists in memory, you want to keep that variable around so you'll need to create a different variable.  But once the object goes away, you can then reuse the variable.



    We tried, at one point, to use the same variable (w) for all forms and windows... and it ended up confusing things because it was hard to tell which form was being referenced by the w.



    Now, another thing to note... when you have that many variables defined in the beginning of your code, is it possible that your test is doing too much?  Are there tasks, workflows, procedures, etc., that may be able to be broken out into other functions?  Especially tasks and such that may be re-useable across a number of tests.  For example, logging in to your application.  Can that be pulled out to a seperate function?  That would reduce the number of variables in test as well.



    So...it's just a matter of technique, need, etc.
  • Hello Robert,



    I read through your answer for a couple of times. You explain very clearly. That greatly makes sense here.



    When it comes to variable, it just reminded me of one interesting thing when i tried QTP as recording script. It's always wierd for me, cause looks like QTP hided the variable from the script. I means, the variable definition and use is transparent to the user.



    I just tried QTP and TestComplete both on a same but small case, basically, user launch the browser, login and click some links and then logout and close the browser.



    QTP:



    Browser("JMap Admin").Page("JMap Admin").WebEdit("username").Set "administrator"

    Browser("JMap Admin").Page("JMap Admin").Link("Login").Click

    Browser("JMap Admin").Page("JMap Admin_2").Frame("heading").Link("Tools").Click

    Browser("JMap Admin").Page("JMap Admin_2").Frame("center").Link("Deployment").Click

    Browser("JMap Admin").Page("JMap Admin_2").Frame("heading_2").Link("Logout").Click

    Browser("JMap Admin").Page("JMap Admin").Sync

    Window("Windows Internet Explorer").Close



    TestComplete:



      Dim iexplore

      Dim table

      Dim page

      TestedApps.Page1.Run

      Set iexplore = Aliases.IEXPLORE

      Call iexplore.ToUrl("http://192.168.0.218:8080/jmapadmin/login.jsp?error=not_logged_in")

      Set table = iexplore.pageJmapAdmin.formTheform.tableLoginpanel

      Call table.cell.textboxUsername.SetText("administrator")

      Call table.cell1.linkJavascriptSubmit.textnodeLogin.Click(10, 11)

      Set page = iexplore.pageJmapAdmin1

      Set table = page.frameHeading.panelToolbarBox.panelM.panelToolbar.table

      table.cellToolbarTools.linkTools.Click

      Call page.frameCenter.panelElementBox.panelM.table.cell.table.cell.linkAppDeploymentJsp.textnodeDeployment.Click(82, 9)

      table.cell.linkLogout.Click

      page.Wait

      iexplore.IEFrame.Close



    My feeling is QTP's script is more concise, user doesn't need much care on defining variable and passing value. Also seems QTP hided the hierarchy of browser from the script. It's interesting. Maybe only QTP knows how they can do that.



    That's not a question. Just curious somewhat. You don't need put any words here. :)



    Whatever, thanks for your clear and specific explanation!



    Lucien


  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Actually, they are not that much different.  I suspect that QTP is utlizing their object repository behind the scenes.  You can achieve the same thing with TestComplete with some modification of the aliases.  Done properly, you could end up with code, in TC, that looks like this:





      TestedApps.Page1.Run

      Aliases.IEXPLORE.ToUrl("http://192.168.0.218:8080/jmapadmin/login.jsp?error=not_logged_in")

      Call Aliases.IEXPLORE.pageJmapAdmin.textboxUsername.SetText("administrator")

      Call Aliases.IEXPLORE.pageJmapAdmin.textnodeLogin.Click(10, 11)

      Call Aliases.IEXPLORE.pageJmapAdmin1.linkTools.Click  

      Call Aliases.IEXPLORE.pageJmapAdmin1.textnodeDeployment.Click(82,9)

      Call Aliases.IEXPLORE.pageJmapAdmin.linkLogout.Click

      Call Aliases.IEXPLORE.pageJmapAdmin.Wait  

      Call Aliases.IEXPLORE.IEFrame.Close




    It's a matter of  telescoping down the hierarchy of your aliases and just calling the values directly rather than assigning them as variables.
  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)
    Hi Lucien,



    When it comes to variable, it just reminded me of one interesting thing when i tried QTP as recording script. It's always wierd for me, cause looks like QTP hided the variable from the script. I means, the variable definition and use is transparent to the user.

    ...

    My feeling is QTP's script is more concise, user doesn't need much care on defining variable and passing value.


    Just FYI, TestComplete can also record scripts that use fully-qualified object names and do not use variables, like in Robert's example. For this purpose, turn on the Do not generate variables option in Tools > Options > Engines > Recording.
  • Thanks for your feedback. It works!



    Enclosed is the screenshot. It's still interesting how QTP hide the hierarchy details of the variables to make the script so short. :)



    Lucien
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    The difference between QTP and TestComplete when it comes to the hierarchy may be the model used in calling web page objects.  I'm not certain, but I think that either Hybrid or Tree model are used by default when TestComplete is originally installed.  I don't know QTP very well at all but, judging from the code you've posted, I suspect that QTP uses more of a DOM model where the hierarchy is "hidden" by simply identifying the different items on a page simply as a list of page objects rather than embedded objects within other objects.



    See the following article to learn more about these models.



    http://smartbear.com/support/viewarticle/12439/