Forum Discussion

dshriver's avatar
dshriver
Occasional Contributor
11 years ago

Patching recorded tests

I've got a task that is seemingly very easy but I am confused how to approach it in TC10.



One user has created tests (via recording) and I'm trying to make them transportable by patching them.  Basically we can run the tests against various boxes so, at the very least, it needs to be easy to change the domain and run.



So far I've been pestering Customer Support but maybe it would be faster to get tips here.



When I'm in "Project Workspace" looking at the individual tests I can see "Navigate" steps that have URLs in them.  So I put in a project variable for the domain, and in the Navigate steps the URL becomes a "Code Expression".



However, when I run I get a lot of "Object Not Found" errors.



At least some of these have the URL with the old domain in them.  When I try to change them I'm a bit perplexed because I can only choose "Constant" or "Project Variable" (I'd really like to pick "Code Expression" and then put my variable for the domain name in with the static parts added to it).  I don't see how I can fix this.

8 Replies

  • Marsha_R's avatar
    Marsha_R
    Icon for Champion Level 3 rankChampion Level 3
    Can you give us a screenshot so we can get a better idea of where you are working?
  • dshriver's avatar
    dshriver
    Occasional Contributor
    I have some screenshots and I'll detail the sequence of events that lead to them.



    1) the test suite is run with a variable at the project level being set to one domain name ("crs.mitre.org").  The keyword test passes ("Pass.jpg")



    2) the variable (at the project level) is changed to another domain ("vcrs.mitre.org") which runs a different version of the exact same pages.  The keyword test fails ("Fail1.jpg").  Note when I drill down and look at a page object in the name mapping editor that page oddly has the old domain name in it (crs.mitre.org), see the picture "Fail2wrongDomainName.jpg".  In the keyword tests I did edit all the "Navigate" steps so that they used a Code Expression (and my domain variable).  When I try to edit these pages I find that I cannot choose a "code expression" I can only use some string containing a URL (obviously editing all of these between tests defeats the whole idea of using a project variable...)
  • dshriver's avatar
    dshriver
    Occasional Contributor
    I can't seem to upload the pictures to your site.  Probably this is an issue of automated security.  I can email the pictures to some email address though.
  • AlexKaras's avatar
    AlexKaras
    Icon for Champion Level 1 rankChampion Level 1
    Hi Dan,



    > a page object in the name mapping editor

    Have you edited your namemapping for the page object so its mode is 'Project Variable' but not 'Constant'? (To do this click on the ellipsis button for the URL parameter of the page object in the Namemapping editor.)
  • dshriver's avatar
    dshriver
    Occasional Contributor
    That would be very clumsy at the least.



    The URL has portions that do change based on what machine I run on (domain) and parts that don't change.  I need something like the "Code Expression" I used earlier on the Navigate pages.  Those worked nicely for the navigate step because I had the non-changing portions as a string and the domain as a Project Variable.



    If I use "Project Variable" that would mean I'd need to create a large number of project variables for each keyword test and change all of them each time I change domains.



    I had hoped that by changing the initial navigate step on the recorded test that all the subordinate objects would use that URL, but it seems like they all get a hardcoded value at the time the test was originally recorded.
  • dshriver's avatar
    dshriver
    Occasional Contributor
    I've gotten an email reply (I've been asking technical support as well as this forum) and a preliminary test indicates that things seem to be fixed (I patched one keyword test successfully).  I'm just wondering what is the "right way" to do things in TC.



    Earlier I tried to patch the recorded tests by making every initial "Navigate" browser step use a "Code Expression".  That "Code Expression" uses the Project variable I setup for our domain (which changes) and the portions that don't change (for instance the page itself...).



    What I found was that the keyword tests failed on a large number of "Object Not Found" errors because items that I thought were subordinate (and assumed would automatically change), had the URL hardcoded into them (with the original domain value).



    Finally, tech support suggested changing all those hardcoded URLs (which I wanted to change into "Code Expression"s) to use a wildcard in place of the domain name.  So now I have both the "Navigate" step using a "Code Expression", and in "Name Mapping" I have subordinate objects using a wildcard.  I'm wondering if this two part approach is what is generally suggested in TC in this case.  Also, how does the system know what to use for the wildcard (I didn't tell it which domain to point to on those hardcoded steps, but somehow it seems to point to the right one). 
  • AlexKaras's avatar
    AlexKaras
    Icon for Champion Level 1 rankChampion Level 1
    Hi Dan,



    You will need two project variables - one for the variable part of the address and another one for the full address. Specify the second variable in the Namemapping.

    Set the required value to the first variable and, at the beginning of your test, execute a code that will assign a proper value to the second variable. Your namemapping should work after that.

    Note, that as these variables are of project level, they will be accessible in all (keyword) tests of this given project.

    You may implement the same logic on the project suite level as well if required.
  • dshriver's avatar
    dshriver
    Occasional Contributor
    I'm not sure I understand your solution Alexei... fortunately Yuri Minaev has given me a suggestion which I've used to patch at least two keyword tests.



    All I need to do is to use the Code Expression on Run Browser / Navigate / Browser steps that do actuall navigation.   All the page objects (and subordinate objects of them) get a wildcard for the domain in the Name Mapping.



    So far this seems to be working nicely.



    We were considering (since we didn't know how to do things the right way) doing something evil and using "sed" or some other search/replace tool to do bulk replacements on the domain in all the files that TestComplete generates (they seem to be XML files).