cancel
Showing results for 
Search instead for 
Did you mean: 

How to force stop a CBT run session apart from "Sys.Browser().BrowserWindow(0).Close()"

SOLVED
Highlighted
New Contributor

How to force stop a CBT run session apart from "Sys.Browser().BrowserWindow(0).Close()"

I am running a few tests on web application. Assume there is situation where remote connection was successful but for some reason browser did not open ( I have observed this situation), now how do I end this CBT session via code( manually I know how to stop this from crossbrowsertesting site)

 

I want to stop the session in the place I have marked in RED below

 

def CBT_LaunchCode(server,capabilities,url):
         Browsers.RemoteItem[server, capabilities].Run(url)
         if (Sys.Browser().BrowserWindow(0).Exists):
            Log.Message("Continue with the test")
        else:

           #Stop CBT instance here via some code 
          Browsers.RemoteItem[server, capabilities].Run(url)  #then reconnect here

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Manager

Re: How to force stop a CBT run session apart from "Sys.Browser().BrowserWindow(0).Close()&

Hi @rmaney I see that you got a solution from the Support Team. Let me post it here - 

 

>>

...the issue happens because the error is raised before the Sys.Browser().BrowserWindow(0).Close() call, and the execution of the test item is interrupted according to the project option. This is the expected behavior, TestComplete works in this way. So, you can use the OnStopTest event handler (https://support.smartbear.com/testcomplete/docs/reference/events/onstoptest.html) to close the browser, e.g. like this:

def EventControl1_OnStopTest(Sender):
    pass
    browser = Sys.WaitBrowser()
    if (browser.Exists):
      browser.BrowserWindow(0).Close()

<<

 

Glad that it worked!


Sonya Mihaljova
Community and Education Specialist

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today

View solution in original post

7 REPLIES 7
Highlighted
Staff

Re: How to force stop a CBT run session apart from "Sys.Browser().BrowserWindow(0).Close()&quot

Is there a reason that you don't want to use the "Sys.Browser().BrowserWindow(0).Close()" snippet?

Also, are you observing that the remote browser windows do not open on a particular step? particular configuratoin? (any further info would be beneficial in debugging this by having more to pass on to our devs)

-

To answer your question a bit more directly, perhaps you could try the Terminate method?

although to be honest I'm not quite sure if that applies to the remote browsers as well https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/window-and-process/te...

One last comment is that, if you are seeing that the remote browser window does not open, and that the subsequent test steps are failing, instead of finding an elegant code based way of handling this, couldn't we just as easily modify the current project property settings so that we just stop the test item/project item, etc upon an error? So that if the remote browser does not open, the next subsequent step will fail, and we will get the result back on that right away with some sort of an object not found error

 

Best,
Justin Kim
Highlighted
New Contributor

Re: How to force stop a CBT run session apart from "Sys.Browser().BrowserWindow(0).Close()&

Thank you for the help. I will see if "Stop on error" setting stops the CBT run session. 

 

Was this working a week before? because I remember the tests being queued even after failing. But anyway I will have a look again.

Highlighted
New Contributor

Re: How to force stop a CBT run session apart from "Sys.Browser().BrowserWindow(0).Close()&

I have "Stop current item On error" and "Stop current item on object recognition" error enabled. But this doesnt end the CBT session when test case 1 fails with some error,  from local next test case is already triggered to CBT, and gets queued. I have opened a ticket with Smart Bear for this. Hope I find a solution. Any suggestions from here?

Highlighted
Community Manager

Re: How to force stop a CBT run session apart from "Sys.Browser().BrowserWindow(0).Close()&

Thanks Justin!

 

@rmaney I was able to locate your support ticket and see that the investigation is on-going. Please keep us posted when you have a solution from the Support Team!


Sonya Mihaljova
Community and Education Specialist

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
Highlighted
Community Manager

Re: How to force stop a CBT run session apart from "Sys.Browser().BrowserWindow(0).Close()&

@rmaney oh, I see that you replied straight to the community notification - this way your message won't make it to the forum. 

Anyway, we will be waiting for your results here🙂


Sonya Mihaljova
Community and Education Specialist

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
Highlighted
Community Manager

Re: How to force stop a CBT run session apart from "Sys.Browser().BrowserWindow(0).Close()&

Hi @rmaney I see that you got a solution from the Support Team. Let me post it here - 

 

>>

...the issue happens because the error is raised before the Sys.Browser().BrowserWindow(0).Close() call, and the execution of the test item is interrupted according to the project option. This is the expected behavior, TestComplete works in this way. So, you can use the OnStopTest event handler (https://support.smartbear.com/testcomplete/docs/reference/events/onstoptest.html) to close the browser, e.g. like this:

def EventControl1_OnStopTest(Sender):
    pass
    browser = Sys.WaitBrowser()
    if (browser.Exists):
      browser.BrowserWindow(0).Close()

<<

 

Glad that it worked!


Sonya Mihaljova
Community and Education Specialist

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today

View solution in original post

Highlighted
New Contributor

Re: How to force stop a CBT run session apart from "Sys.Browser().BrowserWindow(0).Close()&

Thank you for the help

New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!

Challenge Status

How to execute remote test and obtain results via Test Runner REST API

Participate!

Comparing content of HTML table with Excel file data

Participate!

Compare HTML table with Excel file and correct data in the file

Participate!

Retrieve Data from a Web Page

Participate!
Top Kudoed Authors