Forum Discussion

mkiewicz's avatar
mkiewicz
Occasional Contributor
8 years ago

Run Browsers in Parallel

We need to be able to run two browsers in parallel up to a certain point and take a screenshot to test functionality of two users in the same space as how our application would react when  that situation presents itself. Is this possible? I'm able to open up a second window in Chrome by sending a <cntrl-N> keypress to the first window. I can't seem to assign the second window to an object to act on it. though

Thanks in advance!!

  • Hi,

     

    If the browser is at different pages during the test, than it should be no problem to distinguish these two pages just by web address.

    If the address is the same, then:

    -- Page is a logical object provided by TestComplete to support cross-browser testing. Every Page object has complimentary BrowserWindow object that represents actual parent object (container) for the Page one. Because BrowserWindow object represents a window object provided by OS, it has its handle;

    -- It is possible to match Page object to its BrowserWindow container using this code (provided by SmartBear;s Support somewhere in time, VBScript)

    '-----------------------------------------------------------------------------
    
    ' Returns BrowserWindow object that corresponds to the given page object
    ' From: http://smartbear.com/forums/f75/t83264/how-to-match-a-page-object-to-its-browserwindow
    Function BrowserWindowByPageGet(ByRef page)
      Const cProcName = "BrowserWindowByPageGet"
      Dim cProcNameMsgPrefix : cProcNameMsgPrefix = cUnitNameMsgPrefix & cProcName & "(): "
    
      Dim title
      Dim wnd
      Dim strMsg
    
      Set wnd = Utils.CreateStubObject
      If (Not IsNull(page)) Then
        If ("Page" = page.ObjectType) Then
          strMsg = "Waiting for the page to load from the web server..."
          Do Until aqObject.IsSupported(page, "contentDocument")
            Call aqUtils.Delay(500, strMsg)
          Loop
          Do Until aqObject.varDispatch = aqObject.GetVarType(page.contentDocument)
            Call aqUtils.Delay(500, strMsg)
          Loop
          Do Until aqObject.IsSupported(page.contentDocument, "title")
            Call aqUtils.Delay(500, strMsg)
          Loop
    
          title = page.contentDocument.title
          Set wnd = page.Parent.FindChild("WndCaption", title & "*")
          If (Not wnd.Exists) Then
            Set wnd = page.Parent.FindChild("WndCaption", Project.Variables.pvtBaseURL)
          End If
        End If
      End If
      Set BrowserWindowByPageGet = wnd
    End Function
    '-----------------------------------------------------------------------------
    

    -- Assuming that pages are opened one by one, you may

      -- either just keep references to two opened pages in two global variables and use the variable that is needed at the given moment;

      -- or, if you really need to use handle for some reason, you may create a kind of dictionary, keep handle as a key and a reference to the Page object as a corresponding value.

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    CTRL-N opens a new tab to a page... however, if the page does not have a different URL than the original page, then TestComplete can't make the distinction.

    Does it have to be Chrome?  You could, potentially, open up the second page in a different browser and do the check from there.

    • mkiewicz's avatar
      mkiewicz
      Occasional Contributor

      We have it working in Chrome and Edge, but the preference is that we use it solely on Chrome since the majority of our customer base in on Chrome 

      • mkiewicz's avatar
        mkiewicz
        Occasional Contributor

        And the second window is opening to the browser home page, whereas the original window is in the application at the time that the Cntrl-N keypress is sent so the URLs are different. The second window, if you spy it, even shows as BrowserWindow(1), but all actions in it happen in the first window. It's as if the second window doesn't exist. And even though the second window shows as BrowserWindow(1), the other attributes are the same as the first window 

        Selenium accomplishes this through handles. Can TC do it this way, too?

    • mkiewicz's avatar
      mkiewicz
      Occasional Contributor

      And the second window is opening to the browser home page, where as the original window is in the application at the time that the Cntrl-N keypress is sent. The second window, if you spy it, even shows as BrowserWindow(1), but all action in it happen in the first window. And even though the second window shows as BrowserWindow(1), the other attributes are the same as the first window 

      Selenium accomplishes this through handles. Can TC do it this way, too?

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Shifting from one browser window to the other shifts the index... what used to be 0 is now 1 and vice versa.  BrowserWindow is for operating with the browser application itself.  If you need to operate with the application in the web page, you need to work with the page objects on the browser process.  

        Say your application is at url http://myapp.com/ and the home page is about:blank, then you should see in your object browser the Sys.Browser("chrome") with two page objects... one for page("http://myapp.com/") and one for page("about:blank").  Interacting with the application means you interact with the page object for your application.

         

        If you open a second page to your application, you know have two page objects with the same URL.  You could work, probably with the ID property to distinguish them but, each time you close a browser tab and re-open it, the ID will change.  So, this is something you'll have to work around.  What you will need to do is send commands and stuff to those different pages.  In code, you'll need to distinguish the two by noting the ID of the two pages in code (rather than depending upon static mapping) and operating on them that way.  

         

        I don't know if this is "handles" necessarily, but it's how TestComplete identifies pages... they are objects off the browser containing the Web application under test.