Forum Discussion

rmaney's avatar
rmaney
New Contributor
5 years ago

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

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

7 Replies

  • 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/terminate-method-process-object.html

    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

     

    • rmaney's avatar
      rmaney
      New Contributor

      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.

      • rmaney's avatar
        rmaney
        New Contributor

        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?