feat: add switchToTab by gimler · Pull Request #5436 · codeceptjs/CodeceptJS

Add method to switch to tab

Our app open a window and in this window we call window.close() after clicking on button.

The problem is that switchToPreviousTab() need a active tab. In our app the window/tab is already close by our application.

So with the new method switchToTab you can switch to any open tab.

Applicable helpers:

  • Playwright

Type of change

  • 🚀 New functionality
  • 🐛 Bug fix

Checklist:

  • Tests have been added
  • Documentation has been added (Run npm run docs)
  • Lint checking (Run npm run lint)
  • Local tests are passed (Run npm test)

Question

switchToNextTab also call await targetCreatedHandler.call(this, page) but switchToPreviousTab not. I am not shure if switchToTab should also call await targetCreatedHandler.call(this, page)?

We can also remove the duplicate code and use switchTotTab in switchToPreviousTab() and switchToNextTab()