How to close context with auto-closed tab

Hi all,

I’m having problem with closing the context where browser tab was auto-closed.

The scenario that I need to perform is:

  1. New context
  2. Open browser
  3. Open new tab (automatically open after click on button)
  4. Close tab (automatically closed after saved changes)
  5. Close context

I can not properly close the context because I’m having following error: Error: page.bringToFront: Target page, context or browser has been closed.
It looks like it stores somewhere in memory already auto-closed tab.
I’m using Chromium 102.0.5005.40

Here is my code sample:

Extra info to my post.
When I do Get Page Ids I still have that auto-closed page id there and CURRENT page is considered as the one that was just closed.

Not sure if you are using Browser Library or SeleniumLibrary?

With both libraries, when you switched to the new browser tab the keyword returns a reference to the original tab so that you can switch back to it.

SeleniumLibrary also has the optional locator MAIN which might be useful if you are using SeleniumLibrary.

Dave.

Thanks Dave. I’am using Browser Library and already tried with solution proposed by you.
I can switch to the main page by it’s id but still can not close the context.
When I do Get Page Ids it returns two ids - for the main page and for the one that was already automatically closed.

Is it the Close Context step in your Suite Teardown that’s causing you the issue? (perhaps I misunderstood the problem)

Have you tried with Close Context ALL

I’m not sure you even need to close the context in the teardown, simply closing the browser with Close Browser will close the contexts as well, as that’s Suite Teardown, you’re not going to be doing anything else with the browser, so no reason to close the context and keep the browser open?

Dave.

Yes, exactly - Close Context causing the issue.
I didn’t paste the wole code as I thougt it might be just Chromium issue.
At the same time I have another context open so I believe I can not use Close Context ALL.
Here is the whole Suite Setup and Suite Teardown:

Ok this is getting beyond my knowledge of Browser Library, perhaps someone else can answer.

Dave.

@aaltat ?

The use case should work, but it looks like it doesn’t. Could you raise an issue, so that we don’t forget it.

1 Like

Hi @aaltat ,
I raised and issue as you suggested. Thanks.

1 Like