Check Out the Latest News About SmartBear Connect
Reply
Occasional Contributor
Posts: 14
Registered: ‎11-21-2016
Accepted Solution

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!!

Posts: 3,848
Topics: 33
Kudos: 1,210
Solutions: 253
Registered: ‎11-30-2009

Re: Run Browsers in Parallel

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.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Extensions available
Community Leaders Program
Occasional Contributor
Posts: 14
Registered: ‎11-21-2016

Re: Run Browsers in Parallel

[ Edited ]

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 

Occasional Contributor
Posts: 14
Registered: ‎11-21-2016

Re: Run Browsers in Parallel

[ Edited ]

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?

Occasional Contributor
Posts: 14
Registered: ‎11-21-2016

Re: Run Browsers in Parallel

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?

Posts: 3,848
Topics: 33
Kudos: 1,210
Solutions: 253
Registered: ‎11-30-2009

Re: Run Browsers in Parallel

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.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Extensions available
Community Leaders Program
Occasional Contributor
Posts: 14
Registered: ‎11-21-2016

Re: Run Browsers in Parallel

[ Edited ]

The way I've always done it (and this is through code) is that you get an array of all running chrome processes and get the window handles before opening the new window. Open window, get handles, and compare to the list taken before opening the window. Odd handle out is the new window. Rinse, repeat for the second window. You can then switch between the two windows using their handles and the switchTo(<handle>) function that comes with WebDriver

Highlighted
Posts: 3,848
Topics: 33
Kudos: 1,210
Solutions: 253
Registered: ‎11-30-2009

Re: Run Browsers in Parallel

TestComplete handles things, not by browser process but by a page object.  The page is what you work with when you're web testing with TestComplete, not the browser process.  Different model.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Extensions available
Community Leaders Program
Community Hero
Posts: 2,836
Registered: ‎07-19-2013

Re: Run Browsers in Parallel

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.

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Let's Meet in Boston
Join the user conference on Sep 12-13
Try QAComplete Now