Forum Discussion

xyin's avatar
xyin
Occasional Contributor
8 years ago

How to identify multiple Chrome browser instances

Hi,

 

I need to automate/simulate multiple users (3 and more) logging in to their accounts of an instant messaging website and communicate with one another. We have to use Chrome browser for all users.

Here's a sample site: iceim.theice.com

 

I realized that, for example, if userA logs into his account using a default Chrome browser, any subsequently opened browser, when navigated to the above site, will automatically load userA's session.


I could open an incognito Chrome window, which will let userB login. But this only allows 2 user sessions, I can not use another incognito window to let userC login.

 

I have found a way by using a Chrome option to make multiple (3+) user login sessions available:
chrome.exe --user-data-dir="C:\temp\user1"
chrome.exe --user-data-dir="C:\temp\user2"
chrome.exe --user-data-dir="C:\temp\user3"
...

 

My question is: How to identify different Chrome browser instances?

 

Again, only Chrome can be used, and all users login to the same web site.

 

I would appreciate if someone could provide some VBScript sample.
I searched the community forums but couldn't find any useful information.

 

Thanks a lot.

12 Replies

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    I think you would run into instances of Ambiguous Recognition with multiple browsers open on one machine.  

     

    Would it be a more realistic test if you ran the test on each of three machines?  I can see it being something like

     

    Parameters = User, Chat1, Chat2

     

    Login with User

    Send message to Chat1

    Send message to Chat2

    Verify message from Chat1

    Verify message from Chat2

     

    Run that same test on three machines with different combinations in the parameters

    • xyin's avatar
      xyin
      Occasional Contributor

      Marsha_R,

       

      Thanks for the reply.

       

      However I'd prefer using one machine to automate the testing since I'm not sure how hard it is to run a test to control AUTs on different machines.

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    The most reliable way is to be able to identify separate chrome windows/pages from the very start of the test. For example, it might be possible to perform an automated login into your tested application when starting browser (e.g. something like navigating to http://iceim.theice.com@user1:pwd1/) and then identify the new web page by looking for the provided user name (user1 in the above example).

    If nothing like the above is possible, you may consider a kind of workaround that should work. The idea is that every new instance of Chrome will have incremented value of the window index property (in TestComplete's Object Browser). So the workflow is like that:

    1. Close all Chrome instances (Chrome must be configured to not run in the background);

    2. Set initial expected value of window index to '-1' (because the first window will have index of zero);

    3. Start new instance of Chrome, increment the value of expected window index and search for the Chrome window with this index. Navigate to the required address and store the reference to the page to be used later in tests;

    4. Repeat step 3 required number of times.

     

    However, I would also recommend you to consider the option of the Network Suite in TestComplete (https://support.smartbear.com/viewarticle/81321/). This will leave you with only one Chrome instance on every test machine and you should be able to synchronize test actions (e.g. check for some message on machine B only after the message was posted on machine A) with the help of Synchronization Points provided by the Network Suite.

    • xyin's avatar
      xyin
      Occasional Contributor

      AlexKaras,

       

      Thanks for the reply.

       

      Can you give some example scripts on your step 2 and 3? Thanks.

       

      I did some tests and here is what I found:

       

      After I opened multiple Chrome browsers with the "--user-data-dir=C:\temp\userxxx" option, in TestComplete Object Browser, these Chrome browsers looked the same, all were shown as

                   Sys.Browser("chrome")

       

      So I had no way to differentiate them. See screen shot:

       

       

      As comparison, I used multiple IE browsers with "-private" option, and they could be differentiated in the Object Browser like:

                   Sys.Browser("iexplore"), Sys.Browser("iexplore", 2), Sys.Browser("iexplore", 3), etc.

      So I could define them as different objects in my script and do tasks like loading login page, using different user ids and passwords to login, etc.

      See screen shot:

       

       

      As a matter of fact, I opened multiple instances of some Windows applications such as Notepad, Command prompt, all were shown in the Object Browser as differentiable ones:

       

       

      It just looks odd that Chrome is treated differently when there are multiple instances.

       

      I will look up the network suite option.

       

      Thanks.

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        > Sys.Browser("iexplore"), Sys.Browser("iexplore", 2), Sys.Browser("iexplore", 3), etc.

        Actually, I expected to see the same for Chrome as well... I cannot say what Chrome browsers are displayed just like Browser("Chrome") on your screenshot, but considering that they have different indexes (again, as per your screenshot), I would try to reference Chrome processes the same way: Sys.Browser("Chrome"), Sys.Browser("Chrome", 2), etc. Have you tried this? Does it work? If it works, than I would consider it as an Object Browser display problem and report it to Support (https://support.smartbear.com/message/?prod=TestComplete).

  • We handle this by using the title of the page in the NameMapping entry. You could also handle this by using the URL (assuming the individual browsers are on different pages).

     

    If the same page is loaded in each of the three browsers and no unique identifiers can be used for the same page (like showing the logged in username in the title), you can fall back to using the Index of the parent (the browser itself).

    • xyin's avatar
      xyin
      Occasional Contributor

      bo_roop,

       

      My test case is that all 3 users or browser instances are loading the same page.

      Like I mentioned earlier, TestComplete 12 has an issue of not providing different indexes to different Chrome instances, while it does to IE browsers.

      • bo_roop's avatar
        bo_roop
        Contributor

        Bummer. I know we've run into some issues that are stopping us from updating to v12. Hopefully 12.10 is coming soon and it will fix all the problems that were introduced.

         

        In the meantime, could you get around this by grabbing the Window's handle of the new tab when it's opened and then place it into a variable? You could then use that variable as a required property of the NameMapping entry. You should be able to get away with this logic as long as you are able to grab the correct handle from the newly launched tab.

         

        Another thought would be to open the tabs as separate windows and drive them to a specific location and then use the ScreenTop or ScreenLeft values to differentiate between the windows.

         

        Both are less than optimal options, but when left with nothing better...