Forum Discussion

AMR013's avatar
AMR013
Contributor
2 years ago

TestComplete not recognizing page even though same line previously worked

Hi everyone,

 

In my test I'm doing a simple line to input text into a textbox (Specifically, username in a username textbox). After doing what I need to do in my application, I log out (which takes me back to the login screen) and need to log in as a different user to do another test in the application. For some reason, TestComplete is not recognizing that same line for the username after I log out. Specifically, it says the page was not found even though it's the same URL I previously used. Any ideas as to why TestComplete can't find the page even though I've clearly used it before? Below is an example of my code:

 

// Declaring page

  var page = 'https://www.testPage.com';



//  Launch Google Chrome and access page.

  Browsers.Item(btChrome).RunOptions = page;

  Browsers.Item(btChrome).Run();



// Click Username textbox

   Aliases.browser.Page(page).FindElement("#username").SetText("user1");



/* Do test and then log out */



// Click Username textbox

   Aliases.browser.Page(page).FindElement("#username").SetText("user1"); -> This same line results in the page not found error.

 

17 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    I log out (which takes me back to the login screen) and need to log in as a different user 

    Is this done within the same code run? If it is then it might be caching case described here:

    https://support.smartbear.com/testcomplete/docs/testing-with/object-identification/name-mapping/how-to/refresh-cache.html

    and here:

    https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/refreshmappinginfo-method.html

    Does this help?

     

    • AMR013's avatar
      AMR013
      Contributor

      AlexKaras ,

       

      Thank you for the links to the caching articles. Appreciate that! I did look into it and sadly it wasn't a caching problem.

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    In your previous post, you had issues opening the browser. Now you are having issues with this. You haven't mentioned what version of TestComplete and Browser you are using?

    • AMR013's avatar
      AMR013
      Contributor

      Marsha_R ,

       

      Thanks for your response. I tried adding wait statements to where the issue was occurring, but for some reason it still has trouble finding the object I'm trying to click on when I run my entire script. Once it fails, I comment out the beginning of my script and run it from where it errored out and that same line works. I'm completely stumped as to why it has issues recognizing it upon my entire script run versus running it in a section.

      • Marsha_R's avatar
        Marsha_R
        Champion Level 3

        Have you stepped through it with Debug? It would be interesting to see what's happening in that transition.

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Does the URL change in anyway. i.e. when navigating to a different page?

     

    Do you use wildcards in your URL?

     

    What lines of code are you commenting out, to make it work?

    • AMR013's avatar
      AMR013
      Contributor

      rraghvani ,

      At the point I run into the issue, the URL does not change nor are wildcards being used. Here's an example of my code to hopefully give you an idea of what I'm seeing:

       

      Lines a - b

      /* Test does whatever */

       

      // The below lines of codes are grabbing a value from a screen, splitting the colons, and saving the text after the third comma as 'recordNo'

       

      Line 1 - var recordNoRowWhole = Aliases.browser.Page("www.google.com").ContentText.split(":");

      Line 2 - var recordNoConverted = recordNoRowWhole.toString();

      Line 3 - var s = recordNoConverted;

      Line 4 - var i = s.indexOf(',', 1 + s.indexOf(',', 1 + s.indexOf(',')));

      Line 5 - var recordNo = s.substring(i+1);

       

      Line c - d

      /* Test proceeds. I log out and then log back into the system. After I log in, I'm attempting to retrieve and access my record in a search screen using the recordNo variable. The lines below is something you actually helped me with in a previous post. */

       

      Line 10 - var parameter = "//td[contains(., ' "+ recordNo.toString() + " ')]";

      Line 11 - Aliases.browser.page.FindElement(parameter).Click();

       

      When it gets to Line 11, the test fails. The log error states "Unable to find the object "//td[contains(., '1234')]".

       

      When I re-test, I comment out Lines a - b, Lines 1 - 5, and Line c - d, and start the test from Line 10. I add another line before Line 10 re-defining my recordNo variable and directly setting it to the value I'm working with (since I commented out the lines that saved the value so I didn't have to run the entire script again). When I do this, the script works (I.E. clicks on the desired object). For example:

       

      Line 9 - var recordNo = '1234';

      Line 10 - var parameter = "//td[contains(., ' "+ recordNo.toString() + " ')]";

      Line 11 - Aliases.browser.page.FindElement(parameter).Click();

       

      Hope this gives you a better idea of the issue I'm running into. Again, thank you (and everyone else) for your time. It's really appreciated.

      • Marsha_R's avatar
        Marsha_R
        Champion Level 3

        Make sure that recordNo is defined as a persistent variable. Otherwise the value is lost every time you log out.

         

         

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    What you have described, reminds me of Refresh Name Mapping Cache

     

    Lines 1 - 5 extracts some sort of record number? 

    Lines 10 - 11 find the element that contains that record number?

     

    How is Aliases.browser.page defined?

     

    For example, the website https://www.w3schools.com/ has two common buttons '< Home' and 'Next >' for each page i.e. https://www.w3schools.com/html/default.asp and https://www.w3schools.com/js/default.asp

     

    If Aliases.browser.page is defined as https://www.w3schools.com/html/default.asp, then I can find buttons '< Home' and 'Next >'. But I won't be able to find buttons on https://www.w3schools.com/js/default.asp as the parent object is different. However, if I define Aliases.browser.page as https://www.w3schools.com/* (note the wildcard), then I can find buttons '< Home' and 'Next >' on all pages.

     

    When you log out and in again, is this all in the same automated process? I.e. you are not running the second test by clicking the play button?

    • AMR013's avatar
      AMR013
      Contributor

      rraghvani ,

      Your understanding of Line 1 - 5 and Line 10 - 11 are correct. Also, the Alias.browser.page is defined "pretty general" so to speak (URL is not different at the page I'm currently having issues on. For example: https://statement1/statement2/html/statement3.html*).

       

      Regarding your question about if my script is all the same automated process, it is. It's a general flow, but due to my issues I'm running into the flow isn't working as well as hoped.

       

      Regarding your suspicion about it being a name mapping caching issue, I did try calling the RefreshMappingInfo against my recordNo variable right before Line 10 (I.E. recordNo.RefreshMappingInfo();), but my test failed saying "recordNo.RefreshMappingInfo is not a function." It's possible I'm using the function incorrectly, but based off the examples listed in the help document you gave me I think I'm using it right.

       

      Hope I'm answering your questions well.

       

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    In the example you have provided,

    Aliases.browser.Page(page).FindElement("#username").SetText("user1");

    Can you replace page with "*" in all of your references

    Aliases.browser.Page("*").FindElement("#username").SetText("user1");

    And try to run your code.

     

    Note: you are performing recordNo.RefreshMappingInfo() on a variable var recordNo = '1234' and not the UI Object.

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    In your example, you have 

    /* Do test and then log out */

    Try commenting out everything except the log out part and then see what happens when you run the whole thing. 

    • AMR013's avatar
      AMR013
      Contributor

      Marsha_R ,

      When I commented out my script except for the log out, placed my recordNo variable above the log out, and ran it executed my problem line no problem. Tried it 3 times and it clicked my desired object. 

      • Marsha_R's avatar
        Marsha_R
        Champion Level 3

        If I was doing it, I would add the testing steps back in one at time and see where it breaks that way.